For teams using Selenium to test web apps, Perfecto provides a familiar RemoteWebDriver implementation to simplify connectivity, configure capabilities, and integrate unique Perfecto features such as WindTunnel network virtualization, image and audio injection, and other advanced environment configuration controls.

Pre-requisite:

 

  1. Download the latest java jdk 32/64 bit based on your hardware from - http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html


     

  2. Download the latest Eclipse IDE for Java EE Developers – Follow the guidance how to install and setup eclipse.
    https://www.eclipse.org/downloads/


     

  3. Perfecto Plugin Installation in Eclipse.  Click on Help Menu > Install New Software.  In the install window enter http://<Your Cloud>/tools/eclipse/site (e.g. http://mobilecloud.perfectomobile.com/tools/eclipse/site ) and the latest Perfecto Plugin will be displayed as shown in the diagram below.  Check this box and install the software. After installation, restart your Eclipse as prompted. 


     

  4. Configure Eclipse Perfecto Plugin connection to your Perfecto Lab:
    Open the Preferences Window from Window > Preferences and enter your Perfecto Lab URL, user and credentials in the Eclipse Preferences window.


     

  5. View the Perfecto Plugin windows
    1. To enable the Perfecto view in Eclipse, click on menu Window > Show View > Other, as shown in the image below.


       

    2. Type in Perfecto in the view edit box as shown below and select the Perfecto Dashboard and Perfecto Lab.


       

    3. Access any mobile device in your Perfecto CQ Lab from the Launch Mobile icon, as shown below
  6. Setup Eclipse and Selenium
    1. Download and Install Selenium Java client – You will need to client for execution on your local browser. Download Selenium Java client http://docs.seleniumhq.org/download/
    2. Extract the .zip file.

       

  7. Install Chrome Driver - https://sites.google.com/a/chromium.org/chromedriver/getting-started

Flow – Execute your local selenium test on the cloud

  1. Open Eclipse and create new Java project


     

  2. Give your project a name “PerfectoSeleniumDemo”


     

  3. Create a new package – right click on the project and select add > Package. Give your Package name “seleniumDemo” and click on Finish button.


     

  4. Create a new class – right click on the package add > class.  Give your class name “Test1” and check “public static void main”.


     

  5. Add external Jars to Java build path – Right click on the project > Properties and select Java Build path.


     

  6. Add external Jar files – Add all the Selenium client Jar file and the libs from the Selenium client folder (#6 in the pre-requisite). 


     

  7. Paste the following code to the Test1.java class

package seleniumDemo;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class FirstTestCase {

public static void main(String[] args) throws InterruptedException, MalformedURLException {

// This code will run the test on your local Chrome browser
System.setProperty("webdriver.chrome.driver","C:/chromedriver_win32/chromedriver.exe");
DesiredCapabilities capabilities=DesiredCapabilities.chrome();
capabilities.setCapability("marionette", true);
RemoteWebDriver driver = new ChromeDriver();

//This code will run the test on Perfecto Mobile Cloud
/*
String browserName = "mobileOS";
DesiredCapabilities capabilities = new DesiredCapabilities(browserName, "", Platform.ANY);
// Enter your cloud URL       
String host = "<Your Cloud>.perfectomobile.com";
//Enter your user and password
capabilities.setCapability("user", "<Your User>");
capabilities.setCapability("password", "<Your Password>");

//The test will run on any Android available device
capabilities.setCapability("platformName", "Android");

// Name your script
capabilities.setCapability("scriptName", "FirstTestCase");

RemoteWebDriver driver = new RemoteWebDriver(new URL("https://" + host + "/nexperience/perfectomobile/wd/hub"), capabilities);
*/

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

try {
//Launch the chrome browser and navigate to www.google.com
driver.get("http://www.google.com");

// Print a Log In message to the screen
System.out.println("Successfully opened the website www.google.com");

//Wait for 3 Sec
Thread.sleep(3000);

//Search Perfecto Mobile
driver.findElement(By.id("lst-ib")).sendKeys("Perfecto Mobile\n");
// Click on PErfecto Mobile and navigate to the web-site.
driver.findElement(By.linkText("Perfecto Mobile")).click();;

//Wait for 15 Sec
Thread.sleep(15000);
}

finally {
// Close the driver
driver.quit();
}
}

  1. Update the chrome driver path to the location that you save the driver (#7 in the pre-requisite).

  2. “Run” the test as Java Application – The test will run on your local Chrome Browser –
    1. Will navigate to www.google.com
    2. Search for “Perfecto Mobile”
    3. Click the link to Perfecto Mobile site and navigate to www.perfectomobile.com
  3. Run the same test on real mobile device on the cloud:
  1. Comment the following line

// This code will run the test on your local Chrome browser
System.setProperty("webdriver.chrome.driver","C:/chromedriver_win32/chromedriver.exe");
DesiredCapabilities capabilities=DesiredCapabilities.chrome();
capabilities.setCapability("marionette", true);
RemoteWebDriver driver = new ChromeDriver();

    1. Un comment the following lines – Use the relevant capabilities. Update your cloud URL, User name and password.

 

String browserName = "mobileOS";
DesiredCapabilities capabilities = new DesiredCapabilities(browserName, "", Platform.ANY);
// Enter your cloud URL       
String host = "<Your Cloud>.perfectomobile.com";
//Enter your user and password
capabilities.setCapability("user", "<Your User>");
capabilities.setCapability("password", "<Your Password>");

//The test will run on any Android available device
capabilities.setCapability("platformName", "Android");

// Name your script
capabilities.setCapability("scriptName", "FirstTestCase");

RemoteWebDriver driver = new RemoteWebDriver(new URL("https://" + host + "/nexperience/perfectomobile/wd/hub"), capabilities);

  1. “Run” the test again – Now the same test will run on remote real devices on Perfecto Cloud.

 

Congratulations!! You executed your Selenium test on the cloud – It is easy and transparent to take your Selenium tests that run on local browsers and with few simple capabilities changes run those tests on the cloud.