2015-01-08 45 views
0

我的代碼執行一個簡單的點擊按鈕自動化如下,我對appium很新,所以我只是試圖讓我的應用程序,然後單擊一個按鈕,因爲我已經給我的例外它阻止我繼續Eclipse中的SessionNotCreatedException「Appium」代碼

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

「原來的錯誤:請求一個新的會話,但一個是在進步」 所以已經爲該設備創建的會話並未結束。 – Shamik

+0

所以我需要關閉我的xcode模擬器?然後嘗試 – user3724559

+1

是的,你應該先嚐試一下。重新啓動您的appium服務器和模擬器並運行代碼。 – Shamik

回答

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