How to inspect element:
step-1 get source code of your mobile application from your development team.
step-2 open the chrome browser from command prompt by type this command
chrome.exe --disable-web-security
step-3 find the index.html file from the mobile source code which is given by dev team.
step-4 now copy the path for index.html and paste the url in chrome. For example if you copied the
mobile sournce code in desktop then the url will be C://User/Desktop/app/www/index.html
step-5 now press F12 on chrome. Then click emulate.
step-6 Refresh/reload your browser.
step-7 Now you will see your application as like your mobile on the chrome browser.
step-8 You can now inspect element by chrome developer tool as like the web applications.
Test script:
import io.appium.java_client.AndroidKeyCode;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.TouchAction;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class SimpleTest {
private AppiumDriver driver;
public WebDriver driverNew;
@BeforeClass
public void setUp(){
// set up appium
File app = new File("apppath");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
// capabilities.setCapability("automationName", "Android");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName","Android");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "apppackage");
capabilities.setCapability("appActivity", "appactivity");
try {
//driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@AfterClass
public void tearDown() throws Exception {
//driver.quit();
}
@Test
public void addContact() throws InterruptedException{
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName);
if (contextName.contains("WEBVIEW")){
driver.context(contextName);
}
}
driver.findElement(By.id("the id which you inspect by chrome browser")).click();
}
}
step-1 get source code of your mobile application from your development team.
step-2 open the chrome browser from command prompt by type this command
chrome.exe --disable-web-security
step-3 find the index.html file from the mobile source code which is given by dev team.
step-4 now copy the path for index.html and paste the url in chrome. For example if you copied the
mobile sournce code in desktop then the url will be C://User/Desktop/app/www/index.html
step-5 now press F12 on chrome. Then click emulate.
step-6 Refresh/reload your browser.
step-7 Now you will see your application as like your mobile on the chrome browser.
step-8 You can now inspect element by chrome developer tool as like the web applications.
Test script:
import io.appium.java_client.AndroidKeyCode;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.TouchAction;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class SimpleTest {
private AppiumDriver driver;
public WebDriver driverNew;
@BeforeClass
public void setUp(){
// set up appium
File app = new File("apppath");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
// capabilities.setCapability("automationName", "Android");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName","Android");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "apppackage");
capabilities.setCapability("appActivity", "appactivity");
try {
//driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@AfterClass
public void tearDown() throws Exception {
//driver.quit();
}
@Test
public void addContact() throws InterruptedException{
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName);
if (contextName.contains("WEBVIEW")){
driver.context(contextName);
}
}
driver.findElement(By.id("the id which you inspect by chrome browser")).click();
}
}
thank very much
ReplyDeleteYour welcome @LOKESH L R
DeleteHi sir,
ReplyDeleteMy apps not runs on emulator samsung s3. well it run on device. but when I tried to login with valid credentials in emulator it not works. Please help me sir.
Thanks for sharing this information.It was very nice blog to learn about Appium .
ReplyDeletehttp://thecreatingexperts.com/appium-training-in-chennai/
This comment has been removed by the author.
ReplyDeleteAppium training in Chennai
ReplyDeleteWe provide best appium training in Chennai with real time scenarios. For real time training reach us 8122241286 and become experts in appium.
Appium training in chennai