• #71 楼 @chenhengjie123 原来是需要 eclipse clean 就行了,晕死,谢谢你

  • #67 楼 @chenhengjie123

    Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: deviceName) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 388 milliseconds
    Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
    System info: host: 'zoucw-PC', ip: '172.27.35.69', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_75'
    Driver info: io.appium.java_client.android.AndroidDriver
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
        at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
        at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:40)
        at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
        at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
        at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:36)
        at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:114)
        at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:132)
        at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:92)
        at com.glen.demo.ContactsTest.main(ContactsTest.java:44)
    这是java运行报错
    
  • #67 楼 @chenhengjie123 不好意思,发错了,重新发一个

    info: --> POST /wd/hub/session {"desiredCapabilities":{"platformVersiom":"4.4","platformName":"Android","unnicodeKeyboard":"Ture","browserName":"","appActivity":".ui.launcherUI","devicename":"Android Emulator","noSign":"Ture","resetKeyboard":"Ture","appPackage":"com.tencent.mm"}}
    info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)
    info: [debug] Got configuration error, not starting session
    info: [debug] Cleaning up appium session
    error: The following desired capabilities are required, but were not provided: deviceName
    info: [debug] Error: The following desired capabilities are required, but were not provided: deviceName

  • #67 楼 @chenhengjie123 info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)

    error: The following desired capabilities are required, but were not provided: deviceName
    info: [debug] Got configuration error, not starting session
    info: [debug] Cleaning up appium session
    error: Failed to start an Appium session, err was: Error: The following desired capabilities are required, but were not provided: deviceName
    这是 appium 运行的错误

  • #62 楼 @chenhengjie123 或者正常是哪三个包的版本啊,我下载下来试试

  • #62 楼 @chenhengjie123 会不会还是 jar 包问题 2.5.3 是不是太高了

  • #62 楼 @chenhengjie123 现在我只保留三个 jar 包 其他版本删除了,然后又报错了

    Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
    Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
    System info: host: 'zoucw-PC', ip: '172.27.35.69', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_75'
    Driver info: driver.version: AndroidDriver
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665)
        at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:40)
        at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
        at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
        at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:36)
        at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:114)
        at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:132)
        at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:92)
        at com.glen.demo.ContactsTest.main(ContactsTest.java:44)
    Caused by: org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect
    Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
    System info: host: 'zoucw-PC', ip: '172.27.35.69', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_75'
    Driver info: driver.version: AndroidDriver
        at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:84)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
        ... 11 more
    Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect
        at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:140)
        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
        at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:144)
        at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:90)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
        at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:69)
        ... 12 more
    Caused by: java.net.ConnectException: Connection refused: connect
        at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:579)
        at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:72)
        at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)
        ... 25 more
    
    
  • #62 楼 @chenhengjie123 代码不出错,运行报错了,现在我保留的是 java client4.1.2 和 selenium java-2.5.3 和 selenium java-standalone 2.5.3 这三个包

  • #59 楼 @chenhengjie123 是不是 java client 的包不对啊 我试了 4.1.2 的 还有 1.4 1.2 的 都不行

  • #59 楼 @chenhengjie123

    package com.glen.demo;
    
    import org.junit.Test;
    import org.openqa.selenium.*;
    import org.openqa.selenium.interactions.HasTouchScreen;
    import org.openqa.selenium.interactions.TouchScreen;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteTouchScreen;
    import org.openqa.selenium.remote.RemoteWebDriver;
    
    import io.appium.java_client.AppiumDriver;
    import io.appium.java_client.android.AndroidDriver;
    
    import java.io.File;
    import java.net.URL;
    import java.util.List;
    
    public class ContactsTest{
        private static void login(AppiumDriver driver) {
            // TODO Auto-generated method stub
    
        }
    
        public static void main(String[] args) throws Exception {
            AndroidDriver driver;
    
            //File app=new File("C:\\Users\\zoucw\\Desktop\\WeChat_880.apk");
            DesiredCapabilities capabilities=new DesiredCapabilities();
    
            //capabilities.setCapability("app",app.getAbsolutePath());
            capabilities.setCapability(CapabilityType.BROWSER_NAME,"");
            capabilities.setCapability("devicename","Android Emulator");
            capabilities.setCapability("platformVersiom","4.4");
            capabilities.setCapability("platformName","Android");
    
            capabilities.setCapability("appPackage","com.tencent.mm");
            capabilities.setCapability("appActivity",".ui.launcherUI");
    
            capabilities.setCapability("unnicodeKeyboard","Ture");
            capabilities.setCapability("resetKeyboard","Ture");
            capabilities.setCapability("noSign","Ture");
    
            driver=new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
    
            Thread.sleep(5000);
            try{
                login(driver);
                Thread.sleep(5000);
            } catch (Exception e){
                e.printStackTrace();
    
            }finally{
                Thread.sleep(5000);
                driver.quit();
            }
    
        }
    
    
    }
    
  • #55 楼 @chenhengjie123 哥们,Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.remote.HttpCommandExecutor.(Ljava/util/Map;Ljava/net/URL;Lorg/openqa/selenium/remote/http/HttpClient$Factory;) V
    at io.appium.java_client.remote.AppiumCommandExecutor.(AppiumCommandExecutor.java:43)
    at io.appium.java_client.remote.AppiumCommandExecutor.(AppiumCommandExecutor.java:55)
    at io.appium.java_client.AppiumDriver.(AppiumDriver.java:131)
    at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:92)
    at com.glen.demo.ContactsTest.main(ContactsTest.java:44)
    报这个错,是不是 java client 这个 jar 包的版本不对啊,我是 4.1.2 的。

  • #55 楼 @chenhengjie123 多谢你啊,真是少了那个文件夹,可以了

  • #55 楼 @chenhengjie123 谢谢你,我看了视频,明白你的意思了,因为我之前没学过 Android,可是我导入路径之后,appium 没有自动识别 package 和 activity 信息,我百度了,用 aapt 命令,但是我 SDK 下没有这个命令,会不会影响自动识别,另外其他方法说是打开应用,我试了也不行。大神有办法吗?

  • #51 楼 @chenhengjie123 版本:appium1.4.16、完整代码如下:
    package com.glen.demo;

    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import org.openqa.selenium.*;
    import org.openqa.selenium.interactions.HasTouchScreen;
    import org.openqa.selenium.interactions.TouchScreen;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteTouchScreen;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import java.io.File;
    import java.net.URL;
    import java.util.List;

    public class ContactsTest {
    private WebDriver driver;

    @Before
    public void setUp() throws Exception {
    //set up appium
    File classpathRoot = new File(System.getProperty("user.dir"));
    File appDir = new File(classpathRoot, "apps/ContactManager");
    File app = new File(appDir, "ContactManager.apk");

    DesiredCapabilities capabilities = new DesiredCapabilities();

    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion", "19");
    capabilities.setCapability("deviceName", "Android Emulator");

    driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }

    @After
    public void tearDown() throws Exception {
    driver.quit();
    }

    @Test
    public void addContact(){
    WebElement el = driver.findElement(By.name("Add Contact"));
    el.click();
    List textFieldsList = driver.findElements(By.tagName("textfield"));
    textFieldsList.get(0).sendKeys("Some Name");
    textFieldsList.get(2).sendKeys("Some@example.com");
    driver.findElement(By.name("Save")).click();
    }

    public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {
    private RemoteTouchScreen touch;

    public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) {
    super(remoteAddress, desiredCapabilities);
    touch = new RemoteTouchScreen(getExecuteMethod());
    }

    public TouchScreen getTouch() {
    return touch;
    }
    }
    }

    另外:配置安卓模拟器过程中少了一个 GoogleMap APIs(ARM system image)不知道对此有没有影响。

  • 我都装好了,不过运行一个 demo 时报错,appium 报错日志:info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: platformName, deviceName)","origValue":"The following desired capabilities are required, but were not provided: platformName, deviceName"},"sessionId":null},可是我启动 appium 时是:info: [debug] Non-default server args: {"address":"127.0.0.1","logNoColors":true,"avd":"android4.4.2","deviceName":"Android Emulator","platformName":"Android","platformVersion":"19","automationName":"Appium"},代码如下:capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion", "19");
    capabilities.setCapability("deviceName", "Android Emulator");请问为啥还报那个错误呢?

  • 我都装好了,不过运行一个 demo 时报错,appium 报错日志:info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: platformName, deviceName)","origValue":"The following desired capabilities are required, but were not provided: platformName, deviceName"},"sessionId":null},可是我启动 appium 时是:info: [debug] Non-default server args: {"address":"127.0.0.1","logNoColors":true,"avd":"android4.4.2","deviceName":"Android Emulator","platformName":"Android","platformVersion":"19","automationName":"Appium"},代码如下:capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion", "19");
    capabilities.setCapability("deviceName", "Android Emulator");请问为啥还报那个错误呢?

  • 我都装好了,不过运行一个 demo 时报错,appium 报错日志:info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: platformName, deviceName)","origValue":"The following desired capabilities are required, but were not provided: platformName, deviceName"},"sessionId":null},可是我启动 appium 时是:info: [debug] Non-default server args: {"address":"127.0.0.1","logNoColors":true,"avd":"android4.4.2","deviceName":"Android Emulator","platformName":"Android","platformVersion":"19","automationName":"Appium"},代码如下:capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion", "19");
    capabilities.setCapability("deviceName", "Android Emulator");请问为啥还报那个错误呢?

  • 已改