【问题标题】:Appium 1.4.16 An unknown server-side error occurred while processing the commandAppium 1.4.16 处理命令时出现未知的服务器端错误
【发布时间】:2017-03-11 08:09:31
【问题描述】:

首先,出于某种原因,这种情况目前仅发生在 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"}

是已知的错误还是什么? 有解决办法吗?

【问题讨论】:

    标签: java android appium


    【解决方案1】:

    您可以使用 PresenceOfElement 代替使用 visibilityOfElementLocated

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.widget.ViewSwitcher/android.widget.FrameLayout/android.view.View"))); 
    

    我更喜欢使用带有一些条件的相对 XPath,例如添加一些属性值(名称、内容描述、文本)。在下面的示例中,我使用属性文本作为“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']"));
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-02-04
      • 2019-03-25
      • 2018-07-26
      • 1970-01-01
      • 2019-12-16
      • 2016-10-14
      • 2017-05-07
      • 2017-01-22
      • 2017-10-21
      相关资源
      最近更新 更多