简体   繁体   English

使用Appium的iOS自动化

[英]iOS automation with Appium

I am writing my 1st automation code for iOS device and i am seeing the following error message that I do not know how to debug.. 我正在编写iOS设备的第一自动化代码,并且看到以下错误消息,但我不知道如何调试。

* Error Message * * 错误信息 *

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Requested a new session but one was in progress) (WARNING: The server did not provide any stacktrace information)

Command duration or timeout: 602.97 seconds

Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'

System info: host: 'Husky-MacBook-Air.local', ip: '10.131.32.153', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.8.0_05'

Driver info: 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:408)

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 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 com.husky.test1.Appium_take1.main(Appium_take1.java:43)

*****  End of Error Message ******

I am using Appium 1.2 and here is my code: 我正在使用Appium 1.2,这是我的代码:

* Code * *代码*

package com.husky.test1;


import java.io.File;

import java.net.URL;

import java.util.List;



import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.remote.CapabilityType;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.openqa.selenium.remote.RemoteWebDriver;

import org.testng.Assert;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;



import java.net.MalformedURLException;






public class Appium_test1 {

    public static void main(String... args){

        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();

        desiredCapabilities.setCapability("device", "iPhone");

        desiredCapabilities.setCapability("version", "7.1");

        desiredCapabilities.setCapability("app", "/Users/cutehusky/Downloads/Payload2/test.app");

        desiredCapabilities.setCapability("platformName", "iOS");

        desiredCapabilities.setCapability("deviceName", "iPhone");       

        URL url = null;

        WebDriver remoteWebDriver = new RemoteWebDriver(url,desiredCapabilities);

        By b = By.xpath("UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[5]/UIAStaticText[1]");

        WebElement we = remoteWebDriver.findElement(b);

        we.click();

    }

}

** End of Automation Code ** **自动化代码结束**

Explain: 说明:

I am trying to launch my test app under "/Users/cutehusky/Downloads/Payload2/test.app", find a button base on its xpath (UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[5]/UIAStaticText[1]) and click on it. 我正在尝试在“ /Users/cutehusky/Downloads/Payload2/test.app”下启动测试应用,并在其xpath(UIAApplication [1] / UIAWindow [1] / UIATableView [1] / UIATableCell [5 ] / UIAStaticText [1]),然后单击它。

Thats all I am looking to accomplish at the moment, please help me :) 那就是我目前想要完成的一切,请帮助我:)

Thanks 谢谢

So the following tells you everything you need to know: 因此,以下内容将告诉您您需要了解的所有信息:

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Requested a new session but one was in progress) (WARNING: The server did not provide any stacktrace information)

When you begin your test, you need to make sure the following things aren't running: 开始测试时,需要确保以下各项没有运行:

  • Simulator 模拟器
  • Instruments 仪器

Appium sometimes gets into a state where it thinks the Simulator is running, but it's not. Appium有时会进入认为模拟器正在运行的状态,但事实并非如此。 This is solved by restarting the server. 这可以通过重新启动服务器来解决。

Instead of remote webdriver use below code 代替远程webdriver使用下面的代码

            protected static AppiumDriver<MobileElement> driver;
            driver = new IOSDriver<MobileElement>(url, dCapabilities);

and try to run if it works 并尝试运行是否可行

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

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