forked from upgundecha/learnsewithpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute_javascript_test.py
More file actions
45 lines (34 loc) · 1.55 KB
/
Copy pathexecute_javascript_test.py
File metadata and controls
45 lines (34 loc) · 1.55 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
from selenium import webdriver
import unittest
class ExecuteJavaScriptTest (unittest.TestCase):
def setUp(self):
# create a new Firefox session
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.driver.maximize_window()
# navigate to the application home page
self.driver.get('http://demo-store.seleniumacademy.com/')
def test_search_by_category(self):
# get the search textbox
search_field = self.driver.find_element_by_name('q')
self.highlightElement(search_field)
search_field.clear()
# enter search keyword and submit
self.highlightElement(search_field)
search_field.send_keys('phones')
search_field.submit()
# get all the anchor elements which have product names displayed
# currently on result page using find_elements_by_xpath method
products = self.driver.find_elements_by_xpath("//h2[@class='product-name']/a")
# check count of products shown in results
self.assertEqual(3, len(products))
def tearDown(self):
# close the browser window
self.driver.quit()
def highlightElement(self, element):
self.driver.execute_script("arguments[0].setAttribute('style', arguments[1]);",
element, "color: green; border: 2px solid green;")
self.driver.execute_script("arguments[0].setAttribute('style', arguments[1]);",
element , "")
if __name__ == '__main__':
unittest.main(verbosity=2)