forked from crossbrowsertesting/Selenium-101-Webinar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5-verification.py
49 lines (33 loc) · 1.29 KB
/
5-verification.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
# Create the webdriver instance
# run test locally against chrome
driver = webdriver.Chrome("./webdrivers/chromedriver")
# navigate
driver.get("http://crossbrowsertesting.github.io/login-form.html")
# find the search box
username = driver.find_element_by_id('username')
password = driver.find_element_by_id('password')
login = driver.find_element_by_id('submit')
username.send_keys('[email protected]')
password.send_keys('test123')
login.click()
try:
# selenium needs to wait for the login to finish before checking
logged_in_message = WebDriverWait(driver, 4).until(
EC.presence_of_element_located((By.ID, "logged-in")))
header = driver.find_element_by_tag_name('h2')
# check the angular class is set
assert header.get_attribute('class') == 'ng-binding'
# make sure the element isn't hidden
assert header.is_displayed()
# verify the text is what we expect
assert logged_in_message.text == "You are now logged in!"
print "PASS: successfully logged in!"
except AssertionError:
print "FAIL: did not log in!"
raw_input()
driver.quit()