Uh oh!
There was an error while loading. Please reload this page.
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 8
Expand file tree
/
Copy pathbasic.py
More file actions
Latest commit
85 lines (65 loc) · 3.33 KB
/
Copy pathbasic.py
File metadata and controls
85 lines (65 loc) · 3.33 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Please visit http://selenium-python.readthedocs.org/en/latest/index.html for detailed installation and instructions
# Getting started: http://docs.seleniumhq.org/docs/03_webdriver.jsp
# API details: https://github.com/SeleniumHQ/selenium#selenium
# Requests is the easiest way to make RESTful API calls in Python. You can install it by following the instructions here:
# http://docs.python-requests.org/en/master/user/install/
importunittest
fromseleniumimportwebdriver
importrequests
classBasicTest(unittest.TestCase):
defsetUp(self):
# Put your username and authey below
# You can find your authkey at crossbrowsertesting.com/account
self.username="user@email.com"
self.authkey="12345"
self.api_session=requests.Session()
self.api_session.auth= (self.username,self.authkey)
self.test_result=None
caps= {}
caps['name'] ='Basic Example'
caps['build'] ='1.0'
caps['browserName'] ='Safari'
caps['version'] ='8'
caps['platform'] ='Mac OSX 10.10'
caps['screenResolution'] ='1366x768'
caps['record_video'] ='true'
caps['record_network'] ='false'
# start the remote browser on our server
self.driver=webdriver.Remote(
desired_capabilities=caps,
command_executor="http://%s:%s@hub.crossbrowsertesting.com:80/wd/hub"%(self.username,self.authkey)
)
self.driver.implicitly_wait(20)
deftest_CBT(self):
# We wrap this all in a try/except so we can set pass/fail at the end
try:
# load the page url
print('Loading Url')
self.driver.get('http://crossbrowsertesting.github.io/selenium_example_page.html')
# maximize the window - DESKTOPS ONLY
#print('Maximizing window')
#self.driver.maximize_window()
#check the title
print('Checking title')
self.assertEqual("Selenium Test Example Page", self.driver.title)
# if we are still in the try block after all of our assertions that
# means our test has had no failures, so we set the status to "pass"
self.test_result='pass'
exceptAssertionErrorase:
# if any assertions are false, we take a snapshot of the screen, log
# the error message, and set the score to "during tearDown()".
snapshot_hash=self.api_session.post('https://crossbrowsertesting.com/api/v3/selenium/'+self.driver.session_id+'/snapshots').json()['hash']
self.api_session.put('https://crossbrowsertesting.com/api/v3/selenium/'+self.driver.session_id+'/snapshots/'+snapshot_hash,
data={'description':"AssertionError: "+str(e)})
self.test_result='fail'
raise
deftearDown(self):
print("Done with session %s"%self.driver.session_id)
self.driver.quit()
# Here we make the api call to set the test's score.
# Pass it it passes, fail if an assertion fails, unset if the test didn't finish
ifself.test_resultisnotNone:
self.api_session.put('https://crossbrowsertesting.com/api/v3/selenium/'+self.driver.session_id,
data={'action':'set_score', 'score':self.test_result})
if__name__=='__main__':
unittest.main()