当前位置: 首页 > 知识库问答 >
问题:

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

强化
2023-03-14

首先,出于某种原因,目前只有Android平板电脑才会出现这种情况。我在Android6.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次

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

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"}

它是已知的虫子还是什么?附近有工作吗?

共有1个答案

高茂
2023-03-14

您可以使用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中定义了这个,并在整个测试框架中经常使用if。

用于其他测试类-

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']"));
    }
}
 类似资料: