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
+50-23Lines changed: 50 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,43 +24,43 @@ Selpy-Python is a Page Object Model (POM) framework for selenium automation with
24
24
* Testdata driven tests
25
25
* Multi Thread run
26
26
* Snap
27
-
* Static code analysis
27
+
* Static code analyser
28
28
29
29
## Setup
30
30
* Clone this repository
31
31
* Navigate to the cloned folder
32
-
* To install the dependencies in MAC we use Homebrew version manager install [using][https://brew.sh/]
32
+
* To install the dependencies in MAC we use Homebrew version manager install (using)[https://brew.sh/]
33
33
* Once brew is installed install python by ```brew install python3```
34
34
* To get additional dependencies of python like pip3, do ```brew postinstall python3```
35
35
* Install the required packages needed for this framework using ```pip3 install -r requirements.txt```
36
36
37
37
## To Run the tests
38
38
For a simple run of all the test files in normal mode, try
39
-
```
39
+
```shell script
40
40
pytest
41
41
```
42
-
To Run the tests in parallel mode for the available test files, try (To have parallel run you need to have atleast 2 tests inside your folder structure)
43
-
```
42
+
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)
43
+
```shell script
44
44
pytest -s -v -n=2
45
45
```
46
46
To Run the tests in parallel mode for the available test files along with browser specification, try
47
-
```
47
+
```shell script
48
48
browser=chrome pytest -s -v -n=2
49
49
```
50
50
To Run the tests in parallel mode for the available test files in headless mode, try
51
-
```
51
+
```shell script
52
52
headless=1 browser=chrome pytest -s -v -n=2
53
53
```
54
54
This will run the tests in headless mode
55
55
56
56
## To open allure results
57
57
Allure is a open source framework for reporting the test runs. To install allure in mac, use the following steps
58
-
```
58
+
```shell script
59
59
brew cask install adoptopenjdk
60
60
brew install allure
61
61
```
62
62
To view the results for the test run, use
63
-
```
63
+
```shell script
64
64
allure serve reports/allure
65
65
```
66
66
@@ -75,7 +75,7 @@ For better illustration on the testcases, allure reports has been integrated. Al
75
75
76
76
## Jenkins Integration with Docker images
77
77
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,
78
-
```
78
+
```shell script
79
79
#!/usr/bin/python3
80
80
python --version
81
81
cd<path_to_the_project>
@@ -84,7 +84,7 @@ headless=1 pytest -s -v -n 4
84
84
```
85
85
86
86
In Jenkins pipeline, try to add the following snippet to execute the tests,
87
-
```
87
+
```shell script
88
88
pipeline {
89
89
agent { docker { image 'python:3.7.6' } }
90
90
stages {
@@ -113,7 +113,7 @@ In `Data/GlobalData/global_data.yml` file, if the headless is `1`, the chrome wi
113
113
114
114
3. For each page add a new class and declare the locators. Static locators can be class variables. Dynamic locators can be separate methods.
3. Ideally each web page should have a new page file inside `pages` folder with the class name same as the web page name.
@@ -158,7 +157,7 @@ class AmazonHomePage(AmazonHomePageLocator):
158
157
### Creating a new test file in the project
159
158
160
159
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.
161
-
```
160
+
```python
162
161
import allure
163
162
import pytest
164
163
import time
@@ -170,7 +169,7 @@ from selpy.variable import Var
170
169
```
171
170
172
171
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.
@@ -192,7 +191,7 @@ Use `allure.step("step name")` to have a detailed reporting in allure.
192
191
193
192
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,
194
193
195
-
```
194
+
```python
196
195
markers =
197
196
sanity: sanity tests marker
198
197
regression: regression tests marker
@@ -215,7 +214,7 @@ I have created markers to have distinguished marker for automation purpose. The
215
214
Allure configurations and pytest's default report has been wired here.
216
215
217
216
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,
218
-
```
217
+
```python
219
218
@pytest.fixture(autouse=True)
220
219
def before_each():
221
220
print('*-* Before each INITIALIZATION')
@@ -235,7 +234,7 @@ The fixture param `autouse=True` ensures that this block is invoked only once fo
235
234
236
235
Closing of all the drivers has been handled like,
237
236
238
-
```
237
+
```python
239
238
@pytest.fixture(scope='module', autouse=True)
240
239
def before_module():
241
240
print('*-* Before module INITIALIZATION')
@@ -247,25 +246,53 @@ def before_module():
247
246
The param `scope='module'`ensures that this block is invoked only once for each test file.
248
247
249
248
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/]
256
+
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/)
258
257
259
258
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.
260
-
```
259
+
```python
261
260
assert (AmazonHomePage.is_home_page_displayed() is True), "Amazon home page is not displayed"
262
261
```
263
262
263
+
## Detailing snap Mode:
264
+
265
+
Snap mode is created to reduce the burden in maintaining the test data. While we test an application with data heavy validations, there is a high chance that the data in the application may change over the course of time.
266
+
267
+
For example: If you are testing an application which tracks nasdaq or any other market related stuff, the data will change on daily basis. We need to have a capability to embrace to the change that is happening in the application with ease.
268
+
269
+
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.
270
+
271
+
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`
281
+
```python
282
+
dynamic_variable.compare(ui_dynamic_data)
283
+
```
284
+
This will compare and report it to allure and assertion has been done within that method.
285
+
286
+
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.
287
+
288
+
5. Use only YML files for this purpose, since it is easier to handle key value pair with yaml file.
289
+
264
290
## Built With
265
291
266
292
* [pytest](https://docs.pytest.org/en/latest/) - Core test framework
0 commit comments