【问题标题】:Multiple waiting approaches in #Appium#Appium 中的多种等待方法
【发布时间】:2022-12-22 18:38:30
【问题描述】:

什么是最好的显式等待在 Appium 中实现?

我知道有3种可能性:

  • 使用 wait FluentWait 提供
  • 使用WebDriverWait来自硒支持仅在内部扩展FluentWait
  • 使用Appium的本机 AppiumFluentWait 也从 FluentWait 扩展.

我们的框架正在经历一些重大变化,现在是为未来做好准备的最佳时机。

当前的实现正在使用 WebDriverWait 但为此我们必须显式添加 selenium-support 库的导入,因为 Appium 的实现只在运行时导入它。

使用显式导入 selenium-support 库是否存在一些问题,因为 Appium 团队考虑在此范围内添加库导入,AppiumFluentWait 是更好的方法吗?

但是 appium 再次删除了 selenium ex 中的一些常用功能:MobileElement 及其新版本,这种方法将来是否容易被删除?

输出为:mvn dependency:tree

 +- io.appium:java-client:jar:8.3.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-api:jar:4.7.1:compile (version selected from constraint [4.7.0,5.0))
[INFO] |  +- org.seleniumhq.selenium:selenium-remote-driver:jar:4.7.1:compile (version selected from constraint [4.7.0,5.0))
[INFO] |  |  +- com.google.auto.service:auto-service-annotations:jar:1.0.1:compile
[INFO] |  |  +- com.google.auto.service:auto-service:jar:1.0.1:compile
[INFO] |  |  |  \- com.google.auto:auto-common:jar:1.2:compile
[INFO] |  |  +- io.netty:netty-buffer:jar:4.1.84.Final:compile
[INFO] |  |  +- io.netty:netty-codec-http:jar:4.1.84.Final:compile
[INFO] |  |  |  \- io.netty:netty-codec:jar:4.1.84.Final:compile
[INFO] |  |  +- io.netty:netty-common:jar:4.1.84.Final:compile
[INFO] |  |  +- io.netty:netty-transport-classes-epoll:jar:4.1.84.Final:compile
[INFO] |  |  +- io.netty:netty-transport-classes-kqueue:jar:4.1.84.Final:compile
[INFO] |  |  +- io.netty:netty-transport-native-epoll:jar:4.1.84.Final:linux-x86_64
[INFO] |  |  +- io.netty:netty-transport-native-kqueue:jar:4.1.84.Final:osx-x86_64
[INFO] |  |  +- io.netty:netty-transport-native-unix-common:jar:4.1.84.Final:compile
[INFO] |  |  +- io.netty:netty-transport:jar:4.1.84.Final:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-api:jar:1.19.0:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-context:jar:1.19.0:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-exporter-logging:jar:1.19.0:compile
[INFO] |  |  |  +- io.opentelemetry:opentelemetry-sdk-metrics:jar:1.19.0:compile
[INFO] |  |  |  \- io.opentelemetry:opentelemetry-sdk-logs:jar:1.19.0-alpha:compile
[INFO] |  |  |     \- io.opentelemetry:opentelemetry-api-logs:jar:1.19.0-alpha:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-sdk-common:jar:1.19.0:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:jar:1.19.0:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:jar:1.19.0-alpha:compile
[INFO] |  |  |  \- io.opentelemetry:opentelemetry-exporter-common:jar:1.19.0:runtime
[INFO] |  |  +- io.opentelemetry:opentelemetry-sdk-trace:jar:1.19.0:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-sdk:jar:1.19.0:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-semconv:jar:1.19.0-alpha:compile
[INFO] |  |  +- io.ous:jtoml:jar:2.0.0:compile
[INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.12.18:compile
[INFO] |  |  +- org.apache.commons:commons-exec:jar:1.3:compile
[INFO] |  |  +- org.asynchttpclient:async-http-client:jar:2.12.3:compile
[INFO] |  |  |  +- org.asynchttpclient:async-http-client-netty-utils:jar:2.12.3:compile
[INFO] |  |  |  +- io.netty:netty-codec-socks:jar:4.1.60.Final:compile
[INFO] |  |  |  +- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.60.Final:compile
[INFO] |  |  |  +- io.netty:netty-transport-native-kqueue:jar:osx-x86_64:4.1.60.Final:compile
[INFO] |  |  |  +- org.reactivestreams:reactive-streams:jar:1.0.3:compile
[INFO] |  |  |  +- com.typesafe.netty:netty-reactive-streams:jar:2.0.4:compile
[INFO] |  |  |  \- com.sun.activation:jakarta.activation:jar:1.2.2:compile
[INFO] |  |  +- org.seleniumhq.selenium:selenium-http:jar:4.7.1:compile
[INFO] |  |  |  \- dev.failsafe:failsafe:jar:3.3.0:compile
[INFO] |  |  +- org.seleniumhq.selenium:selenium-json:jar:4.7.1:compile
[INFO] |  |  \- org.seleniumhq.selenium:selenium-manager:jar:4.7.1:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-support:jar:4.7.1:runtime (version selected from constraint [4.7.0,5.0))
[INFO] |  +- com.google.code.gson:gson:jar:2.10:compile
[INFO] |  +- cglib:cglib:jar:3.3.0:runtime
[INFO] |  |  \- org.ow2.asm:asm:jar:7.1:runtime
[INFO] |  +- commons-validator:commons-validator:jar:1.7:runtime
[INFO] |  |  +- commons-beanutils:commons-beanutils:jar:1.9.4:runtime
[INFO] |  |  +- commons-digester:commons-digester:jar:2.1:runtime
[INFO] |  |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  |  \- commons-collections:commons-collections:jar:3.2.2:runtime
[INFO] |  +- org.apache.commons:commons-lang3:jar:3.12.0:compile
[INFO] |  +- commons-io:commons-io:jar:2.11.0:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:2.0.5:compile

【问题讨论】:

    标签: selenium automation appium wait appium-java


    【解决方案1】:

    所以首先它取决于架构。
    第二,你真的需要 FluentWait 吗? WebDriverWait 类有可选参数:timeout、poll_frequency 和 ignored_exceptions,您可以在那里提供它们。

    :Args:
                - driver - Instance of WebDriver (Ie, Firefox, Chrome or Remote)
                - timeout - Number of seconds before timing out
                - poll_frequency - sleep interval between calls
                  By default, it is 0.5 second.
                - ignored_exceptions - iterable structure of exception classes ignored during calls.
                  By default, it contains NoSuchElementException only.
    

    我怎么看:

    1. 等待 = WebDriverWait(驱动程序,10)

    2. s_wait = WebDriverWait(驱动程序, 3)

    3. l_wait = WebDriverWait(驱动程序, 30)

    4. fl_wait = WebDriverWait(driver, 10, poll_frequency=1, ignored_exceptions=[ElementNotVisibleException])

    5. 然后实现返回的方法:waits

      def 等待(自我,定位器,等待:WebDriverWait = None): 如果等待是无: 等待 = self._wait 返回 wait.until(ec.presence_of_element_located(定位器))

      然后在需要的时候调用必要的方法,一般在基类内部实现即可
      python 中的示例,但您可以重用逻辑

    【讨论】:

      猜你喜欢
      • 2018-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-10
      • 2013-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多