Skip to content

Commit 3921d99

Browse files
updating readme
1 parent 9590af4 commit 3921d99

File tree

2 files changed

+51
-24
lines changed

2 files changed

+51
-24
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ further defined and clarified by project maintainers.
7373
### Enforcement
7474

7575
Instances of abusive, harassing, or otherwise unacceptable behavior may be
76-
reported by contacting me at [mail][mailto:[email protected]]. All
76+
reported by contacting me at [mail](mailto:[email protected]). All
7777
complaints will be reviewed and investigated and will result in a response that
7878
is deemed necessary and appropriate to the circumstances. The project member has
7979
obligated to maintain confidentiality with regard to the reporter of an incident.

README.md

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,43 @@ Selpy-Python is a Page Object Model (POM) framework for selenium automation with
2424
* Testdata driven tests
2525
* Multi Thread run
2626
* Snap
27-
* Static code analysis
27+
* Static code analyser
2828

2929
## Setup
3030
* Clone this repository
3131
* 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/]
3333
* Once brew is installed install python by ```brew install python3```
3434
* To get additional dependencies of python like pip3, do ```brew postinstall python3```
3535
* Install the required packages needed for this framework using ```pip3 install -r requirements.txt```
3636

3737
## To Run the tests
3838
For a simple run of all the test files in normal mode, try
39-
```
39+
```shell script
4040
pytest
4141
```
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
4444
pytest -s -v -n=2
4545
```
4646
To Run the tests in parallel mode for the available test files along with browser specification, try
47-
```
47+
```shell script
4848
browser=chrome pytest -s -v -n=2
4949
```
5050
To Run the tests in parallel mode for the available test files in headless mode, try
51-
```
51+
```shell script
5252
headless=1 browser=chrome pytest -s -v -n=2
5353
```
5454
This will run the tests in headless mode
5555

5656
## To open allure results
5757
Allure is a open source framework for reporting the test runs. To install allure in mac, use the following steps
58-
```
58+
```shell script
5959
brew cask install adoptopenjdk
6060
brew install allure
6161
```
6262
To view the results for the test run, use
63-
```
63+
```shell script
6464
allure serve reports/allure
6565
```
6666

@@ -75,7 +75,7 @@ For better illustration on the testcases, allure reports has been integrated. Al
7575

7676
## Jenkins Integration with Docker images
7777
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
7979
#!/usr/bin/python3
8080
python --version
8181
cd <path_to_the_project>
@@ -84,7 +84,7 @@ headless=1 pytest -s -v -n 4
8484
```
8585

8686
In Jenkins pipeline, try to add the following snippet to execute the tests,
87-
```
87+
```shell script
8888
pipeline {
8989
agent { docker { image 'python:3.7.6' } }
9090
stages {
@@ -113,7 +113,7 @@ In `Data/GlobalData/global_data.yml` file, if the headless is `1`, the chrome wi
113113
114114
3. For each page add a new class and declare the locators. Static locators can be class variables. Dynamic locators can be separate methods.
115115
116-
```
116+
```python
117117
class AmazonHomePageLocator:
118118
amazon_logo = Locator("css selector", "div#nav-logo a[aria-label='Amazon']")
119119
amazon_search_categories = Locator("css selector", "div.nav-search-scope select.nav-search-dropdown")
@@ -137,7 +137,7 @@ class AmazonHomePageLocator:
137137
138138
3. For each page add a new class and each page class should inherit the locators class of the same page
139139
140-
```
140+
```python
141141
from Locators.amazon_home_page import AmazonHomePageLocator
142142
143143
@@ -149,7 +149,6 @@ class AmazonHomePage(AmazonHomePageLocator):
149149
@classmethod
150150
def is_home_page_displayed(cls):
151151
return AmazonHomePageLocator.amazon_logo.is_displayed_with_wait()
152-
153152
```
154153
155154
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):
158157
### Creating a new test file in the project
159158
160159
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
162161
import allure
163162
import pytest
164163
import time
@@ -170,7 +169,7 @@ from selpy.variable import Var
170169
```
171170
172171
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.
173-
```
172+
```python
174173
@allure.feature("Feature name")
175174
@allure.severity('Critical')
176175
@pytest.mark.regression
@@ -183,7 +182,7 @@ def test_amazon_book_search_001():
183182
dynamic_variable = Var("amazon_book_search_result_dynamic.yml", "dynamic")
184183
```
185184
To run the test with marker you can execute as
186-
```
185+
```shell script
187186
pytest -v -m regression
188187
# or
189188
pytest -v -m ui
@@ -192,7 +191,7 @@ Use `allure.step("step name")` to have a detailed reporting in allure.
192191
193192
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,
194193
195-
```
194+
```python
196195
markers =
197196
sanity: sanity tests marker
198197
regression: regression tests marker
@@ -215,7 +214,7 @@ I have created markers to have distinguished marker for automation purpose. The
215214
Allure configurations and pytest's default report has been wired here.
216215
217216
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
219218
@pytest.fixture(autouse=True)
220219
def before_each():
221220
print('*-* Before each INITIALIZATION')
@@ -235,7 +234,7 @@ The fixture param `autouse=True` ensures that this block is invoked only once fo
235234
236235
Closing of all the drivers has been handled like,
237236
238-
```
237+
```python
239238
@pytest.fixture(scope='module', autouse=True)
240239
def before_module():
241240
print('*-* Before module INITIALIZATION')
@@ -247,25 +246,53 @@ def before_module():
247246
The param `scope='module'`ensures that this block is invoked only once for each test file.
248247
249248
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,
250-
```
249+
```python
251250
from selpy.store import Store
252251
def pytest_configure(config):
253252
Store.global_data_path = os.path.dirname(os.path.abspath(__file__)).replace("/Tests", "") + '/Data/GlobalData/global_data.yml'
254253
Store.static_data_path = os.path.dirname(os.path.abspath(__file__)).replace("/Tests", "") + '/Data/TestData/'
255254
Store.dynamic_data_path = os.path.dirname(os.path.abspath(__file__)).replace("/Tests", "") + '/Data/DynamicData/'
256255
```
257-
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/)
258257
259258
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
261260
assert (AmazonHomePage.is_home_page_displayed() is True), "Amazon home page is not displayed"
262261
```
263262
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.
272+
```python
273+
ui_dynamic_data = {}
274+
ui_dynamic_data["amazon_product_title"] = AmazonProductPage.amazon_product_title.texts_as_string()
275+
```
276+
2. Initiate a class variable with the file name against which you need to verify the UI data.
277+
```python
278+
dynamic_variable = Var("amazon_book_search_result_dynamic.yml", "dynamic")
279+
```
280+
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+
264290
## Built With
265291
266292
* [pytest](https://docs.pytest.org/en/latest/) - Core test framework
267293
* [flake8](https://pypi.org/project/flake8/) - Static code analyser
268294
* [pytest-xdist](https://pypi.org/project/pytest-xdist/) - To run pytest in parallel mode
295+
* [selpy](https://pypi.org/project/selpy/) - Page Object Model for python
269296
* [Allure pytest](https://pypi.org/project/allure-pytest/) - For Detailed reporting
270297
* [Selenium](https://www.seleniumhq.org/) - For web browser automation.
271298

0 commit comments

Comments
 (0)