コード例 #1
0
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")
コード例 #2
0
def try_find_element(web_driver: WebDriver, by: FindElementBy, unique_val, retry_count, ignore_if_not_found=False) \
        -> WebElement:
    """
    attempts to find element within defined retry count.
    raises NoSuchElementException if ignore_if_not_found=false
    """
    element = None
    retried = 0
    while True:
        try:
            if by == FindElementBy.CLASS:
                element = web_driver.find_element_by_class_name(unique_val)
            elif by == FindElementBy.NAME:
                element = web_driver.find_element_by_name(unique_val)
            elif by == FindElementBy.AUTOMATION_ID:
                element = web_driver.find_element_by_accessibility_id(
                    unique_val)
        except NoSuchElementException:
            retried = retried + 1
            if retried > retry_count:
                if ignore_if_not_found:
                    return None
                raise NoSuchElementException
            else:
                sleep(1)
                continue
        break
    return element
コード例 #3
0
 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
コード例 #4
0
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")