Friday, April 07, 2017

How to do automation testing using Selenium Deriver for Mobile device i.e. Android or Hybride

Step 1:- Download this selendroid-standalone-0.17.0-with-dependencies.jar from below given url
https://github.com/selendroid/selendroid/releases/download/0.17.0/selendroid-standalone-0.17.0-with-dependencies.jar
and use this command to start it on port 4444 (Use your desire port to start this jar)

C:\Software\Mobile_Automation>java -jar selendroid-standalone-0.17.0-with-dependencies.jar -port 4444
Step 2:- Run AVD Manager.exe kept at location
C:\Users\Test\AppData\Local\Android\sdk
Image4
and Start Emulator which we want to run
Step 3:- Once Emulator is start make sure to confirm that we are able to see this page on the screen along with Emulator name
http://localhost:4444/wd/hub/status

Step 5:- Run following below class and see the result
package io.selendroid.demo.mobileweb;
import io.selendroid.client.SelendroidDriver;
import io.selendroid.common.SelendroidCapabilities;
import io.selendroid.standalone.SelendroidConfiguration;
import io.selendroid.standalone.SelendroidLauncher;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
public class MobileWebTest {
private SelendroidLauncher selendroidServer = null;
private WebDriver driver = null;
@Test
public void shouldSearchWithEbay() {

try {

URL url = new URL("http://localhost:4444/wd/hub");
DesiredCapabilities desiredCapabilities = SelendroidCapabilities.android();
WebDriver driver = new SelendroidDriver(url,desiredCapabilities);

// And now use this to visit ebay
driver.get("http://www.google.in");
// Find the text input element by its id
WebElement element = driver.findElement(By.id("lst-ib"));
// Enter something to search for
element.sendKeys("shdhumale.wordpress.com");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Reached here" );
driver.quit();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Image1Image2Image3

No comments: