Skip to content

[🚀 Feature]: Add instructions for Python in the 'Test Runners' section #1474

Closed
@Ankit3794

Description

@Ankit3794

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions