I needed to write end-to-end test code in python, so Make a note of what you are doing.
Use the docker environment described in another article below.
** Build E2E test environment (python3 + selenium) with docker ** http://qiita.com/reflet/items/89ff50c991168adb3a9b
Create a code by referring to the simple test code on the following site
** [Reference site] 2.1. Simple Usage ** http://selenium-python.readthedocs.io/getting-started.html#simple-usage
python_org_search.py
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Remote(
command_executor='http://selenium-hub:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME)
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
Try running the above code
Terminal
# python python_org_search.py
Create a test code referring to the following site and try to execute it.
** [Reference site] 2.3. Using Selenium to write tests ** http://selenium-python.readthedocs.io/getting-started.html#using-selenium-to-write-tests
test_python_org_search.py
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class PythonOrgSearch(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Remote(
command_executor='http://selenium-hub:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME)
def test_search_in_python_org(self):
driver = self.driver
driver.get("http://www.python.org")
self.assertIn("Python", driver.title)
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()
Terminal
# python test_python_org_search.py
Recommended Posts