Appium-运行代码

时间:2016-06-02 05:57:12

标签: selenium appium

FAILED CONFIGURATION:@BeforeTest setUp org.openqa.selenium.SessionNotCreatedException:无法创建新会话。 (原始错误:没有应用程序设置;要么使用--app启动appium,要么在所需功能中传入应用程序值,或者设置androidPackage以在设备上启动预先存在的应用程序)(警告:服务器已执行不提供任何堆栈跟踪信息) 命令持续时间或超时:98毫秒 构建信息:版本:' 2.48.2',修订版:' 41bccdd',时间:' 2015-10-09 19:55:52' 系统信息:主持人:' GOD23342',IP:' 10.244.46.14',os.name:' Windows 7',os.arch:' amd64',os.version:' 6.1',java.version:' 1.8.0_92' 驱动程序信息:org.openqa.selenium.remote.RemoteWebDriver     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)     在org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)     在org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)     在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)     在org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247)     在org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:129)     在org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:156)     在Android.firsttest.setUp(firsttest.java:39)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:498)     at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)     在org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)     在org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)     在org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)     在org.testng.TestRunner.beforeRun(TestRunner.java:647)     在org.testng.TestRunner.run(TestRunner.java:615)     在org.testng.SuiteRunner.runTest(SuiteRunner.java:357)     在org.testng.SuiteRunner.run顺序(SuiteRunner.java:352)     在org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)     在org.testng.SuiteRunner.run(SuiteRunner.java:259)     在org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)     在org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)     at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)     在org.testng.TestNG.runSuitesLocally(TestNG.java:1110)     在org.testng.TestNG.run(TestNG.java:1018)     at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)     在org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)     在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

2 个答案:

答案 0 :(得分:0)

package Android;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

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.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class firsttest {
    WebDriver driver;

    @BeforeTest
    public void setUp() throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities().android();

        capabilities.setCapability("no", true);
        capabilities.setCapability("newCommandTimeout", 100000);
        capabilities.setCapability("noReset", true);

        capabilities.setCapability("deviceName", "Medfield9C8687DA");
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "");

        capabilities.setCapability(CapabilityType.VERSION, "4.4.4");
        capabilities.setCapability("deviceName", "Venue7 3740 LTE");
        // capabilities.setCapability("app", application.getAbsolutePath());
        capabilities.setCapability("noRest", true);
        capabilities.setCapability("platformName", "Android");

        capabilities.setCapability("appActivity",
                "com.android.calculator2.Calculator");
        driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),
                capabilities);
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    }

    @Test
    public void Sum() {
        driver.findElements(By.xpath("//android.widget.Button")).get(0).click();

        driver.findElement(By.name("2")).click();

        driver.findElement(By.name("+")).click();
        driver.findElement(By.name("5")).click();
        driver.findElement(By.name("=")).click();
        String result = driver.findElement(
                By.className("android.widget.EditText")).getText();
        System.out.println("Number sum result is : " + result);
    }

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

答案 1 :(得分:0)

别介意我找出解决方案的人...... 添加了包名称并且它有效 capabilities.setCapability(" appPackage"," com.android.calculator2");