Appium 1.4.16处理命令时发生未知的服务器端错误

时间:2016-08-17 13:26:01

标签: java android appium

首先,由于某种原因,目前仅在Android平板电脑上发生这种情况。 我在Android 6.0到4.4的手机上试过它并且它正在工作。

但由于某些原因,平板电脑没有。

我正试图在屏幕上找到一个广告,我正在搜索它:

private boolean findAdContainerDefault (){
    boolean found = false;
    try {
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//android.widget.ViewSwitcher/android.widget.FrameLayout/android.webkit.WebView")));
        found = true;
    } catch (Exception e) {}
    return found;
}

或者这个:

private boolean findAdContainerFor44 (){
    boolean found = false;
    try {
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//android.widget.ViewSwitcher/android.widget.FrameLayout/android.view.View")));
        found = true;
    } catch (Exception e) {}
    return found;
}

因为有时webview不会在检查器中显示某些设备。

这项工作就像手机上的魅力一样,但出于某种原因,它在平板电脑上有时会工作,如果我在我的测试中使用这种方法8次,它可能会工作6次&即使我试图抓住它,7日也会崩溃。

显然这是服务器端错误: 这是我得到的错误:

org.openqa.selenium.support.ui.ExpectedConditions findElement
WARNING: WebDriverException thrown by findElement(By.xpath: //android.widget.ViewSwitcher/android.widget.FrameLayout/android.webkit.WebView)
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 101 milliseconds

这就是我在服务器端得到的:

> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//android.widget.ViewSwitcher/android.widget.FrameLayout/android.webkit.WebView","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.widget.ViewSwitcher/android.widget.FrameLayout/android.webkit.WebView","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding //android.widget.ViewSwitcher/android.widget.FrameLayout/android.webkit.WebView using XPATH with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Command returned error:java.lang.RuntimeException: Failed to Dump Window Hierarchy
> info: [debug] Condition unmet after 64ms. Timing out.
> info: [debug] Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command.","origValue":"Failed to Dump Window Hierarchy"},"sessionId":"0552388e-e8d3-4be6-ba40-1e8225064654"}
> info: <-- POST /wd/hub/session/0552388e-e8d3-4be6-ba40-1e8225064654/element 500 66.384 ms - 200 
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":13,"value":"Failed to Dump Window Hierarchy"}

它是已知的bug还是什么? 有工作吗?

1 个答案:

答案 0 :(得分:0)

您可以使用PresenceOfElement

,而不是使用visibilityOfElementLocated
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.widget.ViewSwitcher/android.widget.FrameLayout/android.view.View"))); 

我更喜欢使用相对XPath和一些标准,例如添加一些属性值(name,content-desc,text)。在下面的示例中,我使用属性文本作为“MyWebView”。将此值替换为您的属性。

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.view.View[@text='MyWebView']"))); 

您还可以使用以下方法查找屏幕上是否存在元素。

protected boolean isElementPresent(By by) throws IOException {
    boolean isElement = false;
    try
    {
        if (driver.findElement(by) != null)
        {
            isElement = true;
            return isElement;
        }
    }
    catch(Exception e)
    {
        System.out.println("Element not found");
        isElement = false;
        return isElement;
    }
    return isElement;
}

我在AbstractClass中定义了它,并且在整个测试框架中经常使用。

在其他测试类中使用 -

public class testAdBanner extends AbstractMethods {

    public AppiumDriver<?> driver;

    public testAdBanner(AppiumDriver<?> driver2) {
        super(driver2);
        this.driver = driver2;
    }

    public boolean isAdBanner() throws IOException {
        return isElementPresent(By.xpath("//android.view.View[@text='MyWebView']"));
    }
}