You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+34-1Lines changed: 34 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,30 +41,41 @@ More details of this module can be refered in [selpy](https://pypi.org/project/s
41
41
42
42
## To Run the tests
43
43
For a simple run of all the test files in normal mode, try
44
+
44
45
```shell script
45
46
pytest
46
47
```
48
+
47
49
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
+
48
51
```shell script
49
52
pytest -s -v -n=2
50
53
```
54
+
51
55
To Run the tests in parallel mode for the available test files along with browser specification, try
56
+
52
57
```shell script
53
58
browser=chrome pytest -s -v -n=2
54
59
```
60
+
55
61
To Run the tests in parallel mode for the available test files in headless mode, try
62
+
56
63
```shell script
57
64
headless=1 browser=chrome pytest -s -v -n=2
58
65
```
66
+
59
67
This will run the tests in headless mode
60
68
61
69
## To open allure results
62
70
Allure is a open source framework for reporting the test runs. To install allure in mac, use the following steps
71
+
63
72
```shell script
64
73
brew cask install adoptopenjdk
65
74
brew install allure
66
75
```
76
+
67
77
To view the results for the test run, use
78
+
68
79
```shell script
69
80
allure serve reports/allure
70
81
```
@@ -80,6 +91,7 @@ For better illustration on the testcases, allure reports has been integrated. Al
80
91
81
92
## Jenkins Integration with Docker images
82
93
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
+
83
95
```shell script
84
96
#!/usr/bin/python3
85
97
python --version
@@ -89,6 +101,7 @@ headless=1 pytest -s -v -n 4
89
101
```
90
102
91
103
In Jenkins pipeline, try to add the following snippet to execute the tests,
104
+
92
105
```shell script
93
106
pipeline {
94
107
agent { docker { image 'python:3.7.6' } }
@@ -132,6 +145,7 @@ class AmazonHomePageLocator:
132
145
```
133
146
134
147
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
+
135
149
```
136
150
CSS - 'css selector'
137
151
XPATH - 'xpath'
@@ -174,6 +188,7 @@ class AmazonHomePage(AmazonHomePageLocator):
174
188
### Creating a new test file in the project
175
189
176
190
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
+
177
192
```python
178
193
import allure
179
194
import pytest
@@ -186,6 +201,7 @@ from selpy.variable import Var
186
201
```
187
202
188
203
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.
Use `allure.step("step name")` to have a detailed reporting in allure.
208
227
209
228
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
224
243
--cov=Tests
225
244
--alluredir reports/allure
226
245
--clean-alluredir
227
-
228
246
```
247
+
229
248
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.
230
249
231
250
Allure configurations and pytest's default report has been wired here.
232
251
233
252
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
+
234
254
```python
235
255
@pytest.fixture(autouse=True)
236
256
def before_each():
@@ -247,6 +267,7 @@ def before_each():
247
267
print(e)
248
268
print('*-* After each END')
249
269
```
270
+
250
271
The fixture param `autouse=True` ensures that this block is invoked only once for each test method.
251
272
252
273
Closing of all the drivers has been handled like,
@@ -260,19 +281,23 @@ def before_module():
260
281
driver.quit()
261
282
print('*-* After module END')
262
283
```
284
+
263
285
The param `scope='module'`ensures that this block is invoked only once for each test file.
264
286
265
287
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,
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/)
274
298
275
299
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
+
276
301
```python
277
302
assert (AmazonHomePage.is_home_page_displayed() is True), "Amazon home page is not displayed"
278
303
```
@@ -294,18 +319,24 @@ For example: If you are testing an application which tracks nasdaq or any other
294
319
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.
295
320
296
321
1. Declare the dictionary where the UI texts/data is to be stored during the test run.
3. To compare the UI data with the file use the `compare` method that comes along with the `dynamic_variable`
335
+
306
336
```python
307
337
dynamic_variable.compare(ui_dynamic_data)
308
338
```
339
+
309
340
This will compare and report it to allure and assertion has been done within that method.
310
341
311
342
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
315
346
## Static code analyser:
316
347
317
348
For static code analyser I used flake8. To check the configurations view (.flake8)[.flake8] file. To check on the code status execte,
349
+
318
350
```shell script
319
351
flake8
320
352
```
353
+
321
354
currently there are `0` vulnerabilities with this project.
0 commit comments