问题
I'm trying to run parallel test on 2 devices using appium & selenium grid but for some reason it runs only on the first node server (and first device) but nothing happen on the second server.
Also if I'm shutting down the first server and run the test then the test run on the second server so there shouldn't be any issue with the servers.
Is there some parameter that I have to give in order to set it to parallel ?
Thanks for the help !
Here are my files :
First server json file :
{
"capabilities":
[
{
"browserName": "SamsungS6",
"deviceName": "04157df40862d02f",
"version":"6.0.1",
"maxInstances": 3,
"platform":"ANDROID"
}
],
"configuration":
{
"cleanUpCycle":2000,
"timeout":30000,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"url":"http://localhost:4491/wd/hub",
"host": "localhost",
"port": 4491,
"maxSession": 5,
"register": true,
"registerCycle": 5000,
"hubPort": 4433,
"hubHost": "localhost"
}
}
Second server json file :
{
"capabilities":
[
{
"browserName": "OnePlusOne",
"deviceName": "14b2b276",
"version":"6.0.1",
"maxInstances": 3,
"platform":"ANDROID",
"platformName":"ANDROID"
}
],
"configuration":
{
"cleanUpCycle":2000,
"timeout":30000,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"url":"http://localhost:4490/wd/hub",
"host": "localhost",
"port": 4490,
"maxSession": 5,
"register": true,
"registerCycle": 5000,
"hubPort": 4433,
"hubHost": "localhost"
}
}
Run the selenium grid :
java -jar selenium-server.jar -role hub -port 4433
Run first scenario
node.exe node_modules\appium\bin\appium.js --nodeconfig myfirstscenario.json -p 4490 -U 14b2b276 -bp 5490 --chromedriver-port 6490
Run second scenario
node.exe node_modules\appium\bin\appium.js --nodeconfig mysecondscenario.json -p 4491 -U 04157df40862d02f -bp 5491 --chromedriver-port 6491
The test
@BeforeTest(alwaysRun = true)
public void setUp(){
try {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "ANDROID");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "");
capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, appPackage);
capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, appActivity);
driver = new AndroidDriver(new URL("http://localhost:4433/wd/hub"), capabilities);
new WebDriverWait(driver, 60);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
@Test
public void test(){
System.out.println("hello world");
try {
sleep(6000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@AfterTest(alwaysRun = true)
public void closeDriver(){
driver.quit();
}
回答1:
The problem is because neither have you provided anything that is unique in your DesiredCapabilities nor have you added a custom CapabilityMatcher. By default the Grid uses only the browserName, version and platform to decide which node a test is to be routed to.
Here's one way of fixing the problem. Add a new key named "applicationName" to your nodeConfig.json and set the values of "OnePlusOne" and "SamsungS6" respectively. You then add a new capability named "applicationName" to your desired capability in your test and then set the value of "OnePlusOne" and "SamsungS6" respectively. After this your test would be routed to the correct device.
You can read more about this in my blog post here.
回答2:
i also faced the same issue but got resolved by
Step1: add the appium (.. \Appium\node_modules.bin) in you environment variable Step2: make the differen json for the each node.
for node 1
{ "capabilities":
[
{
"version":"6.0",
"maxInstances": 1,
"platform":"ANDROID",
"newCommandTimeout":"30",
"deviceReadyTimeout":5
}
], "configuration": {
"cleanUpCycle":2000,
"timeout":10800,
"url":"http://127.0.0.1:4723/wd/hub",
"host": "127.0.0.1",
"port": 4723,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 1,
"register": true,
"registerCycle": 5000,
"hubPort": 4444,
"hubHost": "127.0.0.1" } }
for node 2
{
"capabilities":
[
{
"version":"5.0.2",
"maxInstances": 1,
"platform":"ANDROID",
"newCommandTimeout":"30",
"deviceReadyTimeout":5
}
],
"configuration":
{
"cleanUpCycle":2000,
"timeout":10800,
"url":"http://127.0.0.1:4733/wd/hub",
"host": "127.0.0.1",
"port": 4733,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 1,
"register": true,
"registerCycle": 5000,
"hubPort": 4444,
"hubHost": "127.0.0.1"
}
}
now for to run the hub i have made that in a batch file
java -jar %cd%\selenium-server-standalone-2.52.0.jar -role hub http://127.0.0.1:4444/grid/console
and
for node1
appium -a 127.0.0.1 -p 4723 --no-reset --bootstrap-port 4728 -U 192.168.56.101:5555 --nodeconfig %cd%\5555appium1.json
and node 2
appium -a 127.0.0.1 -p 4733 --no-reset --bootstrap-port 4738 -U 4d00af03525c80a1 --nodeconfig %cd%\4d00appium2.json
and in you code add the deviceName:'your device name which comes on adb devices in cmd'
This really worked for me.
来源:https://stackoverflow.com/questions/37485100/parallel-test-with-appium-selenium-grid