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 find_by_swip2(driver: WebDriver, by, locator) -> WebElement: driver.implicitly_wait(1) elements = driver.find_elements(by, locator) while len(elements) == 0: driver.swipe(0, 600, 0, 400) elements = driver.find_elements(by, locator) driver.implicitly_wait(5) return elements[0]
def driver(mock, desired_capabilities: dict) -> WebDriver: hostname = socket.gethostname() ip = socket.gethostbyname(hostname) driver = WebDriver(command_executor=f"http://{ip}:4723/wd/hub", desired_capabilities=desired_capabilities, direct_connection=True, keep_alive=True) driver.implicitly_wait(3) logging.debug( f"created driver with desired_capabilities: {desired_capabilities}") return driver
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)
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 create_driver(request, language): platform = request.config.option.platform assert platform in POSSIBLE_PLATFORM cap = open(f'configuration_data/{platform}_config.json').read() capabilities = json.loads(cap) if platform == ANDROID_TYPE and language: change_language_android(language) elif platform == IOS_TYPE: capabilities["language"] = language driver = WebDriver("http://0.0.0.0:4723/wd/hub", desired_capabilities=capabilities) driver._platform = platform driver.implicitly_wait(5) request.addfinalizer(driver.quit) return Driver(driver)
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()