Mobile Hybrid app demo

HI Friends,

I am new to appium.

Please help me how to do Hybrid app automation using appium.
Please provide simple demo(example).

Thank’Q
JO

Hi @jo

Here a lot of samples: https://github.com/appium/java-workshop/tree/master/src/test/java/io/appium/test/workshop
The sample with a hybrid app is here too.

Thank’Q Sergey

How to focus & Send data in to textbox in hybrid app. Please help me.

Html:
input autocorrect=“off” spellcheck=“false” id=“first_name” data-id=“first_name” data-active=“true” placeholder=“Joseph” type=“text” data-type=“search” maxlength=“50” class=“ui-input-text ui-body-a”

Code:
System.out.println("first name is "+ contextNames);

driver1.findElement(By.cssSelector("input[id=id_firstName]")).click();
Thread.sleep(10000);
WebElement search = driver1.findElement(By.cssSelector("input[id=id_firstName]"));//#id_firstName  
  Thread.sleep(10000);
  search.sendKeys("textname");

Iam getting error:
org.openqa.selenium.UnsupportedCommandException: Invalid locator strategy: css selector

@jo

Firstly you should switch to web view like that:

((AndroidDriver) driver).context(“WEBVIEW_com.yourcompany.package”)

((IOSDriver) driver).context(“WEBVIEW_0”);

Hi
Please check my code

AppiumDriver driver1;

public void register() throws Exception
{
driver1.findElementByName(“Register”).click(); // Access as guest
Thread.sleep(1000);
Set contextNames= driver1.getContextHandles();
System.out.println("2 " + contextNames);

Thread.sleep(5000);
WebElement search =  driver1.findElementByCssSelector("input[id=id_firstName]"); 
Thread.sleep(5000);
search.sendKeys("Automation");

}

Error:
2 [NATIVE_APP, WEBVIEW_com.popcorn.csr]
FAILED: alreadyRegistered
org.openqa.selenium.UnsupportedCommandException: Invalid locator strategy: css selector (WARNING: The server did not provide any stacktrace information)

Thank’Q

Have you done

driver.context(“WEBVIEW_com.popcorn.csr”);

before code above? It happens at WEBVIEW? If it happens when driver is switched to WEBVIEW it is probably something wrong with Appium server or chromedriver.

Thank’Q for ur replies

Please check my complete code…

My Crome: Version 39.0.2171.95
Appium: 1.2.4.1

AppiumDriver driver1;
@BeforeSuite
public void setUp() throws MalformedURLException, InterruptedException
{
System.out.println(“Installing the csr app in device…”);
File app = new File(“C://files/csrapp.apk”);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);
capabilities.setCapability(“deviceName”,“00771695054e2b67”); capabilities.setCapability(“platformVersion”, “5.0”);
capabilities.setCapability(“platformName”, “Android”);
capabilities.setCapability(“app”, app.getAbsolutePath());
capabilities.setCapability(“app-package”, “com.popcorn.csr”);
capabilities.setCapability(“app-activity”, “com.popcorn.csr.CSR”);
driver1= new AppiumDriver( new URL(“http://127.0.0.1:4723/wd/hub”), capabilities) ;

Set<String> contextNames= driver1.getContextHandles();
for(final String contextName : contextNames)
	System.out.println("Type of app : " + contextName);
Thread.sleep(3000); 	

}

@Test(priority=1)
public void alreadyRegistered() throws Exception
{

System.out.println("Test priority 1 Registration started");
driver1.findElementByName("Register").click();
Thread.sleep(2000);
driver1.context("WEBVIEW_com.popcorn.csr");
System.out.println("Enter the First Name ");
Thread.sleep(2000);
WebElement fname = driver1.findElementByCssSelector("input[id=id_firstName]");  
  Thread.sleep(2000);
  fname.sendKeys("John Smith"); 

}

Error:
Installing the csr app in device…
Type of app : NATIVE_APP
Type of app : WEBVIEW_com.popcorn.csr
Test priority 1 Registration started

FAILED: alreadyRegistered

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (Original error: Did not get session redirect from Chromedriver) (WARNING: The server did not provide any stacktrace information)

Aha…

This is an issue of chromedriver.
The relevant conversation: Did not get session redirect from Chromedriver (here woraround is described)
The issue https://code.google.com/p/chromedriver/issues/detail?id=845 is already fixed. You have to replace chromedriver at appium directory (its version 2.10) to new chromedriver (2.13). You can get it here: http://chromedriver.storage.googleapis.com/index.html?path=2.13/

Actually Appuum will use choremedriver 2.13 when 1.3.5 will be released.

Thank’Q so much SergeyTichomirov,

Its working fine. I am able to doing the Hybrid Mobile app automation.
Once again Thank’Q so much… :smile:

Hi
I am facing one more problem in hybrid app

skip the tour: html code

div class=“link-text”>Skip the tour

Code:

AppiumDriver driver1;
@BeforeSuite
public void setUp() throws MalformedURLException, InterruptedException
{
File app = new File(“C://files/Gilead/Touchbase-v1.0.apk”);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);
capabilities.setCapability(“deviceName”,“HT35JW912039”);
capabilities.setCapability(“platformVersion”, “4.4.3”);
capabilities.setCapability(“platformName”, “Android”);
capabilities.setCapability(“app”, app.getAbsolutePath());
capabilities.setCapability(“app-package”, “com.gilead.touchbase”);
capabilities.setCapability(“app-activity”, “TouchBase”);
driver1= new AppiumDriver( new URL(“http://127.0.0.1:4723/wd/hub”), capabilities) ;

  	Set<String> contextNames= driver1.getContextHandles();
  	for(final String contextName : contextNames)
  		System.out.println("App type:"+contextName);
	Thread.sleep(3000);
  }
  
//Login
	@Test(priority=1)
	public void Login() throws InterruptedException
	{	
		Thread.sleep(40000);
		driver1.context("WEBVIEW_com.gilead.touchbase");
        Thread.sleep(2000);
        try
        {
        	Thread.sleep(2000);
		//driver1.findElementByName("Skip the tour").click();
	     driver1.findElementByCssSelector("#tutorials > div > div > div > a").click();
		Thread.sleep(2000);
	//	driver1.findElementByXPath("//*[@id='tutorials']/div/div/div").click();
        }
        catch(Exception e)
        {
        	System.out.println("Excepection  --> "+e);	
        }
	}

Appium Error:
App type:NATIVE_APP
App type:WEBVIEW_com.gilead.touchbase
Current context is: NATIVE_APP
Excepection --> org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 222 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘2.43.1’, revision: ‘5163bce’, time: ‘2014-09-10 16:27:58’
System info: host: ‘jyothisateesh’, ip: ‘192.168.1.36’, os.name: ‘Windows 8’, os.arch: ‘amd64’, os.version: ‘6.2’, java.version: ‘1.7.0_51’
Session ID: 31b22ef6-52c2-4e58-b6a1-7a68cf9c1e34
Driver info: io.appium.java_client.AppiumDriver
Capabilities [{platformVersion=4.4.3, app=C:\files\Gilead\Touchbase-v1.0.apk, platform=LINUX, databaseEnabled=false, javascriptEnabled=true, platformName=Android, deviceName=HT35JW912039, browserName=, app-package=com.gilead.touchbase, webStorageEnabled=false, networkConnectionEnabled=true, app-activity=TouchBase, desired={platformVersion=4.4.3, app=C:\files\Gilead\Touchbase-v1.0.apk, deviceName=HT35JW912039, platformName=Android, browserName=, app-package=com.gilead.touchbase, app-activity=TouchBase}, locationContextEnabled=false, warnings={}, takesScreenshot=true}]
PASSED: Login

please help me

please help me (Used the JQuery Mobile)

@jo
There is not enough information which can help to solve the problem. I think that there is wrong locator. Is it possible that your webview has iframes?

Hi
@SergeyTichomirov can u tell me which information is required?
How i can place mobile app in iframe? We don’t have any webapp.

I am UIAutimatorviewer
FrameLayout > LinearLayout > FrameLayout > LinearLayout > Web View > View > List View > View available.

I need to tap on Me test(link) in the page.

HTML Code:
li onclick=“me()” class=“ui-li ui-li-static ui-btn-up-c ui-last-child”
h1 class=“ui-li-heading”>Me

Please help me.

Ok. Sometimes it is possible that WebView contant is partially located inside iframe’s. A have seen 1-2 hybrid apps like that.

Ok. Is it the target element? Let me see the full HTML fragment which contains

and the target element which you wish to click.
It would be cool if I could see parents of

@SergeyTichomirov So now what i do?

Hi,

Can anyone help in clicking the element by CssSelector. I am automating the app which is Hybrid and trying to click the element by CssSelector. Output is, nothing is happening and the Appium is getting timed out after the implicit time I have mentioned and it is not clicking the element.

I have switched to WebView context and trying to click the element as below,

driver.manage().timeouts().implicitlyWait(300, TimeUnit.SECONDS); // 300 seconds implicit wait

Set contextNames2 = driver.getContextHandles();
for (String contextName : contextNames2) {
if (contextName.contains(“WEBVIEW”)){
System.out.println(contextName);
//driver.switchTo().(contextName);
driver.context(contextName);
}
}

List smartCardIn = driver.findElementsByCssSelector("[data-ng-click=‘smartCardIn()’]");
System.out.println("Element displayed --> " + smartCardIn.size()); // This line is not executing
smartCardIn.get(0).click();

find element by css selector is not getting triggered and the script is stopped after 300 seconds implicit wait. Error is displayed as timedout error.

Please help.

C.S Harsha

I have my index.html inside www/view and not in the directory www thus the appium could not find the inex.html how to point my index.html to appium?