Three ways to appium automated test waits

Source: Internet
Author: User

First kind of sleep ():

Set the fixed sleep time. The Python time package provides the Sleep method sleep (), which can be used to hibernate when the time package is imported and the script executes using sleep ().

Python

# Import Time Package Import Time Time.sleep ()

Java

Thread.Sleep (6000)  // Force wait 6s

Second type of implicitly_wait (): Implicit wait

It is a timeout wait provided by Webdirver. Implicitly waits for an element to be found, or a command to complete. Throws an exception if the set time is exceeded and the element is still not positioned.
#当使用了隐士等待执行测试的时候, if Webdriver does not find an element in the DOM, it will continue to wait beyond the set time to throw an exception that cannot find the element.
#换句话说, when the lookup element or element does not appear immediately, the implicit wait waits for some time to find the DOM, the default time is 0
#一旦设置了隐式等待, it exists in the declaration cycle of the entire Webdriver object instance, implicitly waiting for the test to be slow for a normal response application,
#它将会在寻找每个元素的时候都进行等待, this increases the time of the entire test execution.

The #implicitly_wait () method is more intelligent than sleep (), the latter can only choose a fixed time waiting, the former may be in a time range of intelligent waiting.

Python

Self.driver.implicitly_wait (#全局)   wait 10s

Java

Driver.manage (). Timeouts (). implicitlywait (30,timeunit.seconds);

The third type of webdriverwait ():

It is also a method provided by Webdirver. Within the set time, the default is detected at intervals of time. Whether the page element exists and throws an exception if it is not detected beyond the set time.
The detailed format is as follows:

Webdriverwait (Driver, timeout, poll_frequency=0.5, Ignored_exceptions=none)
    • driver : Webdriver driver (Ie, Firefox, Chrome or remote)
    • Timeout : Maximum time-out, default in seconds
    • poll_frequency : Interval (step) time for sleep time, default is 0.5 seconds
    • ignored_exceptions : Exception information after timeout, Nosuchelementexception exception is thrown by default.

Webdriverwai () is used in conjunction with the until () or Until_not () methods, the following is a description of the until () and the Until_not () methods.

    • until (method, message= "): Call the method provided by the driver as a parameter until the return value is not False.
    • Until_not (method, message= "): Call the method provided by the driver as a parameter until the return value is False.

Python

 from Import  = webdriverwait (Driver, ten). Until (lambda= webdriverwait (Driver, 30, 1, ( elementnotvisibleexception). Until_not (Lambda x:x.find_element_by_id ("Someid"). Is_displayed ())

Java

New Webdriverwait (Driver,= Wait.until (new expectedcondition<webelement> public return d.findelement (By.xpath ("//android.widget.relativelayout[@index = ' 2 ']"    )); }}); E.click (); // the construction method of the Webdriverwait class accepts a Webdriver object and a wait for the maximum time (60 seconds). Then call the until method, which overrides the Apply method in the Expectedcondition interface,
Let it return a webelement, that is, load the completed element, and then click. By default, webdriverwait calls Expectedcondition every 500 milliseconds until a successful return, if the set value is exceeded
No successful return, will throw an exception

Three ways to appium automated test waits

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.