Automate browser and native app - android

I want to use Appium to automate the scenario below on Android
First open a web page in Chrome. The web page contains a
registration form
Fill the form then click the submit button
The submit button open my native app via the uri (the same behavior
as we open the Google Play by clicking on a link market://...)
Finally interact with the app
I could make the automation for step 1 to 3 but stucked at step 4.
Is this possible with Appium? Is there any other testing framework which can automate the scenario like that?

It seems that the problem is related to changing from the webview context to the native app's own context. This is done in Java by using the command driver.context("NATIVE_APP");
To view all available contexts use driver.getContextHandles();, which returns a Set<String> with all available contexts.
Native context is always called "NATIVE_APP" and webviews usually are indexed as "WEBVIEW_0", "WEBVIEW_1" and so on.
All interactions to the app that are not related to a webview directly, will usually need to be done while in "NATIVE_APP" context.

It seem you have timeout exception, just change your code from driver.find_element(By.id("my_button_id"))
to
WebDriverWait(driver, 10).until(lambda:driver.find_element(By.id("my_button_id")))

Related

Can't switch between two mobile drivers for Chrome and other react native app

Good afternoon,
I am trying to automate the following scenario on Android using Kotlin:
Start Appium driver and open React native app (driver1)
Perform some actions on React native app
Create driver2 with chrome options to open chrome and paste deep link there
Deeplink leads to the app automatically (but I suppose the current session uses driver2, not driver1 here)
I need to continue using the app further with driver1 however it is not working and not finding the element which is on the next screen where my deep link leaded me
I am using Appium v1,21,0
Language - Kotlin
App - React-native
I tried the following solutions:
getContext - does not work as this is not a hybrid app but two different mobile apps
startActivity - it actually launching the app from scratch, not continuing (i need to be on a particular screen after deep-link navigation, can't navigate anywhere else flow won't work)
startActivityCommand - this one did not work for me at all (it ignores the command but maybe anyone can give an example of its usage as I might use it wrong)
driver.switchTo().window("0") - did not work
assign to driver2(web) new capabilities - does not work as it is already defined so we cant change it
sessionId - I am not sure how it works exactly yet, but I tried to find a way to assign a driver to the particular session-id and was not successful (looks like AppiumDriver methods do not support it)
Would appreciate any ideas, links, or sources that can help archive the above
Good Day!
Solution that helped:
#AndroidFindBy(xpath = "//android.widget.EditText[#resource-id=\"com.android.chrome:id/search_box_text\"]")
#iOSXCUITFindBy(id = "")
lateinit var chromeURL: MobileElement
var deeplink = <your deeplink>
driver.activateApp("com.android.chrome")
chromeURL.sendKeys(deepLink)
var clickOnDeepLink = driver.findElements(MobileBy.AndroidUIAutomator("new UiSelector().text(\"$deepLink\")"))
clickOnDeepLink[0].click() //here we could not use Keys.ENTER so we just click on the element first in the list - default android google chrome behaviour
So there is no need for several drivers - same driver instance is fine

How to test Deferred Deep Linking with AppsFlyer?

I'm integrating AppsFlyer with Android Native Application. And I want to use Deferred Deep Linking, when user click landing page ads and download the app and upon first app open the user lands directly on the activity I want.
Link docs: https://support.appsflyer.com/hc/en-us/articles/207032096-Deferred-Deep-Linking-Getting-the-Conversion-Data
But I have not found a way to check that my code is running correctly.
Please help me with this problem
What was working for me is:
Add physical device as a test device in AppsFlyer (here's how to do it)
Enable Debug Mode in AppDelegate.swift in didFinishLaunchingWithOptions
AppsFlyerTracker.shared().isDebug = true
Add AppsFlyer methods in your AppDelegate.swift (as per article)
Remove app (or test build) from physical device
Open Deep Link from physical device, you will be redirected to App Store. Don't install app from the App Store!!! (just close it)
Install app via XCode
After it, on a first install it will call onConversionDataReceived method and the rest staff.
You're going to have to implement the onInstallConversionDataLoaded listener:
public interface AppsFlyerConversionListener {
void onInstallConversionDataLoaded(Map<String,String> conversionData);
void onInstallConversionFailure(String errorMessage);
}
This will return a map of all the parameters on the link that you clicked.
The parameter you need to pay attention to is the af_dp parameter.
This parameter should contain the URI scheme of the activity you want to route your users to. Make sure that you have set up this URI scheme properly in the manifest.
To create a tracking link you can use Link Management. It doesn't matter if it's a single platform link or a OneLink, as long as you have the af_dp parameter on the link, that parameter (along with all other parameters on the link) will be part of the response.
If you're still facing issues, feel free to reach out to support#appsflyer.com.

Mobile testing with appium/Android - can't access webelements in the mobile app

Android mobile app testing with appiumv1.6.5 and java-client-3.2.0.
I can't access webelements in the mobile app home page. Home page is loaded, but there is an other window loaded saying "session is expired". No way to move that new window.
driver.switchTo().activeElement()/driver.switchTo().alert() gives:
org.openqa.selenium.WebDriverException: Method has not yet been implemented
I checked the page source, when I call driver.getPageSource(), it is hanging. I have to close mobile app through the device to move to the next step in the code.
With new UI Automator you don't need to use switchTo method. Make you sure that you device's Android System WebView is up to date else you need to update through Google PlayStore. Once you update Android System WebView and try capture the elements using UIAutomator as you do normally and should see the elements inside webview in the UIAutomator's screenshot.

Is there a way to check for direct update from native - IBM Mobilefirst?

I am trying to implement Direct Update in my app. In my app, I have display the native page as home page.
So from wlcommoninit(), I am calling WL.Nativepage.show(), to move to native page.
Before moving to native page, I want my app to check for direct update. So before calling WL.Nativepage.show(), I have called the below API,
WL.Client.CheckforDirectUpdate()
It is working like this,
App loads
Check for direct update
Direct update available - so default dialog shows to update the app
In the background, the app is moving to native page.
I want the app to move to the home page only if there is no update available,
so in onSuccess method of WL.Client.CheckforDirectUpdate(), I am passing to the native page.
In some cases the app works perfect, but some times once the update dialog displays to the user the app is moving to the native page and the dialog disappears again I have to return to any hybrid page to access the update dialog.
So I would like to check for notification in the home page [Native Page]. Is there any equivalent native[Android and IPhone] Mobilefirst API available for direct update?
There is no such API. However perhaps you could use the SendAction API to invoke JS code and return the result. I don't think this will play out as expected, though: https://www.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.dev.doc/devref/c_action_sender.html

Phonegap / Cordova ChildBrowser won't run Twitter web intents (SSL?)

I'm trying to integrate Twitter sharing functionality into my Android PhoneGap application, and rather than re-implement the controls to shorten URLs and track tweet length, I thought I'd use their premade web intents at https://twitter.com/intent/...
So I'm trying to launch a URL like https://twitter.com/intent/tweet?text=Hello in a ChildBrowser window, so that I can let Twitter's interface take over. The user could sign in with their credentials, and once they're signed in, the text from the URL params would appear in the Tweet box.
It won't work. When I use http://twitter.com/intent/... instead of https://twitter.com/intent/... , ChildBrowser displays the sign-in screen, but as soon as the user submits their credentials, the screen goes white. I suspect this is because Twitter switches over to HTTPS.
I confirmed that this was the case by trying a simple window.open instead of window.plugins.childBrowser.showWebPage. I have no problems with HTTP / HTTPS when using the native browser on Android. However, the native browser prompts me to accept an unverified security certificate. I suspect this is the problem with ChildBrowser - it doesn't know how to handle that prompt.
Using the native browser popover simply isn't an option: the user needs to be able to exit the process after hitting 'Tweet' or 'Follow', etc., but the 'back' button on the Android device simply moves the history one step backward to the POST action for their intent. Then, it re-launches the app from scratch, instead of returning you to the original state.
How can I configure ChildBrowser / my Android Phonegap application to override SSL issues on Twitter, so that I can run web intents in Childbrowser?
The relevant code is:
base="https://twitter.com/intent/tweet?text=";
URL=base+encodeURIComponent("it works!");
// works, but asks to accept a certificate
window.open(URL);
// blank white page
window.plugins.childBrowser.showWebPage(URL, { showLocationBar: true });
My cordova.xml file has whitelists configured as such:
<access origin="http://127.0.0.1*"/> <!-- allow local pages -->
...which I don't suspect should be a problem. However, a basic test of swapping origin=".*" yielded no change in behaviour.
I've also examined the HTTP and HTTPS headers for the Twitter intent landing pages. There doesn't appear to be anything out of line - they're identical, except for the Strict-Transport-Security header for HTTPS, which works elsewhere (e.g. Github).
Please help!
The ChildBrowser is not bound by the whitelist. The whitelist is only used to keep the main PhoneGap app from running code outside of trusted domains.
I'm confident if you go get the latest ChildBrowser code from Android you won't have run into this problem anymore. We've made some changes recently that make it more robust.
Also, Libby has a good tutorial integrating Twitter and the ChildBrowser.
http://www.mobiledevelopersolutions.com/home/start/twominutetutorials/tmt5p1

Categories

Resources