TestFiles

Here under the tests package first we need to define the conftest.py file and then we need to define all the test files which are based on test scenarios.

Conftest.py

As we discussed in pytest concepts about conftest.py file. If any fixtures are not found in test files it will search fixtures in conftest.py file and execute it.

Conftest.py file name is predefined, so we shouldn’t change the file name here.

Here we need to define a method and assign the pytest fixture to it. This method will help us to execute at the beginning and end of the test suite.

For more information on conftest.py file please look into the pytest tutorial of conftest.py concept.




Test files

Under the test package we have defined the test files for each test scenario by using locators and methods which are defined in pages.

In this Each test file we need to define the methods and assign the fixtures to execute the test cases in given run order.

Here we have called methods which are created in the pages for contact form and enter text to perform functional testing on the webpage.


conftest.py

import pytest
from SeleniumFrameWork.base.BasePage import BaseClass
from SeleniumFrameWork.base.DriverClass import WebDriverClass
import time
import SeleniumFrameWork.configurationfiles.DeviceConfig as dc


@pytest.yield_fixture(scope='class')
def beforeClass(request):
    print('Before Class')
    driver1 = WebDriverClass()
    driver = driver1.getWebDriver(dc.bName)
    bp = BaseClass(driver)
    bp.launchWebPage(dc.url, dc.webPageTitle)
    if request.cls is not None:
        request.cls.driver = driver
    yield driver
    time.sleep(5)
    driver.quit()
    print('After Class')

test_ContactFormtest.py

import unittest
import pytest
import time
from SeleniumFrameWork.base.BasePage import BaseClass
from SeleniumFrameWork.pages.ContctFormPage import ContactForm
import SeleniumFrameWork.utilities.CustomLogger as cl

@pytest.mark.usefixtures("beforeClass","beforeMethod")
class ContactFormTest(unittest.TestCase):

    @pytest.fixture(autouse=True)
    def classObjects(self):
        self.cf = ContactForm(self.driver)
        self.bp = BaseClass(self.driver)


    @pytest.mark.run(order=2)
    def test_enterDataInForm(self):
        time.sleep(5)
        self.cf.enterName()
        self.cf.enterEmail()
        self.cf.enterMessage()
        self.cf.enterCaptha()
        self.cf.clickOnPostButton()

    @pytest.mark.run(order=1)
    def test_formPage(self):
        self.cf.clickContactForm()
        self.cf.verifyFormPage()



test_EnterTextTest.py

import unittest
import pytest
import time
from SeleniumFrameWork.pages.EnterTextPage import EnterText

@pytest.mark.usefixtures("beforeClass", "beforeMethod")
class EnterTextTest(unittest.TestCase):

    @pytest.fixture(autouse=True)
    def classObjects(self):
        self.et = EnterText(self.driver)

    @pytest.mark.run(order=4)
    def test_enterDataInEditBox(self):
        self.driver.maximize_window()
        time.sleep(2)
        self.et.enterText()
        self.et.clickOnSubmitButton()

    @pytest.mark.run(order=3)
    def test_clickOnLocatorsPage(self):
        self.et.clickOnLocatorsPage()