简体   繁体   English

使用appium自动化移动应用程序

[英]Automation mobile application using appium

I am trying to automate an android application using Appium and Cucumber with Java.I have written the code for a functionality and it is working fine. 我正在尝试使用AppiumCucumber来自动化android应用程序。我已经编写了功能代码,并且运行良好。 But some times while running the script, it throws an error 但是有时在运行脚本时会引发错误

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)

Source code: 源代码:

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();
    }

}

This error gets cleared and the script works fine when I close the emulator and open it again. 当我关闭模拟器并再次打开它时,此错误将被清除并且脚本可以正常工作。 Can anybody help me in this? 有人可以帮我吗?

Hey please then kill all simulator programmatically after executing testcase. 嘿,请在执行测试用例后以编程方式杀死所有模拟器。 Below code might help you. 下面的代码可能会帮助您。

/**
 * 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();
    }
}

If you are openning a specific simulator you can specify this in above code. 如果要打开特定的模拟器,则可以在上面的代码中指定。

For android simulator please use 对于android模拟器,请使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM