2015-05-12 3 views
1

Я успешно сконфигурировал сетку селена с appium. Я успешно создал драйвер для двух разных устройств Android. Скажем, d1 и d2. теперь я хочу поддерживать раковину между ними, потому что мой драйвер выполняет некоторую операцию с использованием d1, а затем после завершения этой другой операции с драйвером d2. Когда я выполняю операцию на d2, другой драйвер d1 должен быть идеальным Но когда я делаю операцию над вторым драйвером, то на первом устройстве приложение находится в фоновом режиме после переключения на первое устройство , это дает мне ошибку, что сеанс не является valid.please помогите мне здесь, что мне делать? следует ли реализовать многопоточность? или есть ли способ поставить первый драйвер на идеальное состояние, а второй выполняет эту операцию?Параллельное тестирование на android

import io.appium.java_client.AppiumDriver; 
import io.appium.java_client.android.AndroidDriver; 

import java.net.MalformedURLException; 
import java.net.URL; 
import java.util.concurrent.TimeUnit; 

import org.apache.commons.lang3.ObjectUtils.Null; 
import org.openqa.selenium.By; 
import org.openqa.selenium.remote.DesiredCapabilities; 
import org.testng.annotations.AfterClass; 
import org.testng.annotations.AfterTest; 
import org.testng.annotations.Test; 

public class selenium_grid_example 
{ 

    AppiumDriver d1,d2; 
    String id = null; 
    DesiredCapabilities capabilities2= new DesiredCapabilities(); 

    @Test(priority=1) 
    public void two_driver() throws InterruptedException{ 
     DesiredCapabilities capabilities1= new DesiredCapabilities(); 
     capabilities1.setCapability("deviceName","xxxx"); 
     capabilities1.setCapability("platformVersion", "5.1"); 
     capabilities1.setCapability("appPackage", "xxxx);   
     capabilities1.setCapability("appActivity", "xxxx"); 
     capabilities1.setCapability("udid", "xxxx"); 
     capabilities1.setCapability("commandTimeout", 10000); 
     try { 
      d1 = new AndroidDriver(new URL("http://127.0.0.1:4728/wd/hub"),  capabilities1); 
     } catch (MalformedURLException e) { 
      System.out.println("Not able to start application"); 
      e.printStackTrace(); 
    } 
    d1.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS); 




capabilities2.setCapability("deviceName","xxxx"); 
    capabilities2.setCapability("platformVersion", "xxx"); 
    //capabilities.setCapability("app",app.getAbsolutepath()); 
    capabilities2.setCapability("appPackage", "xxxx");   
    capabilities2.setCapability("appActivity", "xxxx"); 
    capabilities2.setCapability("udid", "xxxx"); 
    capabilities2.setCapability("commandTimeout", 1000); 
    d2.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS); 

} 


@Test(priority=2) 
public void login_to_application() throws MalformedURLException, InterruptedException{ 
    here i am doing some operation on driver d1   
    d1.manage().wait(20000); 

} 

@Test(priority=3) 
    public void join_meeting(){ 
     try { 
      d2= new AndroidDriver(new URL("http://127.0.0.1:4730/wd/hub"),  capabilities2); 
      } catch (MalformedURLException e) { 
       // TODO Auto-generated catch block 
      here i am doing another operation on driver d2 
      when i am doing some operation here previously opened app get in background on device one 

     } 
    } 
    @AfterClass 
    public void quit_driver(){ 
     try { 
      Thread.sleep(40000); 
     } catch (InterruptedException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     System.out.println("Quiting driver"); 
     d1.quit(); 
    d2.quit(); 
    System.out.println("Driver quited successfully"); 
    } 

}} 

здесь я получил эту ошибку

org.openqa.selenium.remote.SessionNotFoundException: 
Command duration or timeout: 9 milliseconds 
Build info: version: 2.45.0, revision: 32a636c, time: 2015-03-05 22:01:35 
System info: host: gs-1783, ip: 10.22.99.156, os.name: Windows 8, os.arch: amd64, os.version: 6.2, java.version: 1.8.0_45 
Driver info: io.appium.java_client.android.AndroidDriver 
Capabilities [{appPackage=com.fuze.fuzemeeting, networkConnectionEnabled=true, warnings={}, commandTimeout=10000, databaseEnabled=false, deviceName=Nexus, platform=LINUX, appActivity=com.fuze.fuzemeeting.ui.FuzeMainActivity, desired={appPackage=com.fuze.fuzemeeting, appActivity=com.fuze.fuzemeeting.ui.FuzeMainActivity, platformVersion=5.1, commandTimeout=10000, udid=0aee8e8b02e4223e, platformName=Android, deviceName=Nexus}, platformVersion=5.1, webStorageEnabled=false, locationContextEnabled=false, browserName=Android, takesScreenshot=true, javascriptEnabled=true, udid=0aee8e8b02e4223e, platformName=Android}] 
Session ID: 46ce15cd-1e05-4d6a-a460-360dd64c0782 
    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:162) 
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599) 
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180) 
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:185) 
    at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:468) 
    at selenium_grid_example.quit_driver(selenium_grid_example.java:136) 
    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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) 
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564) 
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213) 
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138) 
    at org.testng.internal.TestMethodWorker.invokeAfterClassMethods(TestMethodWorker.java:225) 
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:114) 
    at org.testng.TestRunner.privateRun(TestRunner.java:767) 
    at org.testng.TestRunner.run(TestRunner.java:617) 
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334) 
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329) 
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291) 
    at org.testng.SuiteRunner.run(SuiteRunner.java:240) 
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) 
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224) 
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149) 
    at org.testng.TestNG.run(TestNG.java:1057) 
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111) 
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204) 
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175) 

ответ

1

Я считаю, что это проблема вызвана из обоего сессий, пытающихся использовать тот же порт, хром-драйвер.

При запуске использование Узла Селен сетки:

appium --nodeconfig /Path/to/Config.json -p XXXX -bp YYYY --chromedriver-port ZZZZ;

Обязательно укажите три отдельные порты для каждого узла.

Надеется, что это помогает,

Лиам

Смежные вопросы