This repository was archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path6-screenshots.py
More file actions
53 lines (36 loc) · 1.47 KB
/
6-screenshots.py
File metadata and controls
53 lines (36 loc) · 1.47 KB
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
47
48
49
50
51
52
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
from os import getcwd
# 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('not-a-user@crossbrowsertesting.com')
password.send_keys('not-the-password')
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 Exception:
print "FAIL: did not log in!"
screenshot_fpath = getcwd() + '/on-error.png'
driver.get_screenshot_as_file(screenshot_fpath)
print ('saved screenshot to ' + screenshot_fpath)
driver.quit()