【问题标题】:Automation mobile application using appium使用 appium 的自动化移动应用程序
【发布时间】:2017-12-07 14:51:05
【问题描述】:

我正在尝试使用带有 Java 的 Appium 和 Cucumber 自动化一个 android 应用程序。我已经编写了一个功能的代码,它工作正常。但有时在运行脚本时会抛出错误

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original err
or: Could not proxy command to remote server. Original error: Error: read ECONNRESET (WARNING: The server did not provid
e any stacktrace information)

源代码:

import com.google.common.base.Function;
import com.intel.truevr.appautomation.core.Capabilities;
import org.openqa.selenium.By;
import io.appium.java_client.MobileDriver;
import io.appium.java_client.MobileElement;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.openqa.selenium.support.ui.Wait;
import java.util.List;
import io.appium.java_client.TouchAction;

public class C754L2D {
    Capabilities c = new Capabilities();
    MobileDriver driver =  c.getDefaultCapabilities();
    Wait wait = new Wait() {
        @Override
        public Object until(Function isTrue) {
            return null;
        }
    };

    @Given("^User taps the toggle button in the live 2D video playing screen$")
    public void user_taps_toggle_button() throws Exception {

        MobileElement allow = (MobileElement) driver.findElement(By.id("com.android.packageinstaller:id/permission_allow_button"));
        allow.click();
        List<MobileElement> list = driver.findElements(By.id("android:id/text1"));
        for(MobileElement ele :list) {
            String text = ele.getText();
            if(text.equals("Live")){
                ele.click();
                break;
            }
        }
        MobileElement panoramicButton = (MobileElement) driver.findElement(By.id("com.jackalopelite.simplecontainer:id/rl_select_2d"));
        panoramicButton.click();
        MobileElement Screen= (MobileElement) driver.findElement(By.className("android.view.View"));
        TouchAction ta = new TouchAction(driver);
        ta.tap(Screen, 531, 357).perform();
        MobileElement toggleButton = (MobileElement) driver.findElement(By.id("com.jackalopelite.simplecontainer:id/fab_player_switch_mode"));
        toggleButton.click();
    }
    @When("^Taps back button in the transition screen$")
    public void taps_back_button() throws InterruptedException {

        Thread.sleep(1000);
        MobileElement backButton = (MobileElement) driver.findElement(By.id("com.jackalopelite.simplecontainer:id/iv_cardboard_back"));
        backButton.click();

    }
    @Then("^The transition screen should dismiss and user should be navigated back to 2d live video playing screen$")
    public void dismiss_transition_screen() {

        try{
            MobileElement cameraAngleSelectionButton = (MobileElement) driver.findElement(By.id("com.jackalopelite.simplecontainer:id/rl_player_switch_camera_parent"));
            if(cameraAngleSelectionButton != null) {
                System.out.println("The transition screen is dismissed and user is navigated back to 2d live video playing screen");
            }
        }catch(Exception e){
            System.out.println("The transition screen is not dismissed and user is not navigated back to 2d live video playing screen");
        }
        //driver.quit();
    }

}

当我关闭模拟器并再次打开它时,此错误被清除并且脚本工作正常。有人可以帮我吗?

【问题讨论】:

  • 阅读此github thread,与同一问题有关。
  • 该线程中没有解决方案

标签: java android appium


【解决方案1】:

嘿,请在执行测试用例后以编程方式杀死所有模拟器。下面的代码可能会对您有所帮助。

/**
 * Stop Simulator
 */
public void stopSimulator() {
    try {
        Runtime.getRuntime().exec("killall \"iOS Simulator\"");
    } catch (IOException e) {
        //e.printStackTrace();
    }
    try {
        Runtime.getRuntime().exec("killall Simulator");
    } catch (IOException e) {
        //e.printStackTrace();
    }
}

如果您要打开特定的模拟器,您可以在上面的代码中指定。

安卓模拟器请使用

Runtime.getRuntime().exec("adb emu kill");

【讨论】:

  • 我正在使用安卓模拟器。相同的鳕鱼对它有用吗?
  • 请使用上面的,让我知道您的反馈
猜你喜欢
  • 1970-01-01
  • 2021-10-11
  • 2019-05-01
  • 2019-12-07
  • 2016-01-02
  • 2018-05-31
  • 2014-09-25
  • 1970-01-01
  • 2020-10-05
相关资源
最近更新 更多