It was due to some other error, now things seems to work fine. Thanks!!!. I used the framework mentioned by you:
Need a featured if you can build it for cucumber:
- Need a before all kind of method
It was due to some other error, now things seems to work fine. Thanks!!!. I used the framework mentioned by you:
Need a featured if you can build it for cucumber:
@Dhiren_Mudgil would be really helpfull if u can raise a issue on the repo https://github.com/saikrishna321/AppiumTestDistribution and provide more details. will surely look into this
YeahI have tried and its working fine for me.
can you share your code, so that I can guide you.
Thanks
Ravi
@ravikr42
Need help on Selenium Grid: I am trying executes script on different mobile emulators but i canât succeed . I have tried different tutorials but unable to succeed.
Tried but doesnât work. Other script are runnung fine. I have use following procedure
1)Started Hub
2)Started Node
3)try to execute script
Let me know if i am missing anything
I am trying demo example:
Code 1:- CalcExample .java
package example;
import java.io.File;
import libs.BaseTest;
import org.openqa.selenium.By;
public class CalcExample extends BaseTest{
public CalcExample(){ } public CalcExample(int deviceNum) { super(deviceNum); } public void performOperations() { try { driver.findElement(By.id("com.android2.calculator3:id/cling_dismiss")).click(); driver.findElement(By.id("com.android2.calculator3:id/digit5")).click(); driver.findElement(By.id("com.android2.calculator3:id/plus")).click(); driver.findElement(By.id("com.android2.calculator3:id/digit9")).click(); driver.findElement(By.id("com.android2.calculator3:id/equal")).click(); String num = driver.findElement(By.xpath("//android.widget.EditText[@index=0]")).getText(); System.out.println("Result : "+num); driver.closeApp(); } catch(Exception e) { e.printStackTrace(); } } public void run(){ File app = new File("C:\\AndroidCalculator.apk"); String appPath = app.getAbsolutePath(); createDriver(appPath); // create devices performOperations(); // user function }
public static void main(String[] args) { // Create object CalcExample calc = new CalcExample(); calc.execute(); }
}
Code 2:-
package libs;
import libs.DeviceConfiguration;
import io.appium.java_client.android.AndroidDriver;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class BaseTest implements Runnable{
public AndroidDriver driver;
protected BaseTest deviceThreads;
protected int numOfDevices;
protected String deviceId;
protected String deviceName;
protected String osVersion;
protected String port;
protected Thread t;
protected int deviceCount;AppiumManager appiumMan = new AppiumManager(); static Map<String, String> devices = new HashMap<String, String>(); static DeviceConfiguration deviceConf = new DeviceConfiguration();
public BaseTest(){ try { devices = deviceConf.getDivces(); deviceCount = devices.size()/3; }catch (Exception e) { e.printStackTrace(); } } public BaseTest(int i){ int deviceNumber = (i+1); this.deviceId = devices.get("deviceID"+deviceNumber); this.deviceName = devices.get("deviceName"+deviceNumber); this.osVersion = devices.get("osVersion"+deviceNumber); } public void createDriver(){ try { port = appiumMan.startAppium(); // Start appium server // create appium driver instance DesiredCapabilities capabilities = DesiredCapabilities.android(); capabilities.setCapability("deviceName", deviceName); capabilities.setCapability("platformName", "android"); capabilities.setCapability(CapabilityType.VERSION, osVersion); capabilities.setCapability(CapabilityType.BROWSER_NAME, "chrome"); capabilities.setCapability("udid", deviceId); this.driver = new AndroidDriver(new URL("http://127.0.0.1:"+port+"/wd/hub"),capabilities); } catch(Exception e){ e.printStackTrace(); } } public void createDriver(String appPath){ try { port = appiumMan.startAppium(); // Start appium server // create appium driver instance DesiredCapabilities capabilities = DesiredCapabilities.android(); capabilities.setCapability("deviceName", deviceName); capabilities.setCapability("platformName", "android"); capabilities.setCapability(CapabilityType.VERSION, osVersion); capabilities.setCapability("app", appPath); capabilities.setCapability("udid", deviceId); this.driver = new AndroidDriver(new URL("http://127.0.0.1:"+port+"/wd/hub"),capabilities); } catch(Exception e){ e.printStackTrace(); } } public void destroyDriver() { driver.quit(); try { deviceConf.stopADB(); } catch (Exception e) { e.printStackTrace(); } } public void start(){ if (t == null){ t = new Thread(this); t.start (); } }
public void run(){ } public <c> void execute() { Class<?> c; try { int startMethod = 0; String className = this.getClass().toString(); System.out.println("class : "+className); className = className.replace("class ", ""); System.out.println("class : "+className); // Get extended class name c = Class.forName(className); System.out.println("class : "+c); // Get start method Method[] m = c.getMethods(); System.out.println("methods: "+m.length); for(int i=0;i<m.length;i++) { //System.out.println("methods: "+m[i]); if(m[i].toString().contains("start")){ startMethod=i; break; } } System.out.println("methods: "+m[startMethod]); // get constructor Constructor<?> cons = c.getConstructor(Integer.TYPE); System.out.println("cons: "+cons); System.out.println("deviceCount: "+deviceCount); // Create array of objects Object obj = Array.newInstance(c, deviceCount); for (int i = 0; i < deviceCount; i++) { Object val = cons.newInstance(i); Array.set(obj, i, val); }
for (int i = 0; i < deviceCount; i++) { Object val = Array.get(obj, i); m[startMethod].invoke(val); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
}
Hi,
I was trying out parallel or sequential execution on multiple android devices, but my scripts always ran on only one device. I finally figured out that I needed to provide unique values for - Appium Port, Bootstrap Port and Device ID (UDID) to make it work.
I have written a post about this, which you can check out below. It uses Java Thread and Runnable interface to run the test in parallel in 2 devices. The logic for parallel execution can be anything, but as mentioned above the important thing is that we pass different values for Appium Port, Bootstrap Port, Device ID (not Device Name) and Chrome Driver Port (if using Chrome Browser)
Code and steps looks good. are you giving unique address and port details in node configuration file.? how are you executing scripts ? Use testNG parallel execution.
Kindly check or share the node configuration details.
Thanks
Ravi
Node File 1
{
âcapabilitiesâ:
[
{
âbrowserNameâ: âAndroidâ,
âversionâ:â6.0.0â,
âmaxInstancesâ: 3,
âplatformâ:âANDROIDâ,
âdeviceNameâ:â192.168.116.102:5555â
}],
"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
}
}
Node File 2
{
âcapabilitiesâ:
[
{
âbrowserNameâ: âAndroidâ,
âversionâ:â4.4.4â,
âmaxInstancesâ: 3,
âplatformâ:âANDROIDâ,
âdeviceNameâ:â192.168.116.101:5555â
}],
"configuration":
{
ânodeTimeoutâ:120,
âportâ:4724,
âhubPortâ:4444,
âproxyâ: âorg.openqa.grid.selenium.proxy.DefaultRemoteProxyâ,
âurlâ:âhttp://127.0.0.1:4724/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
}
}
Please share any working demo project with me⌠I am stuck in it since last month
Thanks @vaibhav_khachane for sharing. I will look into it and get back to you.
Please drop your mail. I will share.
Thanks
Ravi
Thanks for quick response
My Email Id:- [email protected]
@ravikr42 you may be interested in this https://github.com/saikrishna321/AppiumTestDistribution
Please share any basic example like launch application on multiple device using selenium grid. I need it.
@vaibhav_khachane pls take a look at the sample project, https://github.com/saikrishna321/PageObjectPatternAppium
Just connect two android devices to your machine. Clone the project and navigate to the root of the project and run the command mvn clean -Dtest=Runner test
You should see the tests running in parallel
Hi Thanks ,I am going through project and import it into eclipse and change the config file. and try to run the project, but getting an error. I am using java with TestNG for my project. I am begginer in Mobile Automation testing . So please share with me step by step process if possible.
Please navigate to the folder where the pom.xml is located and pls use Intellji as IDE
I am still stuck in this issue .please help me
I am having the same issue. My node register json file1
{
âcapabilitiesâ: [{
âbrowserNameâ: âChromeâ,
âudidâ: â4d006312964a40fdâ,
âversionâ: â5.0.1â,
âmaxInstancesâ: 1,
âplatformâ: âANDROIDâ
}
],
âconfigurationâ: {
âcleanUpCycleâ: 2000,
âtimeoutâ: 3000,
âproxyâ: âorg.openqa.grid.selenium.proxy.DefaultRemoteProxyâ,
âurlâ: âhttp://127.0.0.1:4723/wd/hubâ,
âhostâ: â127.0.0.1â,
âportâ: 4723,
âmaxSessionâ: 10,
âregisterâ: true,
âregisterCycleâ: 5000,
âhubPortâ: 4444,
âhubHostâ: â127.0.0.1â
}
}
json file 2:
{
âcapabilitiesâ: [{
âbrowserNameâ: âChromeâ,
âudidâ: â5e845882â,
âversionâ: â6.0.1â,
âmaxInstancesâ: 1,
âplatformâ: âANDROIDâ
}
],
âconfigurationâ: {
âcleanUpCycleâ: 2000,
âtimeoutâ: 3000,
âproxyâ: âorg.openqa.grid.selenium.proxy.DefaultRemoteProxyâ,
âurlâ: âhttp://127.0.0.1:4729/wd/hubâ,
âhostâ: â127.0.0.1â,
âportâ: 4729,
âmaxSessionâ: 10,
âregisterâ: true,
âregisterCycleâ: 5000,
âhubPortâ: 4444,
âhubHostâ: â127.0.0.1â
}
}
i used following commands to register node:
node.exe node_modules\appium\bin\appium.js --nodeconfig C:\Users\srajagop\Desktop\grid\samsung_node.json -p 4723 -bp 2251 -U 4d006312964a40fd --chromedriver-port 2351
node.exe node_modules\appium\bin\appium.js --nodeconfig C:\Users\srajagop\Desktop\grid\nexus_node.json -p 4729 -bp 2251 -U 5e845882 --chromedriver-port 2352
using testng for parallel testing
Watch this video : https://youtu.be/vXpskMkytD8
You can open two different terminals, the first you leave with the default host and port witch is 0.0.0.0 4723, start running your test on it.
go to the other terminal and run command: appium -a 127.0.0.1 -p 4725
(or any other host and port you like) and run the second one.
Iâm working with emulators and it works for me.