-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy pathselenium_links.py
62 lines (57 loc) · 1.47 KB
/
selenium_links.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
import time
import traceback
import sys
import urllib
import re
url = ""
def test(links,driver):
p=0
f=0
t=0
for k in range(len(links)):
x = links[k]
foo = ""
t=t+1
try:
link = driver.find_element_by_id(x[0])
link.click()
foo = driver.page_source
driver.back()
assert(x[1] in foo)
print k,"PASS:",x[0],"==>",x[1],"in page"
p=p+1
except:
print k,"FAIL:",x[0],"==>",x[1],"not in page"
traceback.print_exc()
f=f+1
print 'Link testing complete. PASS:',p,'FAIL:',f,'Total:',t
url = ""
if len(sys.argv) > 1:
client = sys.argv[1]
if(len(sys.argv)>2):
url = sys.argv[2]
else:
client = "Firefox"
if url == "":
url = "http://127.0.0.1/staging/"
mainlinks = [("linkhome","library for numerical computations"),
("linkworkshop","IN"),
("linkdoc","vectors and matrices"),
("linklib","var numeric"),
("linklibmin","var numeric="),]
driver=0
print "Link testing."
try:
driver = eval('webdriver.'+client+'()')
print "Using",client
driver.implicitly_wait(10)
driver.get(url)
test(mainlinks,driver)
driver.quit()
except:
print "Could not do browser",client
if driver:
driver.quit()