How to “wait to activity” using Appium, on begin and during test itself?

前端 未结 7 1526
挽巷
挽巷 2020-12-31 04:06

I\'m starting an already installed app using appium.

After my driver is initialized. How do I make it poll-wait till certain activity is displayed?

I saw onl

相关标签:
7条回答
  • 2020-12-31 04:45

    Specific activity means some specific element is being displayed. I use the following code to wait until some certain element on the screen:

    WebDriverWait wait = new WebDriverWait(driver, 30);
    wait.until(ExpectedConditions.elementToBeClickable(By
            .xpath("//android.widget.Button[contains(@text, 'Log In')]")));
    

    or:

    WebDriverWait wait = new WebDriverWait(driver, 30);
    wait.until(ExpectedConditions.presenceOfElementLocated(By
                .xpath("//android.widget.TextView[contains(@resource-id, 'action_bar_title')]")));
    
    0 讨论(0)
  • 2020-12-31 04:48

    It can be done by different ways using element. Webdriver provide “WebDriverWait”, “ExpectedCondition” classes to implement this. ExpectedConditions class provide some set of predefine conditions to wait elements as:

    1. elementSelectionStateToBe: an element state is selection.
    2. elementToBeClickable: an element is present and clickable.
    3. elementToBeSelected: element is selected
    4. frameToBeAvailableAndSwitchToIt: frame is available and frame
    5. selected. invisibilityOfElementLocated: an element is invisible
    6. presenceOfAllElementsLocatedBy: present element located by.
    7. refreshed: wait for a particular condition when page refresh.
    8. textToBePresentInElement: text present on particular an element
    9. textToBePresentInElementValue: and element value present for a
      particular element. and many more You can learn more ways to implement implicit and explicit wait by going through this url: http://roadtoautomation.blogspot.in/2013/10/webdriver-implicit-and-explicit-wait.html

    Hope it helps...

    0 讨论(0)
  • 2020-12-31 04:54

    I would suggest you to use WebDriverWait. Thread.sleep() is not a good way to use in your test scripts

    0 讨论(0)
  • 2020-12-31 04:58
    long startTime = System.currentTimeMillis();
    while(System.currentTimeMillis() - startTime < Time_Out)
        if (getDriver().currentActivity().equals(activity))
            break;
    
    0 讨论(0)
  • 2020-12-31 05:03

    You can use the following code to poll the current activity every second. If you want to reduce polling time you can reduce sleep time to 500 and wait*2 :

    public void waitForActivity(String desiredActivity, int wait) throws InterruptedException
    {
        int counter = 0;
        do {
            Thread.sleep(1000);
            counter++;
        } while(driver.currentActivity().contains(desiredActivity) && (counter<=wait));
    
        log("Activity appeared :" + driver.currentActivity(), true);
    }
    
    0 讨论(0)
  • 2020-12-31 05:05
    WebDriverWait wait = new WebDriverWait(driver,20);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("about_me"))); 
    

    If you wish to know in detail how implicit and explicit wait can be used in Appium then visit this TUTORIAL

    0 讨论(0)
提交回复
热议问题