Closed
Description
Feature and motivation
There are currently no instructions in the Test Runners section for Python. I would like to contribute the following:
Pytest
Install pytest dependency
pip install pytest
Now, run test using:
pytest
Unittest
Save the script to test_web_form.py
file
import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
class TestWebForm(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
def tearDown(self):
self.driver.quit()
def test_eight_components(self):
self.driver.get("https://www.selenium.dev/selenium/web/web-form.html")
title = self.driver.title
self.assertEqual(title, "Web form")
self.driver.implicitly_wait(0.5)
text_box = self.driver.find_element(by=By.NAME, value="my-text")
submit_button = self.driver.find_element(by=By.CSS_SELECTOR, value="button")
text_box.send_keys("Selenium")
submit_button.click()
message = self.driver.find_element(by=By.ID, value="message")
value = message.text
self.assertEqual(value, "Received!")
if __name__ == "__main__":
unittest.main()
Run the file with using:
python test_web_form.py
Metadata
Metadata
Assignees
Labels
No labels