Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Created July 5, 2024 12:56
Show Gist options
  • Save SarahElson/4fc93f92d3384993fc73824f913f8f52 to your computer and use it in GitHub Desktop.
Save SarahElson/4fc93f92d3384993fc73824f913f8f52 to your computer and use it in GitHub Desktop.
Python Unit Testing: A Complete Tutorial
import unittest
import HtmlTestRunner
import sys
sys.path.append(sys.path[0] + "/..")
from setup.setup import testSet
from locators.formLocators import formWebAction
set_up = testSet()
form = formWebAction(set_up.driver)
class formSampleTest(unittest.TestCase):
def test_unit_user_should_able_to_fill_form(self):
try:
form.getWeb("https://www.lambdatest.com/selenium-playground/input-form-demo")
set_up.testSetup()
title = form.getTitle()
self.assertIn("Selenium", title, "Selenium is not in title")
form.fillName("Idowu")
form.fillEmail("fakeemail@gmail.com")
form.fillPassword("secret")
form.fillCompany("Lambdatest")
form.fillWebsite("someweb.com")
form.fillCountry("Nigeria")
form.fillCity("A City")
form.fillAddress1("Den street")
form.fillAddress2("Den street")
form.fillState("Lagos")
form.fillZipCode("240100")
form.submit()
except AssertionError as e:
print("Something went wrong", e)
set_up.tearDown()
if __name__ == "__main__":
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='DemoFormHTML_results'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment