我的代码执行一个简单的点击按钮自动化如下,我是appium的新手所以我只是试图获取我的应用程序并单击一个按钮,因为我已经给了我的例外,它阻止我继续< / p>
public class IOSTester {
public static void main(String[] args) throws Exception {
WebDriver driver;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
capabilities.setCapability(CapabilityType.VERSION, "8.1");
capabilities.setCapability("deviceName","iPadAir Simulator");
capabilities.setCapability("app", "/Users/AZ-Admin/Documents/test.app");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
if(driver!=null)
{
driver.quit();
}
driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[1]")).click();
}
}
当编译器到达“driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
”时,我得到以下异常,任何人都可以帮助我
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: 1.19 seconds
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'CodeWarrior.local', ip: '192.168.0.114', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.1', java.version: '1.7.0_71'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
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: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 CalculatorTest.IOSTester.main(IOSTester.java:28)
谢谢
答案 0 :(得分:0)
将代码更改为
public class IOSTester {
public static void main(String[] args) throws Exception {
AppiumDriver driver;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
capabilities.setCapability(CapabilityType.VERSION, "8.1");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("deviceName","iPad Air");
capabilities.setCapability("app", "/Users/AZ-Admin/Documents/test.app");
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[1]")).click();
}
}
下载Appium Driver.jar并将其附加到您的代码文件并导入AppiumDriver