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 driver(request) -> WebDriver: config = parse_rd_config(conf_file=request.config.getoption('--config')) appium_server_url = config.get('appium_server_url') caps = config.get('caps') driver = WebDriver(command_executor=f"http://{appium_server_url}/wd/hub", desired_capabilities=caps) yield driver driver.quit()
def quit(self): """Quits the driver and stops the session with the Mate Server, cleaning up after itself.""" # Report any left over driver command reports self.command_executor.clear_stash() # Make instance available again RemoteDriver.__instance = None try: AppiumWebDriver.quit(self) except Exception: pass # Stop the Mate client self.command_executor.mate_client.stop()
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 quit(self): """Quits the driver and stops the session with the Agent, cleaning up after itself.""" # Report any left over driver command reports self.command_executor.clear_stash() try: AppiumWebDriver.quit(self) except Exception: pass # Stop the Agent client self.command_executor.agent_client.stop() # Clean up any environment variables set in the decorator for env_var in [ EnvironmentVariable.TP_TEST_NAME, EnvironmentVariable.TP_PROJECT_NAME, EnvironmentVariable.TP_JOB_NAME, ]: EnvironmentVariable.remove(env_var)
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")
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 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 end_session(driver: WebDriver): driver.quit()
def driver_teardown(driver: WebDriver) -> None: yield None logging.debug(f"ending driver session") driver.quit()