SeleniumHQ / seleniumhq.github.io

Official Selenium website and documentation
https://selenium.dev
Apache License 2.0
1.13k stars 1.32k forks source link

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

Closed Ankit3794 closed 2 months ago

Ankit3794 commented 1 year ago

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

github-actions[bot] commented 1 year ago

@Ankit3794, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

titusfortner commented 1 year ago

I'm looking to try to move this test runners section to a new page with #1479

shbenzer commented 2 months ago

This may feature may be closed with #1479 and #1861

diemol commented 2 months ago

Thank you, @shbenzer!