Connecting appium server to selenium grid for android


#62

@bhaskar

Thanks i have done it

are you using parallel execution in testng or junit ?

without these two how can i achieve parallel test execution for android devices?


#63

Hi @nirmal_kumar

I’m using TestNG for parallel execution.


pinned #64

#65

Hi All,

I have created a simple way to run appium script on multiple android devices simultaneously.
You don’t have to bother about how many devices are connected. how many appium server to start, it take cares all of it.

Just need to some installation process and extends one class.
I am still working on it.


#66

Thanks @sameer49

I have executed your which is in github real it’s cool and working fine awesome stuff :smile:

I try with my application to run parallel while installation it’self getting failed saying that error to access the same apk file because my first instance was lock that resource can you give me a solution on it :sunny:

Thanks in advance :heart_eyes:


#67

Hi @nirmal_kumar

I am also facing same issue for app, filed issue for same https://github.com/sameer49/Appium-Grid-For-Android/issues/1
But its intermittent.


#68

Nice work @sameer49 ,

You made the things simple…!!! great job. :+1:


#69

Nice work @sameer49 , starting the Appium server based on the connected device indeed a great approach and reduces the effort to start grid execution.


#70

@sameer49 appreciate your work.
great job buddy… keep it up


#71

I have 2 desktop machines in which Appium script is saved in machine 1 and Appium got installed in machine 2 and android devices also connected in machine 2. now i want to take the script from the machine 1 and execute it in the devices connected in the machine 2. how to achieve this.


#72

Hi All,
@Hassan_Radi ,@Srikanth_Katakam,@karthik_holla,@Appium_Master
Is it possible to have Appium running on a remote machine and devices also connected in a same remote machine, and run the test script from the local machine?


#74

yes thats possible. Only you need give remote mache ip address on appium server details


#75

Machine A IP:- 192.168.2.3
Run appium server on machine A.

Machine B :- Where your scripts are kept.
machine B should be able to ping and accessable machine A.
Run the script like below with providing Machine A IP Address.

public class AppiumExampleTest { private WebDriver driver = null; @Before public void setup() { File appDir = new File("…//TestedAndroidApp//bin//"); File app = new File(appDir, “TestedAndroidApp.apk”); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, “”); capabilities.setCapability(CapabilityType.VERSION, “4.2”); capabilities.setCapability(CapabilityType.PLATFORM, “WINDOWS”); capabilities.setCapability(CapabilityConstants.DEVICE, “android”); capabilities.setCapability(CapabilityConstants.APP_PACKAGE, “com.example.android”); capabilities.setCapability(CapabilityConstants.APP_ACTIVITY, “MainActivity”); capabilities.setCapability(CapabilityConstants.APP, app.getAbsolutePath()); try { driver = new RemoteWebDriver(new URL(“http://192.168.2.3:4723/wd/hub”), capabilities); } catch (MalformedURLException e) { e.printStackTrace(); } driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS); } @Test public void appiumExampleTest() throws Exception { // find button with label or content-description “Button 1” WebElement button=driver.findElement(By.name(“Button 1”)); // click on button and start second Activity button.click(); // we are on second screen now // check if second screen contains TextView with text “Activity2” driver.findElement(“Activity2”); // click back button HashMap<String, Integer> keycode = new HashMap<String, Integer>(); keycode.put(“keycode”, 4); ((JavascriptExecutor) driver).executeScript(“mobile: keyevent”, keycode); // we are again in main activity driver.findElement(By.name(“Button1”)); } @After public void tearDown() { if (driver != null) { driver.quit(); } } }


#76

How can I pass multiple json files here? Can anyone let me know the steps?


#77

Its possible through
Machine-1 : ip - 127.0.01 Running grid server
Machine-1 : ip - 127.0.02 Run appium node- appium -a 127.0.0.2 -p 4723 --bootstrap-port 4727 -U emulator-5554 --nodeconfig %~dp0jsonfiles\nodeconfig_1.json

Json file looks like:

{
“capabilities”:
[
{
“browserName”: “Android”,
“version”:“4.4”,
“maxInstances”: 1,
“platform”:“ANDROID”,
“deviceName”:“emulator-5554”
}],

"configuration":

{
“nodeTimeout”:120,
“port”:4723,
“hubPort”:4444,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.2:4723/wd/hub”,
“hub”: “12.0.0.1:4444/grid/register”,
“hubHost”:“127.0.0.1”,
“registerCycle”:10000,
“register”:true,
“maxSession”:1
}
}

now check on grid server machine and open grid console
you can see node have been registered on grid.

Same way you can register multiple node on multiple machine with different Json files.

Cheerrrrsssss :smiley:


#78

Nodes are registered to hub.

Json file:
{
“capabilities”:
[
{
“browserName”: “Android”,
“version”: “4.4.2”,
“maxInstances”: 5,
“platform”: “ANDROID”,
“deviceName”: “3204da2a5075c0b5”
}
],
“configuration”:
{
“nodeTimeout”:120,
“cleanUpCycle”:2000,
“timeout”:2000000,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:4723/wd/hub”,
“maxSession”: 20,
“port”: 4723,
“host”: “127.0.0.1”,
“register”: true,
“registerCycle”: 5000,
“hub”: “127.0.0.1:4441/grid/register”,
“hubPort”: 4441,
“hubHost”: “localhost”
}
}

I have mentioned the device ids in XML:

<?xml version="1.0" encoding="UTF-8"?>

And referring those in script as
class delaration**

   @Parameters(value={"device_id"})
    @BeforeSuite//The annotated method will be run before all tests in this suite have run. 
    public static WebDriver atStart(@Optional ("2636b827a05e6bb3") String device_id) throws InterruptedException, IOException
    {    
        //setup property with webdriver to create/cutomize a session with webdriver
        DesiredCapabilities capabilities = new DesiredCapabilities();
        System.out.println(""+device_id);
        if ("36C35E3F00B8B341".equals(device_id))
        {
        
            try 
            {
                writer = new FileWriter("..\\Avaamoo\\DataFile\\avaamoMessagePerformanceResults.csv");
            } 
            catch (IOException e) 
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } // windows machine
            

             writer.write("Network Type");
             writer.write(',');
             writer.write("File Type");
             writer.write(',');
             writer.write("File Size");
             writer.write(",");
             writer.write("Total Time Taken to send file (in MS)");
             writer.write(",");
             writer.write('\n');
             

            //Load the excel file to fetch data
            try
            {
                importData();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            
            File app = new File(applicationPath);
            capabilities.setCapability("automationName", "Appium");
            capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
            
            //samsung-sm_n750-3204da2a5075c0b5//micromax-micromax_a311-8a2d363//samsung-nexus_s-30345C56DC2000EC
            capabilities.setCapability("deviceName", "3204da2a5075c0b5");
            capabilities.setCapability("platformVersion", "4.4.2");//Or//capabilities.setCapability(CapabilityType.VERSION, "4.1.2");
            capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
            capabilities.setCapability("platformName", "ANDROID");//Or//capabilities.setCapability(CapabilityType.PLATFORM, "Android");
            capabilities.setCapability("app", app.getAbsolutePath());
            capabilities.setCapability("appPackage", "com.avaamo.android.staging"); //Replace with your app's package
            capabilities.setCapability("appActivity", "com.avaamo.android.ui.LandingActivity"); //Replace with app's Activity
            //setting new command timeout for selenium server
            capabilities.setCapability("newCommandTimeout", "2000000");//33.33 mins
        }

Problem is: The value referred from the xml is null in the script hence I have to mention one device id explicitly for @Optional parameter. Then script executes on one device only.

If value for @optional parameter is removed, it says “org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: deviceName) (WARNING: The server did not provide any stacktrace information)”

I have provided the Device name in script as well as in json files too.

I want to run the script on all attached nodes.

@Hassan_Radi @Appium_Master Please suggest.


#79

Update:

Writing the parameters in xml above test tags resolved the problem.

Currently facing following error
Error forwarding the new session cannot find : Capabilities org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities [{app=D:\APKs\Automated_Projects\avaamo_staging.apk, appPackage=com.avaamo.android.staging, appActivity=com.avaamo.android.ui.LandingActivity, newCommandTimeout=2000000, platformVersion=4.4, automationName=Appium, browserName=Android, platformName=Android, deviceName=30345C56DC2000EC, platform=WINDOWS}]"

Following is the script:

@Parameters(value={“device_id1”,“device_id2”})
@BeforeSuite//The annotated method will be run before all tests in this suite have run.
public static WebDriver atStart(@Optional(“nnn”) String device_id1, String device_id2) throws InterruptedException, IOException
{

if (“226CF65ED0ABE221”.equals(device_id1))//FOR SAMSUNG GALAXY NOTE
{
File app = new File(applicationPath);
capabilities.setCapability(“automationName”, “Appium”);
capabilities.setCapability(CapabilityType.BROWSER_NAME, “android”);

            //samsung-sm_n750-3204da2a5075c0b5//micromax-micromax_a311-8a2d363//samsung-nexus_s-30345C56DC2000EC
            capabilities.setCapability("deviceName", "3204da2a5075c0b5");
        //    capabilities.setCapability("udid", "226CF65ED0ABE221");
            capabilities.setCapability("platformVersion", "4.4");
            capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
            capabilities.setCapability("platformName", "ANDROID");
            capabilities.setCapability("app", app.getAbsolutePath());
            capabilities.setCapability("appPackage", "com.avaamo.android.staging"); //Replace with your app's package
            capabilities.setCapability("appActivity", "com.avaamo.android.ui.LandingActivity"); //Replace with app's Activity
            //setting new command timeout for selenium server
            capabilities.setCapability("newCommandTimeout", "2000000");//33.33 mins
        }
            
            
        if("2636B827A05E6BB3".equals(device_id2))//fOR NEXUS ROOTED
        {
            System.out.println("in nexus: "+device_id2);
            File app1 = new File(applicationPath);
            capabilities.setCapability("automationName", "Appium");
            capabilities.setCapability(CapabilityType.BROWSER_NAME,"android");
         
            capabilities.setCapability("deviceName", "30345C56DC2000EC");
            //capabilities.setCapability("udid", "2636B827A05E6BB3");
            capabilities.setCapability("platformVersion", "4.4");
            capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
            capabilities.setCapability("platformName","ANDROID");
            capabilities.setCapability("app", app1.getAbsolutePath());
            capabilities.setCapability("appPackage", "com.avaamo.android.staging"); //Replace with your app's package
            capabilities.setCapability("appActivity", "com.avaamo.android.ui.LandingActivity"); //Replace with app's Activity
            
            //setting new command timeout for selenium server
            capabilities.setCapability("newCommandTimeout", "2000000");//33.33 mins
        }
        return driver = new AndroidDriver(new URL("http://127.0.0.1:4441/wd/hub"), capabilities);

}

json files:
Node1.json
{
“capabilities”:
[
{
“browserName”: “android”,
“version”: “4.4.2”,
“maxInstances”: 5,
“platform”: “ANDROID”,
“deviceName”: “3204da2a5075c0b5”
}
],
“configuration”:
{
“nodeTimeout”:120,
“cleanUpCycle”:2000,
“timeout”:2000000,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:4723/wd/hub”,
“maxSession”: 20,
“port”: 4723,
“host”: “127.0.0.1”,
“register”: true,
“registerCycle”: 5000,
“hub”: “127.0.0.1:4441/grid/register”,
“hubPort”: 4441,
“hubHost”: “localhost”
}
}
Node2.json
{
“capabilities”:
[
{
“browserName”: “android”,
“version”: “4.4”,
“maxInstances”: 5,
“platform”: “ANDROID”,
“deviceName”: “30345C56DC2000EC”
}
],
“configuration”:
{
“nodeTimeout”:120,
“cleanUpCycle”:2000,
“timeout”:2000000,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:3000/wd/hub”,
“maxSession”: 20,
“port”: 3000,
“host”: “127.0.0.1”,
“register”: true,
“registerCycle”: 5000,
“hub”: “127.0.0.1:4441/grid/register”,
“hubPort”: 4441,
“hubHost”: “localhost”
}
}

NOTE: Starting the nodes from appium gui providing the json files for respective nodes. and successfully connecting.

@Hassan_Radi @Appium_Master @Arvind_Patel Please suggest.


#80

I understand that hub is not able to find the node to forward request.

Does anyone have any idea, what is wrong in the script or any file mentioned above?
Not able to understand whats wrong :frowning:

@Hassan_Radi @Appium_Master @Arvind_Patel @rgonalo


#81

The hub does not find any node because both nodes are configured with “platform”: “ANDROID” and the test requests a node with a “WINDOWS” platform:
capabilities.setCapability(CapabilityType.PLATFORM, “WINDOWS”);


#82

Thanks @rgonalo
capabilityType.PLATFORM should be removed?
Please suggest.