java.net.BindException: Address already in use

478 views
Skip to first unread message

akamel...@gmail.com

unread,
May 6, 2019, 8:58:23 AM5/6/19
to Selenium Users
im trying to run selenium grid within my code and im getting this error, could work properly when i run selenium grid from terminal 
i have tried many ways since days ago and this my code 

Enter code here...package Configuration;


import android.graphics.drawable.Animatable;

import org.openqa.grid.internal.utils.GridHubConfiguration;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.server.SeleniumServer;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import io.appium.java_client.service.local.flags.ServerArgument;


public class BaseSetup {

protected static AndroidDriver<MobileElement> driver = null;
protected AppiumDriverLocalService service;
public WebDriverWait wait;
private ThreadLocalDriver threadLocalDriver = new ThreadLocalDriver();
private SeleniumServer hub;


@Parameters({"deviceName","platformVersion","udid","URL_","Sport","deviceId","sysPort","bootStrap","wdaPort","path"})
@BeforeMethod(alwaysRun = true)
public void setUp (String deviceName, String platformVersion, String udid, String URL_, String Sport, String deviceId, String sysPort, String bootStrap, String wdaPort, String path) throws Exception {
GridHubConfiguration config = new GridHubConfiguration();
config.loadFromJSON("/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/selenium/config.json");
Hub hub = new Hub(config);
hub.start();

Thread.sleep(10000);


System.out.println("Driver Is Initiated");
DesiredCapabilities dc = new DesiredCapabilities();

// Mobile setup
dc.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, platformVersion);
dc.setCapability(AndroidMobileCapabilityType.SYSTEM_PORT, sysPort);
// dc.setCapability("appium:unlockType", "password");
// dc.setCapability("appium:unlockKey", "@0122882435abA");
// dc.setCapability(MobileCapabilityType.UDID,udid_);
// dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2"); // Make the test fail after first tear down "BROWSER_TIMEOUT"
// dc.setCapability("appium:uiautomator2ServerInstallTimeout", "8000");


// Application setup
dc.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.sarajevo.food.dictionary");
dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.sfdmobile.MainActivity");
dc.setCapability(AndroidMobileCapabilityType.APP_WAIT_ACTIVITY, "com.sfdmobile.MainActivity");

dc.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS,"true");
dc.setCapability(MobileCapabilityType.CLEAR_SYSTEM_FILES, true);


// Driver configuration
// int port = Integer.parseInt(Sport); //need when use function .using
service = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new File("/usr/local/bin/node"))
.withAppiumJS(new File("/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js"))
.withArgument(Arg.ADDRESS,URL_)
.withArgument(Arg.PORT,Sport)
.withArgument(Arg.CALLBACKPORT,Sport)
.withArgument(Arg.WDALOCALPORT,wdaPort)
.withArgument(Arg.BootstrapPort,bootStrap)
.withArgument(Arg.NODECONFIG,path)
.withArgument(Arg.SESSIONOVERRIDE));
service.start();
// Thread.sleep(7000); // Needed for appium server to wait for selenium grid to register the node
driver = new AndroidDriver (new URL("http://localhost:4444/wd/hub"), dc);
//Thread.sleep(5000);
// threadLocalDriver.setTLDriver(new AndroidDriver<MobileElement>(new URL("http://"+URL_+":"+Sport+"/wd/hub"),dc));
// threadLocalDriver.setTLDriver(new AndroidDriver<MobileElement>(new URL("http://localhost:4444/wd/hub"),dc));
// driver = threadLocalDriver.getTLDriver();
// wait = new WebDriverWait(driver, 10);
}

@AfterMethod
public void tearDown(){
if (driver != null)
driver.quit();
System.out.println("Driver quit");

}

// @AfterMethod
// public synchronized void teardown() {
// if (driver != null)
// driver.quit();
// }
}





console error 
Enter code here.....
... TestNG 6.14.3 by Cédric Beust (ced...@beust.com)
...
Driver Is Initiated
[Appium] Welcome to Appium v1.12.1
[Appium] Non-default server args:
[Appium]   address: 127.0.0.1
[Appium]   port: 5001
[Appium]   callbackPort: 5001
[Appium]   bootstrapPort: 4725
[Appium]   sessionOverride: true
[Appium]   nodeconfig: /Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/selenium/note8.json
[Appium]   wdaLocalPort: 8230
[debug] [Appium] Starting auto register thread for grid. Will try to register every 5000 ms.
[Appium] Appium REST http interface listener started on 127.0.0.1:5001
[HTTP] --> GET /wd/hub/status
[HTTP] {}
[debug] [GENERIC] Calling AppiumDriver.getStatus() with args: []
[debug] [GENERIC] Responding to client with driver.getStatus() result: {"build":{"version":"1.12.1"}}
[HTTP] <-- GET /wd/hub/status 200 7 ms - 68
[HTTP] 
May 06, 2019 2:37:25 PM org.openqa.grid.web.servlet.handler.RequestHandler process
INFO: Got a request to create a new session: Capabilities {appActivity: com.sfdmobile.MainActivity, appPackage: com.sarajevo.food.dictionary, appWaitActivity: com.sfdmobile.MainActivity, autoGrantPermissions: true, clearSystemFiles: true, deviceName: SM_N950F, platformName: Android, platformVersion: 9, systemPort: 8230}

org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: Error forwarding the new session Empty pool of VM for setup Capabilities {appActivity: com.sfivity, appPackage: com.saraionary, appWaitActivity: com.sfdvity, autoGrantPermissions: true, clearSystemFiles: true, deviceName: SM_N950F, platformName: Android, platformVersion: 9, systemPort: 8230}
Command duration or timeout: 337 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'WS-MIRELSP-OSX.local', ip: '192.168.30.171', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.4', java.version: '1.8.0_152-release'
Driver info: driver.version: AndroidDriver
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'WS-MIRELSP-OSX.local', ip: '192.168.30.171', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.4', java.version: '1.8.0_152-release'
Driver info: driver.version: AndroidDriver

at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:208)
at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:217)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:84)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:94)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:95)
at Configuration.BaseSetup.setUp(BaseSetup.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:458)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.access$000(SuiteRunner.java:40)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:489)
at org.testng.internal.thread.ThreadUtil$1.call(ThreadUtil.java:52)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:186)
... 36 more
Caused by: org.openqa.selenium.WebDriverException: Error forwarding the new session Empty pool of VM for setup Capabilities {appActivity: com.snActivity, appPackage: com.sactionary, appWaitActivity: com.sfctivity, autoGrantPermissions: true, clearSystemFiles: true, deviceName: SM_N950F, platformName: Android, platformVersion: 9, systemPort: 8230}
Command duration or timeout: 337 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'WS-MIRELSP-OSX.local', ip: '192.168.30.171', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.4', java.version: '1.8.0_152-release'
Driver info: driver.version: AndroidDriver
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:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$errorHandler$0(JsonWireProtocolResponse.java:54)
at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
... 41 more
Caused by: org.openqa.grid.common.exception.GridException: Error forwarding the new session Empty pool of VM for setup Capabilities {appActivity: com.sfdvity, appPackage: com.sartionary, appWaitActivity: com.sfivity, autoGrantPermissions: true, clearSystemFiles: true, deviceName: SM_N950F, platformName: Android, platformVersion: 9, systemPort: 8230}
at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:115)
at org.openqa.grid.web.servlet.DriverServlet.process(DriverServlet.java:83)
at org.openqa.grid.web.servlet.DriverServlet.doPost(DriverServlet.java:67)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:808)
at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:587)
at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle(SessionHandler.java:221)
at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.seleniumhq.jetty9.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.seleniumhq.jetty9.server.Server.handle(Server.java:499)
at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:310)
at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.seleniumhq.jetty9.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
... 1 more


java.net.BindException: Address already in use

at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.seleniumhq.jetty9.server.ServerConnector.open(ServerConnector.java:321)
at org.seleniumhq.jetty9.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.seleniumhq.jetty9.server.ServerConnector.doStart(ServerConnector.java:236)
at org.seleniumhq.jetty9.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.seleniumhq.jetty9.server.Server.doStart(Server.java:366)
at org.seleniumhq.jetty9.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.openqa.grid.web.Hub.start(Hub.java:192)
at Configuration.BaseSetup.setUp(BaseSetup.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:458)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.access$000(SuiteRunner.java:40)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:489)
at org.testng.internal.thread.ThreadUtil$1.call(ThreadUtil.java:52)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

May 06, 2019 2:37:09 PM org.openqa.grid.web.Hub initServer
INFO: Will listen on 4444
May 06, 2019 2:37:09 PM org.openqa.grid.web.Hub initServer
INFO: Will listen on 4444
May 06, 2019 2:37:09 PM org.openqa.grid.web.Hub initServer
INFO: Will listen on 4444
May 06, 2019 2:37:09 PM org.openqa.grid.web.Hub initServer
INFO: Will listen on 4444

Test ignored.

java.net.BindException: Address already in use

at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.seleniumhq.jetty9.server.ServerConnector.open(ServerConnector.java:321)
at org.seleniumhq.jetty9.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.seleniumhq.jetty9.server.ServerConnector.doStart(ServerConnector.java:236)
at org.seleniumhq.jetty9.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.seleniumhq.jetty9.server.Server.doStart(Server.java:366)
at org.seleniumhq.jetty9.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.openqa.grid.web.Hub.start(Hub.java:192)
at Configuration.BaseSetup.setUp(BaseSetup.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:458)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.access$000(SuiteRunner.java:40)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:489)
at org.testng.internal.thread.ThreadUtil$1.call(ThreadUtil.java:52)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

May 06, 2019 2:37:10 PM org.openqa.grid.web.Hub initServer
INFO: Will listen on 4444
May 06, 2019 2:37:10 PM org.openqa.grid.web.Hub initServer
INFO: Will listen on 4444

Test ignored.

Test ignored.
May 06, 2019 2:37:25 PM org.openqa.grid.web.Hub initServer
INFO: Will listen on 4444
May 06, 2019 2:37:25 PM org.openqa.grid.web.Hub initServer
INFO: Will listen on 4444

java.net.BindException: Address already in use

at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.seleniumhq.jetty9.server.ServerConnector.open(ServerConnector.java:321)
at org.seleniumhq.jetty9.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.seleniumhq.jetty9.server.ServerConnector.doStart(ServerConnector.java:236)
at org.seleniumhq.jetty9.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.seleniumhq.jetty9.server.Server.doStart(Server.java:366)
at org.seleniumhq.jetty9.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.openqa.grid.web.Hub.start(Hub.java:192)
at Configuration.BaseSetup.setUp(BaseSetup.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:458)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.access$000(SuiteRunner.java:40)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:489)
at org.testng.internal.thread.ThreadUtil$1.call(ThreadUtil.java:52)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)


Test ignored.

===============================================
Default Suite
Total tests run: 4, Failures: 0, Skips: 4
Configuration Failures: 4, Skips: 4
===============================================


Process finished with exit code 0


Krishnan Mahadevan

unread,
May 6, 2019, 11:07:57 AM5/6/19
to seleniu...@googlegroups.com

Basically, there are two issues here.

 

  1. Error forwarding the new session Empty pool of VM for setup Capabilities

 

This is the grid’s way of telling you that the hub came up, but it had no nodes attached to it. So, it can’t service any tests.

 

  1. java.net.BindException: Address already in use

 

It looks like you are trying to start two instances of the Selenium Grid. Going by your earlier post on this, I guess its because you start off the Hub via a @BeforeClass and you have two <test> tags in your suite file and you have configured parallel=”tests”. So TestNG is going to attempt to start both the <tests> in parallel causing the @BeforeClass (where the hub is being started) to be done concurrently. You need to relook at the way in which you are starting your Hub. Ideally speaking you should just start the Hub once per <suite> [ preferably within a @BeforeSuite ] and manage your Appium nodes via a @BeforeTest (so that it starts once per <test> tag ]

 

Here’s a very crude sample that shows how to start a hub, have a Appium node registered to it and then run tests against it.

 

Sample code:

 

import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import io.appium.java_client.service.local.flags.GeneralServerFlag;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import java.util.concurrent.TimeUnit;
import org.hamcrest.Matchers;
import org.openqa.grid.common.exception.GridException;
import org.openqa.grid.selenium.GridLauncherV3;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class AppTest {

 
private AppiumDriverLocalService service;

 
@BeforeClass
 
public void setup() throws InterruptedException {
    Thread hub =
new Thread(this::startHub);
    hub.start();
    waitForGridToComeUp();
    Thread node =
new Thread(this::startupAppiumAsNode);
    node.start();
    TimeUnit.
SECONDS.sleep(10);
  }

 
@AfterClass
 
public void cleanup() {
   
service.stop();
  }

 
@Test
 
public void testMethod() {
    System.
err.println("Printing the Hub status");
    Response response = RestAssured
        .get(
"http://localhost:4444/grid/api/hub").andReturn();
    System.
err.println(response.getBody().prettyPrint());
    response.then().assertThat().statusCode(
200);
    response = RestAssured
        .get(
"http://localhost:4444/wd/hub/status").andReturn();
    System.
err.println("Printing status");
    System.
err.println(response.getBody().prettyPrint());
    response.then().assertThat().body(
"value.message", Matchers.equalTo("Hub has capacity"));
    response.then().assertThat().statusCode(
200);
  }

 
private void startupAppiumAsNode() {
    AppiumServiceBuilder builder =
new AppiumServiceBuilder().usingAnyFreePort()
        .withArgument(GeneralServerFlag.
CONFIGURATION_FILE, "src/test/resources/config.json");
   
service = AppiumDriverLocalService.buildService(builder);
   
service.start();
   
try {
      waitForAppiumNodeToComeUp();
    }
catch (InterruptedException e) {
     
throw new GridException(e.getMessage(), e);
    }
  }

 
private void startHub() {
    String[] args =
new String[]{
       
"-role",
       
"hub",
       
"-host",
       
"localhost"
   
};
    GridLauncherV3.main(args);
  }

 
private void waitForAppiumNodeToComeUp()
     
throws InterruptedException {
   
boolean flag = true;
   
while (flag) {
     
if (service.isRunning()) {
        flag =
false;
      }
      TimeUnit.
SECONDS.sleep(5);
    }
  }

 
private void waitForGridToComeUp() throws InterruptedException {
   
while (true) {
     
if (!isGridUp()) {
        TimeUnit.
SECONDS.sleep(5);
      }
else {
       
break;
      }
    }

  }

 
private boolean isGridUp() {
    Response response = RestAssured
        .get(
"http://localhost:4444/wd/hub/status").andReturn();
   
return response.statusCode() == 200;
  }

}

 

Dependencies that I have used:

 

<dependencies>
 
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
 
<dependency>
    <
groupId>io.appium</groupId>
    <
artifactId>java-client</artifactId>
    <
version>7.0.0</version>
    <
scope>test</scope>
  </
dependency>
  <
dependency>
    <
groupId>org.seleniumhq.selenium</groupId>
    <
artifactId>selenium-server</artifactId>
    <
version>3.141.59</version>
    <
scope>test</scope>
  </
dependency>
  <
dependency>
    <
groupId>org.testng</groupId>
    <
artifactId>testng</artifactId>
    <
version>6.14.3</version>
    <
scope>test</scope>
  </
dependency>
 
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
 
<dependency>
    <
groupId>io.rest-assured</groupId>
    <
artifactId>rest-assured</artifactId>
    <
version>3.3.0</version>
    <
scope>test</scope>
  </
dependency>
</
dependencies>

 

The JSON configuration file

 

{
 
"capabilities": [
    {
     
"maxInstances": 1,
     
"platform": "Android"
   
}
  ],
 
"configuration": {
   
"cleanUpCycle": 2000,
   
"timeout": 30000,
   
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
   
"maxSession": 1,
   
"register": true,
   
"registerCycle": 5000,
   
"hubPort": 4444,
   
"host": "localhost",
   
"hubHost": "localhost"
 
}
}

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/f7f62236-9450-4d53-97fb-b032ca9cdcd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Amr Kamel

unread,
May 8, 2019, 2:54:26 AM5/8/19
to Selenium Users
@Krishnan Mahadevan

thanks krishnan for the details answer i really appreciate it i have edit my script to be as shown below, i tagged grid class as u advised to run once beforeSuite and appium server will be run beforeMethod and tear down AfterMethod, but i encounter another error 
"org.openqa.selenium.WebDriverException: org.openqa.selenium.WebDriverException: cannot forward the request 127.0.0.1:5000 failed to respond"
that happens every time, the error lead to one test among the 4 tests fails this occurred when im using @AfterMethod for tear down function

but if i used tag @AfterClass or Test its working fine but takes more time almost 1.5 min more 

so i there way around to fix this issue and still use the advantage of short time for @AfterMethod 

im running 2 tests in parallel in two android devices

""

Enter code here...package Configuration;



import android.graphics.drawable.Animatable;

import org.openqa.grid.common.GridRole;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.common.exception.GridException;
import org.openqa.grid.internal.utils.GridHubConfiguration;
import org.openqa.grid.internal.utils.SelfRegisteringRemote;
import org.openqa.grid.selenium.proxy.DefaultRemoteProxy;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.Response;
import org.openqa.selenium.server.SeleniumServer;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.BindException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import io.appium.java_client.service.local.flags.ServerArgument;



public class BaseSetup extends GridHub {


protected static AndroidDriver<MobileElement> driver = null;
protected AppiumDriverLocalService service;
public WebDriverWait wait;
private ThreadLocalDriver threadLocalDriver = new ThreadLocalDriver();
private SeleniumServer hub;


@Parameters({"deviceName","platformVersion","udid","URL_","Sport","deviceId","sysPort","bootStrap","wdaPort","path"})
@BeforeMethod(alwaysRun = true)
public void setUp (String deviceName, String platformVersion, String udid, String URL_, String Sport, String deviceId, String sysPort, String bootStrap, String wdaPort, String path) throws Exception {


        System.out.println("Driver Is Initiated");
DesiredCapabilities dc = new DesiredCapabilities();

// Mobile setup
//        dc.setCapability("deviceId", deviceId);
// dc.setCapability("automationName", "uiautomator2");

dc.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, platformVersion);
dc.setCapability(AndroidMobileCapabilityType.SYSTEM_PORT, sysPort);


        dc.setCapability(MobileCapabilityType.UDID,udid);
//        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2"); // Make the test fail after first tear down "BROWSER_TIMEOUT"
// dc.setCapability("appium:uiautomator2ServerInstallTimeout", "8000");


// Application setup
        dc.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "y");
dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "");
dc.setCapability(AndroidMobileCapabilityType.APP_WAIT_ACTIVITY, "com.ty");

dc.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS,"true");
dc.setCapability(MobileCapabilityType.CLEAR_SYSTEM_FILES, true);


// Driver configuration
// int port = Integer.parseInt(Sport); //need when use function .using
service = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new File("/usr/local/bin/node"))
.withAppiumJS(new File("/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js"))
.withArgument(Arg.ADDRESS,URL_)
.withArgument(Arg.PORT,Sport)
.withArgument(Arg.CALLBACKPORT,Sport)
.withArgument(Arg.WDALOCALPORT,wdaPort)
.withArgument(Arg.BootstrapPort,bootStrap)
.withArgument(Arg.NODECONFIG,path)
.withArgument(Arg.SESSIONOVERRIDE));
service.start();
        try {
waitForAppiumNodeToComeUp();
} catch (InterruptedException e) {
throw new GridException(e.getMessage(), e);
}

//                Thread.sleep(10000); // Needed for appium server to wait for selenium grid to register the node
// Thread.currentThread().join();

driver = new AndroidDriver (new URL("http://localhost:4444/wd/hub"), dc);

//Thread.sleep(5000);
////        threadLocalDriver.setTLDriver(new AndroidDriver<MobileElement>(new URL("http://"+URL_+":"+Sport+"/wd/hub"),dc));
//        threadLocalDriver.setTLDriver(new AndroidDriver<MobileElement>(new URL("http://localhost:4444/wd/hub"),dc));
// driver = threadLocalDriver.getTLDriver();
// wait = new WebDriverWait(driver, 10);
}

    private void waitForAppiumNodeToComeUp()
throws InterruptedException {
boolean flag = true;
while (flag) {
if (service.isRunning()) {
flag = false;
}
TimeUnit.SECONDS.sleep(5);
}
}

    @AfterMethod
public void tearDown() throws InterruptedException {
if (driver != null)
TimeUnit.SECONDS.sleep(2);
// driver.quit(); //will lead to unexpected behaviour during teardown, some test will fail
service.stop();
System.out.println("Driver quit");

}

// @AfterTest
//    public synchronized void teardown()  {
// if (driver != null)
////            driver.quit();
// service.stop();
// }
}




consol log

Screen Shot 2019-05-08 at 8.36.58 AM.png

Enter code here...
org.openqa.selenium.WebDriverException: org.openqa.selenium.WebDriverException: cannot forward the request 127.0.0.1:5000 failed to respond
Command duration or timeout: 0 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'WS-MIRELSP-OSX', ip: '192.168.43.219', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.4', java.version: '1.8.0_152-release'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {appActivity: com.sfdmobile.MainActivity, appPackage: com.sarajevo.food.dictionary, appWaitActivity: com.sfdmobile.MainActivity, autoGrantPermissions: true, clearSystemFiles: true, databaseEnabled: false, desired: {appActivity: com.sfdmobile.MainActivity, appPackage: com.sarajevo.food.dictionary, appWaitActivity: com.sfdmobile.MainActivity, autoGrantPermissions: true, clearSystemFiles: true, deviceName: SM_N9208, platformName: Android, platformVersion: 7.0, systemPort: 8240, udid: 0715f75124ea0934}, deviceManufacturer: samsung, deviceModel: SM-N9208, deviceName: 0715f75124ea0934, deviceScreenSize: 1440x2560, deviceUDID: 0715f75124ea0934, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, platform: LINUX, platformName: Android, platformVersion: 7.0, systemPort: 8240, takesScreenshot: true, udid: 0715f75124ea0934, warnings: {}, webStorageEnabled: false}
Session ID: 5deb1c5c-3aa1-4fdc-addd-11eab1b202ce
*** Element info: {Using=class name, value=android.widget.ImageView}

at io.appium.java_client.pagefactory.AppiumElementLocator$WaitingFunction.apply(AppiumElementLocator.java:192)
at io.appium.java_client.pagefactory.AppiumElementLocator$WaitingFunction.apply(AppiumElementLocator.java:1)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:249)
at io.appium.java_client.pagefactory.AppiumElementLocator.waitFor(AppiumElementLocator.java:99)
at io.appium.java_client.pagefactory.AppiumElementLocator.findElements(AppiumElementLocator.java:140)
at io.appium.java_client.pagefactory.interceptors.InterceptorOfAListOfElements.intercept(InterceptorOfAListOfElements.java:48)
at $java.util.ArrayList$$EnhancerByCGLIB$$b5855c01.get(<generated>)
at Pages.LandingPage.sign_as_Tourist(LandingPage.java:98)
at Tests.LandingPageTest.Verify_user_can_use_tourist_mode(LandingPageTest.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.access$000(SuiteRunner.java:40)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:489)
at org.testng.internal.thread.ThreadUtil$1.call(ThreadUtil.java:52)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.openqa.selenium.WebDriverException: cannot forward the request 127.0.0.1:5000 failed to respond
Command duration or timeout: 0 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'WS-MIRELSP-OSX', ip: '192.168.43.219', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.4', java.version: '1.8.0_152-release'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {appActivity: com.sfdmobile.MainActivity, appPackage: com.sarajevo.food.dictionary, appWaitActivity: com.sfdmobile.MainActivity, autoGrantPermissions: true, clearSystemFiles: true, databaseEnabled: false, desired: {appActivity: com.sfdmobile.MainActivity, appPackage: com.sarajevo.food.dictionary, appWaitActivity: com.sfdmobile.MainActivity, autoGrantPermissions: true, clearSystemFiles: true, deviceName: SM_N9208, platformName: Android, platformVersion: 7.0, systemPort: 8240, udid: 0715f75124ea0934}, deviceManufacturer: samsung, deviceModel: SM-N9208, deviceName: 0715f75124ea0934, deviceScreenSize: 1440x2560, deviceUDID: 0715f75124ea0934, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, platform: LINUX, platformName: Android, platformVersion: 7.0, systemPort: 8240, takesScreenshot: true, udid: 0715f75124ea0934, warnings: {}, webStorageEnabled: false}
Session ID: 5deb1c5c-3aa1-4fdc-addd-11eab1b202ce
*** Element info: {Using=class name, value=android.widget.ImageView}
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:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:353)
at io.appium.java_client.DefaultGenericMobileDriver.findElements(DefaultGenericMobileDriver.java:54)
at io.appium.java_client.AppiumDriver.findElements(AppiumDriver.java:152)
at org.openqa.selenium.remote.RemoteWebDriver.findElementsByClassName(RemoteWebDriver.java:416)
at io.appium.java_client.DefaultGenericMobileDriver.findElementsByClassName(DefaultGenericMobileDriver.java:130)
at io.appium.java_client.AppiumDriver.findElementsByClassName(AppiumDriver.java:176)
at org.openqa.selenium.By$ByClassName.findElements(By.java:380)
at org.openqa.selenium.support.pagefactory.ByChained.findElements(ByChained.java:69)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:311)
at io.appium.java_client.DefaultGenericMobileDriver.findElements(DefaultGenericMobileDriver.java:50)
at io.appium.java_client.AppiumDriver.findElements(AppiumDriver.java:148)
at io.appium.java_client.pagefactory.bys.ContentMappedBy.findElements(ContentMappedBy.java:54)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:311)
at io.appium.java_client.DefaultGenericMobileDriver.findElements(DefaultGenericMobileDriver.java:50)
at io.appium.java_client.AppiumDriver.findElements(AppiumDriver.java:148)
at io.appium.java_client.pagefactory.AppiumElementLocator.lambda$1(AppiumElementLocator.java:142)
at io.appium.java_client.pagefactory.AppiumElementLocator$WaitingFunction.apply(AppiumElementLocator.java:172)
... 28 more
Caused by: org.openqa.grid.common.exception.GridException: cannot forward the request 127.0.0.1:5000 failed to respond
at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:140)
Message has been deleted

Amr Kamel

unread,
May 8, 2019, 3:10:16 AM5/8/19
to Selenium Users
hi krishnan 


Also im a bit confused is it really necessary to use selenium grid while performing parallel test


cuz actually i tried to run test without selenium grid at all parallel and it works fine used code below could you please explain if im missing something  

public class BaseSetup  {

protected static AndroidDriver<MobileElement> driver = null;
protected AppiumDriverLocalService service;
public WebDriverWait wait;
private ThreadLocalDriver threadLocalDriver = new ThreadLocalDriver();
private SeleniumServer hub;


@Parameters({"deviceName","platformVersion","udid","URL_","Sport","deviceId","sysPort","bootStrap","wdaPort","path"})
@BeforeMethod(alwaysRun = true)
public void setUp (String deviceName, String platformVersion, String udid, String URL_, String Sport, String deviceId, String sysPort, String bootStrap, String wdaPort, String path) throws Exception {


        System.out.println("Driver Is Initiated");
DesiredCapabilities dc = new DesiredCapabilities();


        dc.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, platformVersion);
dc.setCapability(AndroidMobileCapabilityType.SYSTEM_PORT, sysPort);

        dc.setCapability(MobileCapabilityType.UDID,udid);
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2"); // Make the test fail after first tear down "BROWSER_TIMEOUT"
        dc.setCapability("appium:uiautomator2ServerInstallTimeout", "6000");


// Application setup
dc.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.sarajevo.food.dictionary");
dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.sfdmobile.MainActivity");
//        dc.setCapability(AndroidMobileCapabilityType.APP_WAIT_ACTIVITY, "com.sfdmobile.MainActivity");

dc.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS,"true");
dc.setCapability(MobileCapabilityType.CLEAR_SYSTEM_FILES, true);


     service = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new File("/usr/local/bin/node"))
.withAppiumJS(new File("/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js"))
.withArgument(Arg.ADDRESS,URL_)
.withArgument(Arg.PORT,Sport)
.withArgument(Arg.CALLBACKPORT,Sport)
.withArgument(Arg.WDALOCALPORT,wdaPort)
.withArgument(Arg.BootstrapPort,bootStrap)
//                    .withArgument(Arg.NODECONFIG,path)
.withArgument(Arg.SESSIONOVERRIDE));
service.start();



// driver = new AndroidDriver (new URL("http://localhost:4444/wd/hub"), dc);
driver = new AndroidDriver (new URL("http://"+URL_+":"+Sport+"/wd/hub"), dc);




@AfterMethod
public void tearDown() throws InterruptedException {
        if (driver != null)
// TimeUnit.SECONDS.sleep(2);

Krishnan Mahadevan

unread,
May 8, 2019, 5:47:13 AM5/8/19
to seleniu...@googlegroups.com
Hard to say without running the actual tests locally at my end and that is currently not possible since I don't have the setup.

So maybe you can do one of the following:

1. Create a sample standalone project along with a demo app that can be used to reproduce the problem.

2. Share the sample project ( preferably as a GitHub link ) in this forum and perhaps someone else who is more hands on with the mobile automation ( it's been quite sometime since I did this and so I may be pretty rusty) to take a look and resolve the problem for you.

Depending upon how your tests are being grouped you may need a @BeforeTest or a @BeforeClass annotation. Ideally speaking the appium node needs to be spun off only once and the tests can run against it ( again I assume that you would have also taken care of ensuring that the appium node is able to talk to the actual device properly )

On a side note : you could also try posting on the appium forums for a quick turnaround.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

Krishnan Mahadevan

unread,
May 8, 2019, 5:48:29 AM5/8/19
to seleniu...@googlegroups.com

If parallel execution works fine without the grid then go with that setup. What is the confusion ?

I am a bit outdated with the internals of how the appium server is managed and if it's session safe. So I don't have an apt answer to your question.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

On 8 May 2019, at 12:36, Amr Kamel <akamel...@gmail.com> wrote:

Also im a bit confused is it really necessary to use selenium grid while performing parallel test


cuz actually i tried to run test without selenium grid at all parallel and it works fine used code below  

public class BaseSetup  {

protected static AndroidDriver<MobileElement> driver = null;
protected AppiumDriverLocalService service;
public WebDriverWait wait;
private ThreadLocalDriver threadLocalDriver = new ThreadLocalDriver();
private SeleniumServer hub;


@Parameters({"deviceName","platformVersion","udid","URL_","Sport","deviceId","sysPort","bootStrap","wdaPort","path"})
@BeforeMethod(alwaysRun = true)
public void setUp (String deviceName, String platformVersion, String udid, String URL_, String Sport, String deviceId, String sysPort, String bootStrap, String wdaPort, String path) throws Exception {


        System.out.println("Driver Is Initiated");
DesiredCapabilities dc = new DesiredCapabilities();

// Mobile setup


dc.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, platformVersion);
dc.setCapability(AndroidMobileCapabilityType.SYSTEM_PORT, sysPort);

        dc.setCapability(MobileCapabilityType.UDID,udid);
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2"); // Make the test fail after first tear down "BROWSER_TIMEOUT"
        dc.setCapability("appium:uiautomator2ServerInstallTimeout", "6000");


// Application setup
dc.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.sarajevo.food.dictionary");
dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.sfdmobile.MainActivity");
//        dc.setCapability(AndroidMobileCapabilityType.APP_WAIT_ACTIVITY, "com.sfdmobile.MainActivity");

dc.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS,"true");
dc.setCapability(MobileCapabilityType.CLEAR_SYSTEM_FILES, true);


// Driver configuration
     service = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new File("/usr/local/bin/node"))
.withAppiumJS(new File("/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js"))
.withArgument(Arg.ADDRESS,URL_)
.withArgument(Arg.PORT,Sport)
.withArgument(Arg.CALLBACKPORT,Sport)
.withArgument(Arg.WDALOCALPORT,wdaPort)
.withArgument(Arg.BootstrapPort,bootStrap)
//                    .withArgument(Arg.NODECONFIG,path)
.withArgument(Arg.SESSIONOVERRIDE));
service.start();


// driver = new AndroidDriver (new URL("http://localhost:4444/wd/hub"), dc);
driver = new AndroidDriver (new URL("http://"+URL_+":"+Sport+"/wd/hub"), dc);




    @AfterMethod
public void tearDown() throws InterruptedException {
        if (driver != null)
// TimeUnit.SECONDS.sleep(2);

Amr Kamel

unread,
May 8, 2019, 7:17:36 AM5/8/19
to seleniu...@googlegroups.com
Thanks krishnan for your clear answer and fast response 

Im just new with selenium grid and whenever i was checking resources ppl were using it to run parallel test, but actually i managed to make it work without so wanted to know if it correct behaviour to get raid of selenium grid since code will be more simple and faster in execution 

But thanks for ur feedback i will make this sample project and post it here

Kind regards


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

sravan palleti

unread,
May 8, 2019, 10:37:32 AM5/8/19
to seleniu...@googlegroups.com
Purpose of selenium grid  is to execute your test scripts remotely on a different machine. If you're using grid for just parallel execution, You need to think about it.



On Wed, May 8, 2019 at 3:06 AM Amr Kamel <akamel...@gmail.com> wrote:

Also im a bit confused is it really necessary to use selenium grid while performing parallel test


cuz actually i tried to run test without selenium grid at all parallel and it works fine used code below  

public class BaseSetup  {

protected static AndroidDriver<MobileElement> driver = null;
protected AppiumDriverLocalService service;
public WebDriverWait wait;
private ThreadLocalDriver threadLocalDriver = new ThreadLocalDriver();
private SeleniumServer hub;


@Parameters({"deviceName","platformVersion","udid","URL_","Sport","deviceId","sysPort","bootStrap","wdaPort","path"})
@BeforeMethod(alwaysRun = true)
public void setUp (String deviceName, String platformVersion, String udid, String URL_, String Sport, String deviceId, String sysPort, String bootStrap, String wdaPort, String path) throws Exception {


        System.out.println("Driver Is Initiated");
DesiredCapabilities dc = new DesiredCapabilities();

// Mobile setup


dc.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, platformVersion);
dc.setCapability(AndroidMobileCapabilityType.SYSTEM_PORT, sysPort);

        dc.setCapability(MobileCapabilityType.UDID,udid);
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2"); // Make the test fail after first tear down "BROWSER_TIMEOUT"
        dc.setCapability("appium:uiautomator2ServerInstallTimeout", "6000");


// Application setup
dc.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.sarajevo.food.dictionary");
dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.sfdmobile.MainActivity");
//        dc.setCapability(AndroidMobileCapabilityType.APP_WAIT_ACTIVITY, "com.sfdmobile.MainActivity");

dc.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS,"true");
dc.setCapability(MobileCapabilityType.CLEAR_SYSTEM_FILES, true);


// Driver configuration
     service = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new File("/usr/local/bin/node"))
.withAppiumJS(new File("/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js"))
.withArgument(Arg.ADDRESS,URL_)
.withArgument(Arg.PORT,Sport)
.withArgument(Arg.CALLBACKPORT,Sport)
.withArgument(Arg.WDALOCALPORT,wdaPort)
.withArgument(Arg.BootstrapPort,bootStrap)
//                    .withArgument(Arg.NODECONFIG,path)
.withArgument(Arg.SESSIONOVERRIDE));
service.start();


// driver = new AndroidDriver (new URL("http://localhost:4444/wd/hub"), dc);
driver = new AndroidDriver (new URL("http://"+URL_+":"+Sport+"/wd/hub"), dc);




@AfterMethod
public void tearDown() throws InterruptedException {
        if (driver != null)

// TimeUnit.SECONDS.sleep(2);
// driver.quit(); //will lead to unexpected behaviour during teardown, some test will fail
service.stop();
System.out.println("Driver quit");

}


}

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Krishnan Mahadevan

unread,
May 8, 2019, 10:40:06 AM5/8/19
to seleniu...@googlegroups.com

Sravan,

 

>>>> If you're using grid for just parallel execution, You need to think about it.

 

What is wrong in leveraging the Selenium Grid just for parallel executions? Can you please help elaborate/clarify what pitfalls you see with that ?

Supporting parallel execution and thus bringing down the overall execution time of tests is also one of the use cases that the Grid was built for.

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.com/

 

sravan palleti

unread,
May 8, 2019, 10:56:57 AM5/8/19
to seleniu...@googlegroups.com
Krishnan,

 For just only Parallel Execution when you have limited test scripts to be executed. We can do it in local, why you want Grid? 

Basic purpose of grid was built to accommodate large test suites execution => (Remote machine + parallel execution) GRID 

Krishnan Mahadevan

unread,
May 8, 2019, 12:29:32 PM5/8/19
to seleniu...@googlegroups.com
Many reasons why a grid is always favoured even when it comes to a small number of concurrent test executions:

1. Tests are running on a build server which is headless and lacks browser  binary installation.
2. One needs to run multiple tests on IE browsers ( the last I checked IE still shared sessions across multiple instances on the same machine )
3. The local machine lacks the required hardware power.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

sravan palleti

unread,
May 8, 2019, 12:36:30 PM5/8/19
to seleniu...@googlegroups.com
Agreed!. I went through your blog, it's impressive! keep up the good work.



Reply all
Reply to author
Forward
0 new messages