This project delivers to you a base test architecture for your web tests using the best frameworks and practices.
BasePage
class include basic functionality and driver initialization
base_page.py
class BasePage(object):
def __init__(self, driver, base_url='http://www.amazon.com/'):
self.base_url = base_url
self.driver = driver
self.timeout = 30
def find_element(self, *locator):
return self.driver.find_element(*locator)
MainPage
is derived from the `BasePage class, it contains methods related to this page, which will be used to create test steps.
# main_page.py
class MainPage(BasePage):
def __init__(self, driver):
self.locator = MainPageLocators
super().__init__(driver) # Python3 version
def check_page_loaded(self):
return True if self.find_element(*self.locator.LOGO) else False
When you want to write tests, you should derive your test class from BaseTest
which holds basic functionality for your tests. Then you can call page and related methods in accordance with the steps in the test cases
class TestSignInPage(BaseTest):
def test_sign_in_with_valid_user(self):
print("\n" + str(test_cases(4)))
main_page = MainPage(self.driver)
login_page = main_page.click_sign_in_button()
result = login_page.login_with_valid_user("valid_user")
self.assertIn("yourstore/home", result.get_url())
To enjoy the automated tests, develop the framework or adapt it to your own purposes, just download the project or clone repository. You need to install packages using pip according to requirements.txt file. Run the command below in terminal:
$ pip install -r requirements.txt
python -m unittest
python -m unittest tests.test_sign_in_page.TestSignInPage
python -m unittest tests.test_sign_in_page.TestSignInPage.test_page_load
Run the test with pytest
python -m pytest tests/test_search_item.py --alluredir ./results
Open allure report with this
allure serve ./results/