277169949 发表于 2016-1-24 14:13:55

appium——java 运行的时候报错怎么处理

org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: com.hw.smart.isdacceptance/.provider.activites.WelcomeActivity never started. Current: com.hw.smart.isdacceptance/.provider.activites.LoginActivity) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 33.21 seconds
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:03:00'
System info: host: '4PLMB6BMCZOZDWH', ip: '192.168.1.7', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_13'
Driver info: io.appium.java_client.AppiumDriver
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
        at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
        at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:81)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:126)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:153)
        at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:43)
        at AppDemo.setUp(AppDemo.java:33)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)


代码如下:

import io.appium.java_client.AppiumDriver;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.io.File;
import java.net.URL;
import java.util.concurrent.TimeUnit;

public class AppDemo {
        private AppiumDriver driver;

        @Before
        public void setUp() throws Exception {
                // set up appium
                File classpathRoot = new File(System.getProperty("user.dir"));
                File appDir = new File(classpathRoot, "apps");
                File app = new File(appDir, "ISDAcceptance.apk");
                DesiredCapabilities capabilities = new DesiredCapabilities();
                capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
                capabilities.setCapability("platformName", "Android");
                capabilities.setCapability("deviceName", "582af7877b5a");//
                capabilities.setCapability("platformVersion", "4.4.4");
                capabilities.setCapability("app", app.getAbsolutePath());

                capabilities.setCapability("appPackage", "com.hw.smart.isdacceptance");
                capabilities.setCapability("appActivity",
                                "com.hw.smart.isdacceptance.provider.activites.WelcomeActivity");
                driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),
                                capabilities);

        }

        @After
        public void tearDown() throws Exception {
                if (driver != null) {
                        driver.quit();
                }
        }

        @Test
        public void login() {
               
                // WebElement el = driver.findElement(By.name("Add Contact"));
                // el.click();
                // List<WebElement> textFieldsList = driver
                // .findElementsByClassName("android.widget.EditText");
                // textFieldsList.get(0).sendKeys("Some Name");
                // textFieldsList.get(2).sendKeys("Some@example.com");
                // driver.swipe(100, 500, 100, 100, 2);
                // driver.findElementByName("Save").click();
        }
}


seagull1985 发表于 2016-1-25 08:30:12

看下你的APPIUM客户端正常启动了没有,查下本机端口4723有没有被占用,再查下这个端口是不是被APPIUM客户端启用的。。。

lin0731032 发表于 2016-1-25 09:08:00

检查Appium里面输出的错误信息,看看是否与APP的activity有关

小妮爱军 发表于 2016-1-25 16:07:13

我也碰到这个问题了,请问你解决了吗:)

唯一88 发表于 2016-2-3 13:43:16

我之前遇到了这个问题,是activity写错了,你看看你的,问一下开发activity是什么,修改了应该就能执行通过了!
页: [1]
查看完整版本: appium——java 运行的时候报错怎么处理