在模拟器上运行自动化代码时出错

时间:2017-03-12 11:48:27

标签: java android android-studio-2.1

在模拟器上运行自动化代码时出错

  • 无法通过使用appium和android studio自动化模拟器并获得以下错误。

    [TestNG] Running:
      Command line suite
    
    [VerboseTestNG] RUNNING: Suite: "com.example.tests.FirstTest" containing "0" Tests (config: null)
    [VerboseTestNG] INVOKING: "com.example.tests.FirstTest" - com.example.tests.FirstTest.testFirstCalculator()
    [VerboseTestNG] FAILED: "com.example.tests.FirstTest" - com.example.tests.FirstTest.testFirstCalculator() finished in 71383 ms
    [VerboseTestNG] org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: C:\Windows\system32\cmd.exe /s /c "C:\Users\Teja\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 install "C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk""
    [VerboseTestNG] Failed to install C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]
    [VerboseTestNG] ) (WARNING: The server did not provide any stacktrace information)
    [VerboseTestNG] Command duration or timeout: 0 milliseconds
    [VerboseTestNG] Build info: version: 'unknown', revision: 'b526bd5', time: '2017-03-07 11:11:07 -0800'
    [VerboseTestNG] System info: host: 'USER-PC', ip: '192.168.0.5', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
    [VerboseTestNG] Driver info: driver.version: RemoteWebDriver`enter code here`
    

我使用下面的java代码来自动化应用程序。

我的代码

package com.example.sample;

import java.net.MalformedURLException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class FirstTest {

    WebDriver driver;

    @Before
    public void setUp() throws MalformedURLException {       
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "Nexus 6P API 25");
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
        capabilities.setCapability(CapabilityType.VERSION, "7.1.1");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("appPackage", "com.android.calculator2");
        capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
        driver = new RemoteWebDriver(new URL("http://127.0.0.1:5000/wd/hub"), capabilities);
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    }

    @Test
    public void testFirstCalculator() {
        driver.findElements(By.xpath("//android.widget.Button")).get(0).click();
        driver.findElement(By.name("7")).click();
        driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
    }

    @After
    public void End() {
        driver.quit();
    }
}

0 个答案:

没有答案