...
Code Block | ||
---|---|---|
| ||
import time
from selenium import webdriver
from selenium.webdriver.common.alert import Alert
driver = object
def setup():
global driver
driver = webdriver.Chrome('c:\\pf\\bin\\chromedriver.exe')
# Optional argument, if not specified will search path.
#driver = webdriver.Chrome()
def test_some_functionality():
setup()
driver.get('file://C:/work/git/nodejs-sky/selenium-setup/simple_page.html')
input_field = driver.find_element_by_id("message")
input_field.send_keys("help me!")
submitBtn = driver.find_element_by_id("submit-button")
time.sleep(2) # Let the user actually see something!
submitBtn.click()
time.sleep(3)
alert = Alert(driver)
alert.accept()
time.sleep(3)
driver.get('http://www.google.com/')
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
assert True
test_some_functionality() |
Notice we put any intialisation code in something called setup(). This is so we can reuse this code across multiple tests.
...