Skip to content

Commit 387f1e7

Browse files
author
jagwithyou
committed
Initial Framework
0 parents  commit 387f1e7

19 files changed

+1032
-0
lines changed

.gitignore

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/
130+
/venv

README.md

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# automation_testing_with_python
2+
3+
This is a framework that will make your life easier in the field of automation testing. The goal of this framework is to making automation testing as easier as python that any one can learn and start using easily. your support will be highly appriciated in this process of making this as the easiest and effective framework in the field of automation testing. Please join us by contributing your inputs and giving this repo a star.
4+
#### Below are few useful features of this framework
5+
- Modular Design.
6+
- Report generation.
7+
- Mailer to send the report.
8+
- Events Log.
9+
#### Prerequisite
10+
- High learning sprit towards automation
11+
- Basic knowledge in python
12+
13+
## Quick Start
14+
- ##### Clone Framework
15+
<pre>
16+
git clone https://github.com/jagwithyou/automation-testing-python-selenium.git</pre>
17+
- ##### Copy the web_ui_testing folder to your project location and open command prompt from there.
18+
19+
- ##### Create and activate virtual environment
20+
<pre>
21+
python -m venv ENVIRONMENT_NAME
22+
ENVIRONMENT_NAME\scripts\activate</pre>
23+
- ##### Install required Python Packages
24+
<pre>
25+
pip install -r requirements.txt</pre>
26+
- ##### Run the test
27+
<pre>
28+
pytest</pre>
29+
- ##### Work on project
30+
Congratulations! framework is ready you can add new testcases now.
31+
32+
## Folder Structure
33+
- web_ui_testing
34+
- Locators
35+
- src
36+
- Drivers
37+
- logs
38+
- Reports
39+
- Utility
40+
- Tests
41+
- Config.py
42+
- Conftest.py
43+
- api-testing
44+
- releasing soon
45+
46+
## Web UI Testing:
47+
### Folder Description
48+
**Driver**
49+
- As selenium supports different drivers for different browsers, this folder contains the web drivers that we are going to use on our project.
50+
Ex:- For chrome browser:- chomedriver.exe
51+
52+
**Locators**
53+
- Locator is the unique identifier for any element using which we can find the element.
54+
- Locators can be formed:
55+
1) By X-path,
56+
2) By CSS
57+
3) By ID
58+
4) By attribute
59+
60+
- Let's take a example of a submit button whose xpath is //button[@type='submit
61+
- The locator for the submit button will be:
62+
SUBMIT_BUTTON = (By.XPATH, "//button[@type='submit']")
63+
64+
65+
**Logs**
66+
- Contains the test execution logs
67+
68+
**Reports**
69+
- Contains the test case execution report file after test case execution.
70+
71+
**Tests**
72+
- Contains test cases
73+
- All the functionality and UI test cases should be created inside this folder
74+
- For parallel test case execution all the test case prefix should be uniform.
75+
- To test the user login create a test case as "test_user_login.py".
76+
77+
78+
**Utility**
79+
- this is the utility folder where you should keep your utilities. You can get a large collection of utilities from the [Utilities_repo](../../utilities)
80+
81+
**Config.py**
82+
- A config.py (configuration) file contains all the settings that you can change as per your requirements.
83+
84+
85+
**Conftest.py**
86+
- conftest is the test configuration file for pytest using which we can change the way pytest is working. From adding the setup and teardown to every test case to import external plugins or modules we can configure these easily.
87+
88+
89+
### How to work with this framework
90+
Suppose you want to test the google search bar (which you have seen in the demo; you can relate the flow with the existing code to understand better).
91+
92+
#### **Step-1**
93+
As we want to test google, the project url will be google.com. you have to assign this to the BASE_URL variable.
94+
<pre>
95+
BASE_URL = "https://www.google.com/"
96+
</pre>
97+
98+
#### **Step-2**
99+
Now we have to create a locator file for maintaining all the locators of a page. For a better use create individual locator files for each of the pages of your project. In our case we have created the locator file named google_homepage_locator and declared the locator inside this.
100+
<pre>
101+
from selenium.webdriver.common.by import By
102+
103+
SEARCH_BAR = (By.NAME, "q")
104+
</pre>
105+
106+
#### **Step-3 - Perform the Action**
107+
Now we are ready to write the test script. For that create a file inside tests folder and name it as test_FILENAME.py. As you can rightly guess each test script file should start with ***test_
108+
109+
Inside the script the code looks like below.
110+
<pre>
111+
from tests import BaseClass
112+
from locator.google_homepage_locator import *
113+
from selenium.webdriver.common.keys import Keys
114+
115+
class TestGooglePage(BaseClass):
116+
def test_1_search(self):
117+
''' This is a test case to test the Google Search Page page. '''
118+
#Instantiating the logger
119+
self.log().info("Google Search Page Test Started")
120+
#accessing the search field and sending text to that
121+
self.get_element(SEARCH_BAR).send_keys('Automation Testing Python Selenium')
122+
self.get_element(SEARCH_BAR).send_keys(Keys.RETURN)
123+
#logging the test success
124+
self.log().info("Test Success")
125+
assert True
126+
127+
</pre>
128+
129+
As you can see first we have declared a class that is inherited from the BaseClass and inside it we are writing the test cases. you can assume this class as the ***TestSuite*** and each of the methods as the testcases inside the test-suite. you can write number of testcases inside this class. All the test cases should start as ***test_*** and they are executed alphabetically. so if you want any order of execution then please mention as ***test_1_***. You can give any number (1,2,3) and they will be executed with this order.
130+
131+
The next line is for log if you don't want log you can skip it. After that the operation starts. give your attention to the below three lines.
132+
133+
<pre>
134+
#accessing the search field and sending text to that
135+
self.get_element(SEARCH_BAR).send_keys('Automation Testing Python Selenium')
136+
self.get_element(SEARCH_BAR).send_keys(Keys.RETURN)
137+
</pre>
138+
139+
1. self.get_element() - it is a method that takes the locator and return the element object to perform operation.
140+
2. send_keys() - This sends some value to the object. Here it is sending the Text to the search bar of google. These are pytest derived methods and you can get the list from the pytest documentation.
141+
3. Keys.RETURN - It works like we are clicking the Enter Key after writing our query.
142+
143+
#### Step-4 - Running the script
144+
We can run the complete testing by using the below command
145+
<pre>
146+
pytest
147+
</pre>
148+
If you want to run in a different browser then you can add one more argument here like below.
149+
<pre>
150+
pytest --browser_name firefox
151+
</pre>
152+
153+
Awesome we have done this. Similarly you can follow step 2,3,4 to write automation for each of the field.

config.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
BASE_DIRECTORY = os.getcwd()
3+
BASE_URL = "https://www.google.com/"
4+
5+
#DRIVER
6+
DRIVER_PATH = os.path.join(BASE_DIRECTORY, 'src', 'drivers') #use os.path.join to create a path
7+
WEB_DRIVER_WAIT = 60
8+
HEADLESS = False
9+
ACTION_DELAY = 2
10+
DOWNLOAD_WAIT_TIME = 60
11+
DOWNLOAD_FOLDER = os.path.join(BASE_DIRECTORY,'src', 'media','download')
12+
13+
#Reporting
14+
REPORT_TITLE = "Orange HRM Testing"
15+
REPORT_FOLDER = os.path.join(BASE_DIRECTORY, 'src', 'reports')
16+
INDIVIDUAL_REPORT = False
17+
LOG_FOLDER = os.path.join(BASE_DIRECTORY, 'src', 'logs')
18+

0 commit comments

Comments
 (0)