forked from upgundecha/learnsewithpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathandroid_test.py
More file actions
47 lines (37 loc) · 1.51 KB
/
Copy pathandroid_test.py
File metadata and controls
47 lines (37 loc) · 1.51 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
import unittest
from appium import webdriver
class SearchProductsOnAndroid(unittest.TestCase):
def setUp(self):
desired_caps = {}
# platform
desired_caps['device'] = 'Android'
# platform version
desired_caps['version'] = '4.3'
# mobile browser
desired_caps['app'] = 'Chrome'
# to connect to Appium server use RemoteWebDriver
# and pass desired capabilities
self.driver = \
webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
self.driver.get('http://demo-store.seleniumacademy.com/')
self.driver.implicitly_wait(30)
def test_search_by_category(self):
# click on search icon
self.driver.find_element_by_xpath("//a[@href='#header-search']").click()
# get the search textbox
self.search_field = self.driver.find_element_by_name('q')
self.search_field.clear()
# enter search keyword and submit
self.search_field.send_keys('phones')
self.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("//div[@class='category-products']/ul/li")
# check count of products shown in results
self.assertEqual(3, len(products))
def tearDown(self):
# close the browser window
self.driver.quit()
if __name__ == '__main__':
unittest.main(verbosity=2)