driver.manage.wait(长超时)和Explicit等待之间的区别 [英] Difference between driver.manage.wait(long timeout) and Explicit wait

查看:114
本文介绍了driver.manage.wait(长超时)和Explicit等待之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能说出:的不同用法?

Could anyone say the difference use of the :

driver.manage().wait(long timeout)

WebDriverWait wait = new WebDriverWait(driver, WAIT_IN_SECONDS) 

(EXPLICIT WAIT)了解我将来的参考.

(EXPLICIT WAIT) to understand my future reference.

请原谅我这个问题对我自己在自动化领域的新蜂来说是愚蠢的.

Please pardon me the questions is silly for new bee of my self in automation.

这是显式等待的简单形式吗?

Is it the simple form of the explicit wait?

推荐答案

driver.manage.wait(long timeout)

driver.manage.wait(long timeout) 实际上是 java.lang.Object.wait() 方法来自

driver.manage.wait(long timeout)

driver.manage.wait(long timeout) is actually the java.lang.Object.wait() method is from the java.lang.Object Class which causes the current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object or a specified amount of time has been elapsed. The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until another thread notifies threads waiting on this object's monitor to wake up either through a call to the notify method or the notifyAll method. The thread then waits until it can re-obtain ownership of the monitor and resumes execution.

java.lang.Object.wait() 方法的声明如下:

The declaration of java.lang.Object.wait() method is as follows :

public final void wait() throws InterruptedException
{
    //code logic
}

参数

timeout - the maximum time to wait in milliseconds.

返回值

This method does not return a value.

用法

在一个参数版本中,可能会发生中断和虚假唤醒,因此应始终按如下所示在循环中使用此方法:

Usage

In the one argument version, interrupts and spurious wakeups are possible so this method should always be used in a loop as follows :

 synchronized (obj) {
     while (<condition does not hold>)
         obj.wait();
     ... // Perform action appropriate to condition
 }

此方法只能由作为该对象的监视器的所有者的线程调用.

This method should only be called by a thread that is the owner of this object's monitor.

投掷:

  • InterruptedException :如果另一个线程中断了当前线程.抛出此异常后,将清除当前线程的中断状态.
  • IllegalArgumentException :如果超时值为负.
  • IllegalMonitorStateException :如果当前线程不是对象监视器的所有者.

Explicit Wait 是您为WebDriver实例定义,配置和实现的代码块,以等待满足特定条件后再继续下一行代码.有一些方法可以帮助我们实现ExplicitWait,该方法只会等待所需的时间.将WebDriverWait与ExpectedCondition结合使用是可以实现ExplicitWait的方法之一.

Explicit Wait is a code block you define, configure and implement for the WebDriver instance to wait for a certain condition to be met before proceeding for the next line of code. There are some methods that helps us to implement ExplicitWait that will wait only as long as required. WebDriverWait in combination with ExpectedCondition is one of the way ExplicitWait can be achieved.

您可以在 Explicit Wait 上找到详细的讨论及其在质量检查中的实现 obj.wait() WebDriverWait 没有关系. obj.wait() 处理线程级别的内部逻辑,而 WebDriverWait 处理 HTML DOM 范围内的事件.

obj.wait() have no relation with WebDriverWait. obj.wait() deals with the internal logic at thread-level where as WebDriverWait deals within the scope of HTML DOM.

这篇关于driver.manage.wait(长超时)和Explicit等待之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆