Connecting appium server to selenium grid for android


#124

Can some one please help in the problem above?
Looking forward support here !

@Appium_Master @appium_ia @Arvind_Patel @Hassan_Radi @rgonalo


#125

@Nitin_Thite
can you provide the stack trace of the error message? which lines originated the error??


#126

@Hassan_Radi
Thanks ! The error does not exist now.

@jonahss @Hassan_Radi @Arvind_Patel @rgonalo @Appium_Master @appium_ia
What happens now is:
App is installed on both the devices but executes the script 2 times in one device one after another.

Following are the json files:
for node 1:
{
“capabilities”:
[
{
“browserName”:“android”,
“deviceName”: “SM-N750”,
“version”:“4.4.2”,
“maxInstances”:5,
“platform”:“ANDROID”,
“applicationName”: “3204da2a5075c0b5”
}
],
“configuration”:
{
“nodeTimeout”:120,
“cleanUpCycle”:2000,
“timeout”:10000,
“proxy”:“org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://xxxx:5566/wd/hub”,
“maxSession”:1,
“port”:5566,
“register”:true,
“registerCycle”:5000,
“hub”: “xxxx:4441/grid/register”,
“hubPort”: 4441,
“hubHost”: “xxxx”,
“role”:“node”
}
}

Node 2:
{
“capabilities”:
[
{
“browserName”:“android”,
“version”:“4.4.2”,
“maxInstances”:5,
“platform”:“ANDROID”,
“applicationName”: “0123456789ABCDEF”,
“deviceName”: “Micromax A107”
}
],
“configuration”:
{
“nodeTimeout”:120,
“cleanUpCycle”:2000,
“timeout”:10000,
“proxy”:“org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://xxxx:5577/wd/hub”,
“maxSession”:1,
“port”:5577,
“register”:true,
“registerCycle”: 5000,
“hub”: “xxxx:4441/grid/register”,
“hubPort”: 4441,
“hubHost”: “xxxx”,
“role”:“node”
}
}

Hub json:
{
“throwOnCapabilityNotPresent”:true,
“host”:“xxxx”,
“port”:4441,
“newSessionWaitTimeout”:-1,
“servlets” :[],
“prioritizer”:null,
“capabilityMatcher”:“org.openqa.grid.internal.utils.DefaultCapabilityMatcher”,
“throwOnCapabilityNotPresent”:true,
“nodePolling”:5000,

“cleanUpCycle”:5000,
“timeout”:300000,
“browserTimeout”:0,
“maxSession”:5,
“jettyMaxThreads”:-1
}

Following is the code:
public class abc{

WebDriver driver = null;
DesiredCapabilities capabilities = new DesiredCapabilities();

@Parameters(value={"device_id1","device_id2","ApplicationPath"})
@BeforeTest
public void atStart(@Optional("nnn")String device_id1,String device_id2, String ApplicationPath) throws MalformedURLException, InterruptedException
{    
        
    capabilities=DesiredCapabilities.android();
    
    capabilities.setCapability("automationName", "Appium");
    capabilities.setCapability(CapabilityType.BROWSER_NAME,"android");
    capabilities.setCapability("platformVersion", "4.4.2");
    capabilities.setCapability(CapabilityType.PLATFORM,"ANDROID");
    capabilities.setCapability("platformName","ANDROID");
    capabilities.setCapability("app", ApplicationPath);
    capabilities.setCapability("appPackage", "com.avaamo.android.staging"); //Replace with your app's package
    capabilities.setCapability("appActivity", "com.avaamo.android.ui.TabActivity"); //Replace with app's Activity
    //setting new command timeout for selenium server
    capabilities.setCapability("newCommandTimeout", "2000000");//33.33 mins
        
    if("8a2d363".equalsIgnoreCase(device_id2))
    {
        System.out.println("in nexus: "+device_id2);
        //
        capabilities.setCapability("applicationName",device_id2);
        capabilities.setCapability("udid",device_id2);
        capabilities.setCapability("deviceName","Micromax A311");
    }
    
    if ("3204da2a5075c0b5".equalsIgnoreCase(device_id1))
    {
        System.out.println("in Samsung galaxy: "+device_id1);
        //
        capabilities.setCapability("applicationName", device_id1);
        capabilities.setCapability("udid", device_id1);
        capabilities.setCapability("deviceName","SM-N750");
    }
    
    try
    {
        driver = new AndroidDriver(new URL("http://xxxx:4441/wd/hub"), capabilities);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

Could anyone please help? :smiley:


#127

Hi,

I am able to launch app on different devices but script runs on one only.
As it is parametrized from testng.xml, it is executed on single device 2 times.
It means it is executing the script that should ideally be executed on another device.
Please find details for node and script on comment no 123.

  • I am creating 2 driver instances.

Looking forward.


#128

Any one here for support ? :unamused:


#129

Hi @vijayakarthikeyan

Were you able to run the script on 2 devices?
Can please you share the script and node and hub js files?

I am able to install and launch the app on 2 devices but script is executed only on one.
I have not created 2 instances of webDriver.

Looking forward for help.
Thanks in Advance ! :wink:


Org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure
#130

(linking to own paid content is against TOS)


#131

Hi All,

Please tell me any one, how get list of iPhone device s which are connected to Mac machine using Java code. This is really helpful for me.
Thanks in advance.


#132

Hello,

There is a command that displays the list of device:
xcrun instruments -s device
You can execute this command through Java Code and then parse the response.

Hope it helps.


#133

Hi sam_viz,

Thanks for the reply.


#134

use xcrun instruments -s devices to get only device list. The above command also returns some results fr0m xcode.app.


Adb devices equivalent for iOS app's
#135

Thanks for the tip ! It’s even better this way :smiley:


#136

@Arvind_Patel
Can you please provide me exact steps to set up selenium grid. I want it from scratch.
I would like to know on how to run these json files, where to add them and all. Could you please help me with the same.


#137

Hi, have you defined different --chromedriver-port for both devices?
i did ran a test in 2 devices in parallel setting this parameter as well.


#138

Needed help
@Arvind_Patel @Hassan_Radi

My json files are:

node1.json

{
“capabilities”:
[
{
“browserName”: “Android”,
"version”:”5.0.2”,
“maxInstances”: 3,
“platform”:“ANDROID”,
"deviceName”:”X1033”
}
],
“configuration”:
{
“nodeTimeout”:120,
“port”:4723,
“hubPort”:4444,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:4723/wd/hub”,
“hub”: “127.0.0.1:4444/grid/register”,
“hubHost”:“127.0.0.1”,
“nodePolling”:2000,
“registerCycle”:10000,
“register”:true,
“cleanUpCycle”:2000,
“timeout”:30000,
“maxSession”:1
}
}

node2.json

{
“capabilities”:
[
{
“browserName”: “Android”,
“version”:“5.1”,
“maxInstances”: 3,
“platform”:“ANDROID”,
"deviceName”:”X1033”
}
],
“configuration”:
{
“nodeTimeout”:120,
“port”:4728,
“hubPort”:4444,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:4728/wd/hub”,
“hub”: “127.0.0.1:4444/grid/register”,
“hubHost”:“127.0.0.1”,
“nodePolling”:2000,
“registerCycle”:10000,
“register”:true,
“cleanUpCycle”:2000,
“timeout”:30000,
“maxSession”:1
}
}

Opened 2 appium on ports 4723 & 4728

Started grid on mac with command:

java -jar selenium-server-standalone-2.48.2.jar -role hub

starting node with command:

java -jar selenium-server-standalone-2.48.2.jar -role node -hub http://localhost:4444/grid/register —port 4723 -nodeConfig node1.json

getting ERROR:

Mac-mini:jar intelligrape$ java -jar selenium-server-standalone-2.48.2.jar -role node -hub http://localhost:4444/grid/register —port 4723 -nodeConfig node1.json
16:16:30.700 INFO - Launching a Selenium Grid node
Error building the config :Error with the JSON of the config : Wrong format for the JSON input : com.google.gson.stream.MalformedJsonException: Expected name at line 1 column 2 path $.
Usage: java -jar selenium-server.jar -role node [options]

-host:
<IP | hostname> : usually not needed and determined
automatically. For exotic network configuration, network with
VPN, specifying the host might be necessary.

-port:
: the port the remote/hub will listen on. Default to 4444.

-cleanupCycle:
in ms. How often a proxy will check for timed out thread.

-timeout:
the timeout in seconds before the hub automatically ends
a test that hasn’t had any activity in the last X seconds. The
browser will be released for another test to use. This typically
takes care of the client crashes.

-browserTimeout:
The timeout in seconds a browser can hang

-hub:
http://localhost:4444/grid/register : the url that will be used
to post the registration request. This option takes precedence
over -hubHost and -hubPort options.

-hubHost:
<IP | hostname> : the host address of a hub the registration
request should be sent to. Default to localhost. Option -hub
takes precedence over this option.

-hubPort:
: the port listened by a hub the registration request
should be sent to. Default to 4444. Option -hub takes precedence
over this option.

-proxy:
the class that will be used to represent the node. By default
org.openqa.grid.selenium.proxy.DefaultRemoteProxy.

-maxSession:
max number of tests that can run at the same time on the node,
independently of the browser used.

-registerCycle:
how often in ms the node will try to register itself again.Allow
to restart the hub without having to restart the nodes.

-nodePolling:
in ms. Interval between alive checks of node how often the hub
checks if the node is still alive.

-unregisterIfStillDownAfter:
in ms. If the node remains down for more than
unregisterIfStillDownAfter millisec, it will disappear from the
hub.Default is 1min.

-downPollingLimit:
node is marked as down after downPollingLimit alive checks.

-nodeStatusCheckTimeout:
in ms. Connection and socket timeout which is used for node alive
check.

This synopsis lists options available in node role only. To get help
on the command line options available for other roles run the server
with -help name and the corresponding -role name value.
org.openqa.grid.common.exception.GridConfigurationException: Error with the JSON of the config : Wrong format for the JSON input : com.google.gson.stream.MalformedJsonException: Expected name at line 1 column 2 path $.
at org.openqa.grid.common.RegistrationRequest.loadFromJSON(RegistrationRequest.java:574)
at org.openqa.grid.common.RegistrationRequest.build(RegistrationRequest.java:378)
at org.openqa.grid.selenium.GridLauncher.main(GridLauncher.java:83)
Caused by: org.openqa.grid.common.exception.GridConfigurationException: Wrong format for the JSON input : com.google.gson.stream.MalformedJsonException: Expected name at line 1 column 2 path $.
at org.openqa.grid.common.JSONConfigurationUtils.loadJSON(JSONConfigurationUtils.java:81)
at org.openqa.grid.common.RegistrationRequest.loadFromJSON(RegistrationRequest.java:550)
… 2 more
Caused by: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Expected name at line 1 column 2 path $.
at com.google.gson.internal.Streams.parse(Streams.java:56)
at com.google.gson.JsonParser.parse(JsonParser.java:84)
at com.google.gson.JsonParser.parse(JsonParser.java:59)
at com.google.gson.JsonParser.parse(JsonParser.java:45)
at org.openqa.grid.common.JSONConfigurationUtils.loadJSON(JSONConfigurationUtils.java:79)
… 3 more
Caused by: com.google.gson.stream.MalformedJsonException: Expected name at line 1 column 2 path $.
at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1573)
at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:517)
at com.google.gson.stream.JsonReader.hasNext(JsonReader.java:418)
at com.google.gson.internal.bind.TypeAdapters$25.read(TypeAdapters.java:666)
at com.google.gson.internal.bind.TypeAdapters$25.read(TypeAdapters.java:642)
at com.google.gson.internal.Streams.parse(Streams.java:44)
… 7 more


#139

@tovaibhav1

These two lines are the ones causing the issue. You are using invalid double quotes, thus the inability to parse the json file. Please use this site to validate your json file: http://jsonlint.com/

Change every to be "


#140

Thanks @Hassan_Radi but I used command from location “C:\Program Files (x86)\Appium\node_modules\appium\bin>”

node appium -a 192.168.1.2 -p 4723 --nodeconfig D:\TehnologyWork\Softwares\jar\node1.json

I am receiving error

C:\Program Files (x86)\Appium\node_modules\appium\bin>node appium -a 192.168.1.2 -p 4723 --nodeconfig D:\TehnologyWork\Softwares\jar\node1.json

info: Welcome to Appium v1.4.13 (REV c75d8adcb66a75818a542fe1891a34260c21f76a)
info: Appium REST http interface listener started on 192.168.1.2:4723
info: [debug] Non-default server args: {“address”:“192.168.1.2”,“nodeconfig”:“D:\TehnologyWork\Softwares\jar\node1.json”}
info: Console LogLevel: debug
> error: Unable to load node configuration file to register with grid


#141

@tovaibhav1
Please provide the full stack trace.


#142

@Hassan_Radi its full stack trace in command prompt


#143

@tovaibhav1
I am not sure what is causing this weird issue, but if I were you, I would try to load the same file using Appium .exe application and see how it would react. This would tell me if it is a problem with the file itself or the parameters I am passing.