Skip to content

Commit a630cb3

Browse files
updating the read me file
1 parent 609ffcd commit a630cb3

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,41 @@ More details of this module can be refered in [selpy](https://pypi.org/project/s
4141

4242
## To Run the tests
4343
For a simple run of all the test files in normal mode, try
44+
4445
```shell script
4546
pytest
4647
```
48+
4749
To Run the tests in parallel mode or multi thread run for the available test files, try (To have parallel run you need to have atleast 2 tests inside your folder structure)
50+
4851
```shell script
4952
pytest -s -v -n=2
5053
```
54+
5155
To Run the tests in parallel mode for the available test files along with browser specification, try
56+
5257
```shell script
5358
browser=chrome pytest -s -v -n=2
5459
```
60+
5561
To Run the tests in parallel mode for the available test files in headless mode, try
62+
5663
```shell script
5764
headless=1 browser=chrome pytest -s -v -n=2
5865
```
66+
5967
This will run the tests in headless mode
6068

6169
## To open allure results
6270
Allure is a open source framework for reporting the test runs. To install allure in mac, use the following steps
71+
6372
```shell script
6473
brew cask install adoptopenjdk
6574
brew install allure
6675
```
76+
6777
To view the results for the test run, use
78+
6879
```shell script
6980
allure serve reports/allure
7081
```
@@ -80,6 +91,7 @@ For better illustration on the testcases, allure reports has been integrated. Al
8091

8192
## Jenkins Integration with Docker images
8293
Get any of the linux with python docker image as the slaves in jenkins and use the same for executing the UI automation with this framework (Sample docker image - `https://hub.docker.com/_/python`). From the jenkins bash Execute the following to get the testcases to run,
94+
8395
```shell script
8496
#!/usr/bin/python3
8597
python --version
@@ -89,6 +101,7 @@ headless=1 pytest -s -v -n 4
89101
```
90102

91103
In Jenkins pipeline, try to add the following snippet to execute the tests,
104+
92105
```shell script
93106
pipeline {
94107
agent { docker { image 'python:3.7.6' } }
@@ -132,6 +145,7 @@ class AmazonHomePageLocator:
132145
```
133146
134147
4. To use the Locator method we need to pass the type of locator and the actual locator element. Type of locator has to be mentioned in the following way to allow `selpy` to process the locator.
148+
135149
```
136150
CSS - 'css selector'
137151
XPATH - 'xpath'
@@ -174,6 +188,7 @@ class AmazonHomePage(AmazonHomePageLocator):
174188
### Creating a new test file in the project
175189
176190
1. Define the tests inside the Tests folder. Create a new `.py` file and import the required modules inside (depending on the requirement). Mainly require the page modules inside the test file. It is not recommended to import locator modules since we can access the locators from the page module.
191+
177192
```python
178193
import allure
179194
import pytest
@@ -186,6 +201,7 @@ from selpy.variable import Var
186201
```
187202
188203
2. It is suggested to mention the allure feature name, severity, pytest's markers to the test. This allows us to have better reporting and dynamic way to run in the future.
204+
189205
```python
190206
@allure.feature("Feature name")
191207
@allure.severity('Critical')
@@ -198,12 +214,15 @@ def test_amazon_book_search_001():
198214
static_variable = Var("amazon.yml", "static")
199215
dynamic_variable = Var("amazon_book_search_result_dynamic.yml", "dynamic")
200216
```
217+
201218
To run the test with marker you can execute as
219+
202220
```shell script
203221
pytest -v -m regression
204222
# or
205223
pytest -v -m ui
206224
```
225+
207226
Use `allure.step("step name")` to have a detailed reporting in allure.
208227
209228
3. Append the method name for the test as `test_` only then it will be taken as a test case. This has been configured in ```pytest.ini``` as,
@@ -224,13 +243,14 @@ addopts = -rsxX
224243
--cov=Tests
225244
--alluredir reports/allure
226245
--clean-alluredir
227-
228246
```
247+
229248
I have created markers to have distinguished marker for automation purpose. The `python_funtions` param is where we need to mention the test files. `addopts` param used to take the values that are used to give in command line along with pytest.
230249
231250
Allure configurations and pytest's default report has been wired here.
232251
233252
4. A file `conftest.py` should be created inside the Tests folder. In this file we can have the run before each, run before each module, run during and after pytest setup methods. Adding screenshot to the testcases is handled by,
253+
234254
```python
235255
@pytest.fixture(autouse=True)
236256
def before_each():
@@ -247,6 +267,7 @@ def before_each():
247267
print(e)
248268
print('*-* After each END')
249269
```
270+
250271
The fixture param `autouse=True` ensures that this block is invoked only once for each test method.
251272
252273
Closing of all the drivers has been handled like,
@@ -260,19 +281,23 @@ def before_module():
260281
driver.quit()
261282
print('*-* After module END')
262283
```
284+
263285
The param `scope='module'`ensures that this block is invoked only once for each test file.
264286
265287
5. We used home grown pypi published module `selpy` for Page Object Model support as well as snap support. To use that module data files path has to be set, this is done by,
288+
266289
```python
267290
from selpy.store import Store
268291
def pytest_configure(config):
269292
Store.global_data_path = os.path.dirname(os.path.abspath(__file__)).replace("/Tests", "") + '/Data/GlobalData/global_data.yml'
270293
Store.static_data_path = os.path.dirname(os.path.abspath(__file__)).replace("/Tests", "") + '/Data/TestData/'
271294
Store.dynamic_data_path = os.path.dirname(os.path.abspath(__file__)).replace("/Tests", "") + '/Data/DynamicData/'
272295
```
296+
273297
This ensures that this data has been set before pytest is being invoked only once. More about `selpy` module can be seen at [pypi page](https://pypi.org/project/selpy/)
274298
275299
6. Assert using pytest's default assertion method. Make sure you have a proper description to the assertion, so that once it is failed the failure message is proper.
300+
276301
```python
277302
assert (AmazonHomePage.is_home_page_displayed() is True), "Amazon home page is not displayed"
278303
```
@@ -294,18 +319,24 @@ For example: If you are testing an application which tracks nasdaq or any other
294319
To use the snap mode, you need to use `selpy` [selpy](https://pypi.org/project/selpy/) module, and make use of `Var` methods as follows.
295320
296321
1. Declare the dictionary where the UI texts/data is to be stored during the test run.
322+
297323
```python
298324
ui_dynamic_data = {}
299325
ui_dynamic_data["amazon_product_title"] = AmazonProductPage.amazon_product_title.texts_as_string()
300326
```
327+
301328
2. Initiate a class variable with the file name against which you need to verify the UI data.
329+
302330
```python
303331
dynamic_variable = Var("amazon_book_search_result_dynamic.yml", "dynamic")
304332
```
333+
305334
3. To compare the UI data with the file use the `compare` method that comes along with the `dynamic_variable`
335+
306336
```python
307337
dynamic_variable.compare(ui_dynamic_data)
308338
```
339+
309340
This will compare and report it to allure and assertion has been done within that method.
310341
311342
4. While running the suite for first time where no data is saved within the test file, run the suite with ```snap=1 pytest``` this will ensure the UI data is being saved to the file.
@@ -315,9 +346,11 @@ This will compare and report it to allure and assertion has been done within tha
315346
## Static code analyser:
316347
317348
For static code analyser I used flake8. To check the configurations view (.flake8)[.flake8] file. To check on the code status execte,
349+
318350
```shell script
319351
flake8
320352
```
353+
321354
currently there are `0` vulnerabilities with this project.
322355
323356

0 commit comments

Comments
 (0)