How to automate mobile version pages in android app using appium driver - appium

I am testing an android app using appium.
In that few links of app redirect to mobile version pages.
I googled but didn't get proper solution, I wish to know how to locate the elements and perform actions on mobile version pages.
Thanks in Advance....!

It seems you're looking to find information about automating tests for a Hybrid app (Native app that includes WebViews with mobile web content).
The Appium API Reference is a great resource to get basic info about hybrid app automation: http://appium.io/slate/en/master/?java#automating-hybrid-apps
The main difference when working with WebViews is that you'll need to change the context of the webdriver to match with the WebView you wish to inspect or automate. Also note that once going back to inspecting and automating the actual native app, the context should be set back to NATIVE_APP.
// java
// assuming we have a set of capabilities
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextNames); //prints out something like NATIVE_APP \n WEBVIEW_1
}
driver.context(contextNames.toArray()[1]); // set context to WEBVIEW_1
//do some web testing
String myText = driver.findElement(By.cssSelector(".green_button")).click();
driver.context("NATIVE_APP");
// do more native testing if we want
driver.quit();

Related

how to interact with elements embedded in android.webkit.WebView using uiautomator

am working on android automation using appium & robot framework. for this am using robot's appiumlibrary. so i want to automate facebook login secenario in my application, but the problem is the fb login page on app is embedded to an webview. however in uiautomatorviewer able to focusand and find elements, but while running the scripts it throws an error element not found.
what do i need to do in this scenario. i tried to fetch and then switch to context but there was no new or related context available. NATIVE_APP was the only one available.
To see the webview context using driver.context() method WebView debugging should be enabled; developer must enable ‘setWebContentsDebuggingEnabled’ flag in the WebView class. This flag enables debugging of web contents (HTML / CSS / JavaScript) loaded into any WebViews of app. Once this is done driver.context() method will return native and webview both contexts.
Set<String> availableContexts = driver.getContextHandles();
System.out.println("Total No of Context Found = "+ availableContexts.size());
for(String context : availableContexts) {
if(context.contains("WEBVIEW")){
System.out.println("Context Name is " + context);
driver.context(context);
break;
}
}
Note - You cannot do this for third party app like facebook because you may not rebuild that app with webview debugger enabled.

Web service for deep linking

This is my first time create an ios application that required deep linking. I need to create a web service for my custom url scheme for ios in order to publish it online. Please give some pointer on regarding which web service i should use or is there an alternative way to create a deep linking for custom url scheme for iOS. Thanks.
You can do it yourself with any server platform - Rails, PHP, Dot.Net, etc.
Here is a very simple PHP snippet. Replace "myappname" with your app's URL scheme. The param/value query is optional - you can use any other text and parse it in your App Delegate's openUrl method.
if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone OS') !== FALSE) {
// redirect
header("location: myappname://?key=value");
exit();
}
Client use-cases:
iOS Safari, your app installed - will open your app.
iOS Safari, your app not installed - Safari will complain that it cannot open the link.
Another iOS app, your app installed - will switch to your app.
Another iOS app, your app not installed - same as Safari. However, if the other app is implementing UIApplication's canOpenURL: - it may gracefully take the user to the App Store, but it's up to the other app developer.
Any other device or browser - will continue to render the page, where you can add your html including AppStore links.
If you don't want to create the server code, you can use a tool I created for this purpose. You have it here:
http://www.uppurl.com/
It's mainly a short link tool that checks for user device and give him the right url based on his devices. With this tool you don't need to write any server code and it also takes care of different devices, operating systems and browsers.
Take care of Tal answer as latest versions of Chrome has changed the way to open app and now you need to provide a link in different format, they use something like "intent://..."

how to use jquery mobile asp.net mvc 4 to download and display pdf memory stream data

I have a desktop/mobile web app that needs to display a pdf stream on the target device. I now have this working on the desktop using the jquery dialog. For mobile tho...my html View page has the following link:
View PDF
And that correctly takes me into the Controller Action:
public ActionResult PdfView(string id = "")
{
PayStubDataEntity ps = PayStubAccess.GetPayStubByID(new Guid(id), new Guid(Session["Session_Application_UserID"].ToString()));
WebHelper.SetHeadersForDownload(System.Web.HttpContext.Current.Response, "application/pdf", "PayStub.pdf", false);
MemoryStream pdfMemoryStream = SendPayStubToBrowserAsPdf(ps);
//WebHelper.SendFile(System.Web.HttpContext.Current.Response, "application/pdf", "PayStub.pdf", false, pdfMemoryStream);
return File(pdfMemoryStream, "application/pdf");
}
But nothing ever shows up on my iphone emulator (electric plum). No error messages. I am not sure where the output s/b going or how to view it? Any ideas would be most appreciated.
We have this same issue with android phones and there can be two issues going on. If the website uses ssl and the phone you are on does not accept it as a valid ssl, it will say downloading pdf in the manager, but it never completes a download.
The second issue is the file you are sending to the phone needs to be named in order to download properly to the phone.
Ex: return File(pdfMemoryStream, "application/pdf", fileDownloadName:"PayStub.pdf");
I would suggest using Google Chrome for phone emulation. When you change the settings, it will behave similarly to the phone and you can debug easily.
For example, when I set Google Chrome to the mobile phone user agent Android 4.0.2, it will download the pdf, instead of displaying within the web browser. When it does that, I know it is working locally. It also has iPhone emulation.

How to launch AppWorld from an application? [BlackBerry]

This might be a easy question but i couldn't find solution. I want to open AppWorld by clicking a button in my BB application. For example when user clicks this button Appworld will show "Facebook Application" page. Can i do this?
In Android platform this line launches GooglePlay for Facebook App. Does BlackBerry supports this kind of method?
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.facebook.katana")));
Here is a simple way to do this:
Browser.getDefaultSession().displayPage("http://appworld.blackberry.com/webstore/content/2360/?lang=en");
Above code will invoke the browser in the application and open the BlackBerry App World, I tested it in device and it's perfectly working. For now I put a Whats App messenger link, but you can customize the link according to your requirement.
You can open App World from your BB application directly using the following code. This code avoids opening the browser first.
Registry registry = Registry.getRegistry(this.getClass().getName());
Invocation invocation = new Invocation(null, null,
"net.rim.bb.appworld.Content",
false, ContentHandler.ACTION_OPEN);
invocation.setArgs(new String[] { /* app id in appworld */ });
registry.invoke(invocation);

Webservice stubs in Blackberry app

I am currently developing a proof of concept Blackberry application that uses RPC calls. I have also developed a very basic server application in .Net that simply timestamps a string sent to it and returns it to the client. I have been able to connect to the server app using a .Net client and a Java client so I am fairly confident it works correctly.
For the Blackberry client application I used Java Wireless Toolkit 2.5.2 to generate stubs for the RPC calls. I then used these calls in a basic Blackberry app to try and replicate the results of the .Net and Java clients, but it keeps throwing exceptions. I am not sure if I am using stubs correctly.
pushScreen(new HelloWorldScreen("Initiating communication"));
try {
IHelloService_Stub stub = new IHelloService_Stub();
String result = stub.hello("Hello From Blackberry");
pushScreen(new HelloWorldScreen(result));
} catch (RemoteException e) {
pushScreen(new HelloWorldScreen(e.getMessage()));
}
At present I am running everything locally. The server runs as localhost and the Blackberry app is running on the Blackberry simulator. I have used the Blackberry browser to check if I can reach the service and I can so its not the network connection that is the issue.
The exception thrown is the following:
java.io.interruptedIOException: Local connection timed out after ~ 120000
Try appending ;deviceside=true to your URL. That should eliminate the need for using the MDS simulator.
It appears that it matters where MDS is installed. I had originally installed in in C:\Program Files(x86)\Research in Motion but then read a post elsewhere that suggested installing it directly to C:\ . Amazingly, that did the trick and MDS now runs. For anyone else having MDS issues, here's a troubleshooting link:
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800792/801079/Support_-_BlackBerry_Mobile_Data_Service_Simulator_does_not_launch.html?nodeid=800979&vernum=0

Resources