【问题标题】:Android Appium : Test multiple conditions first before to declare that test is failedAndroid Appium:在声明测试失败之前先测试多个条件
【发布时间】:2016-10-29 22:53:48
【问题描述】:

场景:我有不同类型的广告即将推出。一个可以点击一个按钮,另一个可以点击整个广告。 我要测试什么时候有广告出现,第一次测试通过点击按钮,如果不起作用,点击其他类型。在 appium 中,在第一个 if 条件下,如果找不到元素,它将无法通过测试。 如何在声明失败之前测试多个条件。

【问题讨论】:

    标签: android testing appium ads


    【解决方案1】:

    有很多方法可以做到这一点。在 Python 中,我会使用类似的东西:

        locators = ['.someClass', '#someID']
        for locator in locators:
            el = self.driver.find_elements_by_css_selector(locator)
            if len(el) == 1:
                break
            elif len(el) == 0:
                el = None
            else:
                self.fail('multiple elements: %s found: %d' % locator, len(el))
        self.assertIsNotNone(el, '> 1 matches found on page: %s' % locator)
        el.click()
    

    基本上如果在页面上找不到定位器,那么我们将 el 设置为 None 并尝试另一个定位器。 如果找到一个定位器(在您的情况下,我们说按钮),而不是方法中断。如果找到的定位器 > 1,则它会失败。 您必须定义唯一的定位器才能使此功能起作用。

    【讨论】:

    • 我在寻找 Java。我现在使用的最有效的方法是嵌套的 try catch 方法。这有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多