def get_clildelement(self,eles:WebDriver,key): '''封装从父元素获取子元素''' data = self.read_ini.get_value(key) by = data.split('>')[0] value = data.split('>')[1] try: if by == 'id': ele = eles.find_element_by_id(value) return ele elif by == 'xpath': ele = eles.find_element_by_xpath(value) return ele except Exception as e: self.logger.info('查找元素出现异常,异常信息为:' + {e})
class Tabs(TestCase): """This is the same test as test_android.py but without using Toolium""" def setUp(self): server_url = 'http://127.0.0.1:4723/wd/hub' capabilities = DesiredCapabilities.ANDROID capabilities['automationName'] = 'Appium' capabilities['platformName'] = 'Android' capabilities['deviceName'] = 'Android Emulator' capabilities['browserName'] = '' capabilities[ 'app'] = 'https://github.com/appium/javascript-workshop/blob/master/apps/ApiDemos.apk?raw=true' capabilities['appWaitActivity'] = '' # Create a new appium driver before each test self.driver = WebDriver(command_executor=server_url, desired_capabilities=capabilities) self.driver.implicitly_wait(5) def tearDown(self): # Close driver self.driver.quit() def test_change_tab(self): # Open tabs activity option_locator = 'new UiScrollable(new UiSelector().scrollable(true).instance(0))' \ '.scrollIntoView(new UiSelector().text("{}").instance(0));' self.driver.find_element_by_android_uiautomator( option_locator.format('Views')).click() self.driver.find_element_by_android_uiautomator( option_locator.format('Tabs')).click() self.driver.find_element_by_android_uiautomator( option_locator.format('1. Content By Id')).click() # Check that the first tab is open content1 = self.driver.find_element_by_id( 'io.appium.android.apis:id/view1') assert_equal('tab1', content1.text) # Open second tab and check content self.driver.find_element_by_xpath( '(//android.widget.TabWidget//android.widget.TextView)[2]').click( ) content2 = self.driver.find_element_by_id( 'io.appium.android.apis:id/view2') assert_equal('tab2', content2.text)
def method(self, driver: WebDriver, method, value): ele = None if method == 'id': ele = driver.find_element_by_id(value) elif method == 'xpath': ele = driver.find_element_by_xpath(value) elif method == 'accessibility': ele = driver.find_element_by_accessibility_id(value) else: return 'No element' return ele
def run(self, driver: WebDriver): for step in self.steps: print(step) # {'id': 'tv_agree'} element = None if isinstance(step, dict): if "id" in step.keys(): element = driver.find_element_by_id(step["id"]) if step.keys() != "tv_top_list": element.click() elif "xpath" in step.keys(): element = driver.find_element_by_xpath(step["xpath"]) if "input" in step.keys(): element.send_keys(step["input"])
class Tabs(TestCase): """This is the same test as test_android.py but without using Toolium""" def setUp(self): server_url = 'http://127.0.0.1:4723/wd/hub' capabilities = DesiredCapabilities.ANDROID capabilities['automationName'] = 'Appium' capabilities['platformName'] = 'Android' capabilities['deviceName'] = 'Android Emulator' capabilities['browserName'] = '' capabilities['app'] = 'https://github.com/appium/javascript-workshop/blob/master/apps/ApiDemos.apk?raw=true' capabilities['appWaitActivity'] = '' # Create a new appium driver before each test self.driver = WebDriver(command_executor=server_url, desired_capabilities=capabilities) self.driver.implicitly_wait(5) def tearDown(self): # Close driver self.driver.quit() def test_change_tab(self): # Open tabs activity option_locator = 'new UiScrollable(new UiSelector().scrollable(true).instance(0))' \ '.scrollIntoView(new UiSelector().text("{}").instance(0));' self.driver.find_element_by_android_uiautomator(option_locator.format('Views')).click() self.driver.find_element_by_android_uiautomator(option_locator.format('Tabs')).click() self.driver.find_element_by_android_uiautomator(option_locator.format('1. Content By Id')).click() # Check that the first tab is open content1 = self.driver.find_element_by_id('io.appium.android.apis:id/view1') assert_equal('tab1', content1.text) # Open second tab and check content self.driver.find_element_by_xpath('(//android.widget.TabWidget//android.widget.TextView)[2]').click() content2 = self.driver.find_element_by_id('io.appium.android.apis:id/view2') assert_equal('tab2', content2.text)
def run(self, driver: WebDriver): for step in self.steps: element = None if isinstance(step, dict): if "id" in step.keys(): element = driver.find_element_by_id(step.get("id")) elif "xpath" in step.keys(): element = driver.find_element_by_xpath(step.get("xpath")) else: print(step.keys()) if "input" in step.keys(): element.send_keys(step.get("input")) elif "get" in step.keys(): text = element.get_attribute(step.get("get")) elif "eq" in step.keys(): assert float(text) > float(step.get("eq")) else: element.click()
def run(self, driver: WebDriver): for step in self.steps: element = None if isinstance(step, dict): if "id" in step.keys(): element = driver.find_element_by_id(step["id"]) elif "xpath" in step.keys(): element = driver.find_element_by_xpath(step["xpath"]) else: print(step.keys()) if "input" in step.keys(): element.send_keys(step["input"]) else: element.click() if "get" in step.keys(): text = element.get_attribute(step["get"]) return text
def find_element_by_id(self, el_id): el_id = self.get_element_id(el_id) return AppiumDriver.find_element_by_id(self, el_id)
def find_element_by_id(self, el_id): el_id = self.get_element_id(el_id) return AppiumDriver.find_element_by_id(self, el_id)