-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
47 lines (38 loc) · 1.28 KB
/
test.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
import unittest
from selenium import webdriver
import time
class Selenium2OnLocal(unittest.TestCase):
def setUp(self):
self.driver = webdriver.PhantomJS()
self.driver.get('http://www.mytokri.com/')
self.driver.maximize_window()
def test_from_check404(self):
error404 = "MyTokri - 404 Error Page"
error404 = error404.lower()
links = self.driver.find_elements_by_xpath("//*[@href]")
urls = []
for element in links:
link = element.get_attribute("href")
url = str(link)
if (url.find('http://www.mytokri.com/') != -1):
urls.append(url)
print len(urls)
error = 0
for url in urls:
self.driver.get(url)
title = self.driver.title
try:
title = str(title).lower()
if (title.find(error404) == -1):
#print "Correct URL - " + url
continue
else:
error = error + 1
print "Error at URL - " + url
except UnicodeEncodeError:
pass
print "Total 404 Error in HomePage- " + error
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main()