class IosTestApp(TestCase): def setUp(self): server_url = 'http://127.0.0.1:4723/wd/hub' capabilities = DesiredCapabilities.IPHONE capabilities['automationName'] = 'Appium' capabilities['platformName'] = 'iOS' capabilities['deviceName'] = 'iPhone 6' capabilities['platformVersion'] = '8.3' capabilities['browserName'] = '' capabilities[ 'app'] = 'https://github.com/appium/javascript-workshop/blob/master/apps/TestApp7.1.app.zip?raw=true' # 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_sum(self): first_number = 2 second_number = 3 # Input numbers and click button first_element = WebDriverWait(self.driver, 10).until( EC.presence_of_element_located((By.XPATH, "//UIATextField[1]"))) first_element.send_keys(first_number) self.driver.find_element_by_xpath("//UIATextField[2]").send_keys(second_number) self.driver.find_element_by_accessibility_id("ComputeSumButton").click() # Check expected result result = int(self.driver.find_element_by_xpath("//UIAStaticText[1]").text) assert_equal(first_number + second_number, result, "Wrong sum")
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 test_create_project(driver: WebDriver): driver.find_element_by_xpath( '//XCUIElementTypeButton[@name="+ Create new"]').click() test_project_name = 'test-project-' + random_characters() driver.find_element_by_xpath('//XCUIElementTypeTextField').send_keys( test_project_name) driver.find_element_by_xpath( '//XCUIElementTypeButton[@name="Save"]').click() time.sleep(2) driver.find_element_by_xpath( '//XCUIElementTypeStaticText[@name="{}"]'.format( test_project_name)).click() time.sleep(2)
class IosTestApp(TestCase): """This is the same test as test_ios.py but without using Toolium""" def setUp(self): server_url = 'http://127.0.0.1:4723/wd/hub' app = 'https://github.com/appium/javascript-workshop/blob/master/apps/TestApp7.1.app.zip?raw=true&fake=.zip' capabilities = DesiredCapabilities.IPHONE capabilities['automationName'] = 'Appium' capabilities['platformName'] = 'iOS' capabilities['deviceName'] = 'iPhone 6' capabilities['platformVersion'] = '8.3' capabilities['browserName'] = '' capabilities['app'] = app # 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_sum(self): first_number = 2 second_number = 3 # Input numbers and click button first_element = WebDriverWait(self.driver, 10).until( EC.presence_of_element_located((By.XPATH, "//UIATextField[1]"))) first_element.send_keys(first_number) self.driver.find_element_by_xpath("//UIATextField[2]").send_keys( second_number) self.driver.find_element_by_accessibility_id( "ComputeSumButton").click() # Check expected result result = int( self.driver.find_element_by_xpath("//UIAStaticText[1]").text) assert_equal(first_number + second_number, result, "Wrong sum")
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 test_setting(): capabilities = { "deviceName": "iPhone SE", "udid": "b3346f9b0c4797e7a68fffb4532e1727bc23ad76", "platformName": "iOS", "automationName": "XCUITest", "app": "Settings", "xcodeSigningId": "iPhone Developer", "updatedWDABundleId": "com.afkTestTeam.WebDriverAgentLib", "shouldWaitForQuiescence": "False", "fastReset": True } driver = WebDriver("http://0.0.0.0:4723/wd/hub", desired_capabilities=capabilities) driver.implicitly_wait(5) general = driver.find_element_by_xpath( '//XCUIElementTypeCell[@name="General"]') click_on_element(driver, general) accessibility = driver.find_element_by_xpath( '//XCUIElementTypeCell[@name="Accessibility"]') click_on_element(driver, accessibility) time.sleep(5) hearing_devoces = driver.find_element_by_xpath( '//XCUIElementTypeCell[contains(@name, "Hearing Devices")]') while not hearing_devoces.is_displayed(): driver.execute_script("mobile: swipe", {"direction": "up"}) while hearing_devoces.is_displayed(): hearing_devoces = driver.find_element_by_xpath( '//XCUIElementTypeCell[contains(@name, "Hearing Devices")]') hearing_devoces.click() bluetooth_switch = driver.find_elements_by_xpath( '//XCUIElementTypeSwitch[@name="Bluetooth"]') if bluetooth_switch: bluetooth_switch[0].click() test_hearing_device(driver) driver.back() time.sleep(1) driver.execute_script("mobile: swipe", {"direction": "up"}) slider = driver.find_element_by_xpath( '//XCUIElementTypeCell[@name="Left-Right Stereo Balance"]/XCUIElementTypeOther[3]' ) old_value = slider.get_attribute('value') action = TouchAction(driver) action.tap(slider, x=randint(0, 50), y=10) action.perform() new_value = slider.get_attribute('value') assert old_value != new_value time.sleep(2) driver.quit()
def test_application(): capabilities = { "deviceName": "iPhone SE", "udid": "b3346f9b0c4797e7a68fffb4532e1727bc23ad76", "platformName": "iOS", "automationName": "XCUITest", "app": "/Users/pavlo.tsyupka/Downloads/Nucleus Smart 1.431.2.zip", "xcodeSigningId": "iPhone Developer", "updatedWDABundleId": "com.afkTestTeam.WebDriverAgentLib", "shouldWaitForQuiescence": "False", "fastReset": True } driver = WebDriver("http://0.0.0.0:4723/wd/hub", desired_capabilities=capabilities) driver.implicitly_wait(5) for _ in range(5): driver.execute_script("mobile: swipe", {"direction": "left"}) time.sleep(0.125) demo_mode_button = driver.find_element_by_name('demoModeButton') demo_mode_button.click() volume_open_button = driver.find_element_by_xpath( '//XCUIElementTypeCell[@name="volume"]') volume_open_button.click() plus_button = driver.find_element_by_xpath( '//XCUIElementTypeOther[4]/XCUIElementTypeOther/XCUIElementTypeButton[1]' ) minus_button = driver.find_element_by_xpath( '//XCUIElementTypeOther[4]/XCUIElementTypeOther/XCUIElementTypeButton[2]' ) value_element = driver.find_element_by_xpath( '//XCUIElementTypeCell[@name="volume"]') old_value = value_element.get_attribute('value') plus_button.click() time.sleep(1) new_value = value_element.get_attribute('value') assert old_value != new_value minus_button.click() time.sleep(1) new_value = value_element.get_attribute('value') assert old_value == new_value menu_button = driver.find_element_by_xpath( '//XCUIElementTypeButton[@name="Settings menu"]') menu_button.click() time.sleep(1) exit_button = driver.find_element_by_xpath( '//XCUIElementTypeCell[@name="exitPracticeMode"]') exit_button.click() time.sleep(1) for _ in range(5): driver.execute_script("mobile: swipe", {"direction": "right"}) time.sleep(0.125) driver.quit()
def test_hearing_device(driver: WebDriver): # TODO: selectors in this function may be isn't correct, need recheck them with real device cochlear_device = driver.find_elements_by_xpath( '//XCUIElementTypeCell[contains(@name, "Cochlear")]') if not cochlear_device: # If no device found will skip test return # Connect to hearing device cochlear_device[0].click() # Change between available Presets presets = driver.find_elements_by_xpath( '//XCUIElementTypeOther[@name="Master Volume"]') # If available more than 1 Presets will change one them if len(presets) > 1: presets[-1].click() time.sleep(1) assert not presets[0].is_selected() # Change "Master Volume"//XCUIElementTypeCell[contains(@name, "Cochlear")] master_volume_slider = driver.find_element_by_xpath( '//XCUIElementTypeOther[@name="Master Volume"]') old_value = master_volume_slider.get_attribute('value') action = TouchAction(driver) action.tap(master_volume_slider, x=50, y=10) action.perform() new_value = master_volume_slider.get_attribute('value') # Check if slider value changed assert old_value != new_value # Allow/disallow streaming to paired Sound Processor streaming_switch = driver.find_element_by_xpath( '//XCUIElementTypeSwitch[contains(@name, "Streaming")') # Disallow streaming value if streaming_switch.is_selected(): streaming_switch.click() time.sleep(1) # Check if streaming disallowed assert not streaming_switch.is_selected() # Allow streaming, and check if it allowed streaming_switch.click() time.sleep(1) assert streaming_switch.is_selected() # Start/Stop LIVE LISTEN on iOS Mobile Device start_live_listen_button = driver.find_element_by_xpath( '//XCUIElementTypeOther[contains(@name, "Start")]') start_live_listen_button.click() time.sleep(1) assert not driver.find_elements_by_xpath( '//XCUIElementTypeOther[contains(@name, "Start")]') stop_live_listen_button = driver.find_element_by_xpath( '//XCUIElementTypeOther[contains(@name, "Stop")]') stop_live_listen_button.click() time.sleep(1) assert not driver.find_elements_by_xpath( '//XCUIElementTypeOther[contains(@name, "Stop")]') assert driver.find_elements_by_xpath( '//XCUIElementTypeOther[contains(@name, "Start")]') driver.back()