Appium Android Cannot Detect Alert - appium

We are writing automated tests using Appium and C#. We have a test where we need to verify the text that is displayed in an alert, the alert is being generated by the app not the operating system.
We are trying to write the code in a cross platform manner so that the same test can be used to test the app on iOS and Android.
The code below works for iOS:
AppiumExecutor.GetWaitDriver().Until(d =>
{
try
{
return d.SwitchTo().Alert().Text.Equals(expectedText);
}
catch (NoAlertPresentException)
{
return false;
}
});
When using the same code for Android we get a message "No alert is present on the screen"even though the screenshot that accompanies the message does show the alert we are testing for.
Is there a reason this code doesn't work for Android?
Is it because our app is generating the alert? (It is still using standard Android APIs to do this)
What alternatives do we have to run the same test on Android?

Related

location.pathname on iOS

I use this js condition to run some code if a certain page is visited.
if (location.pathname == '/members/') {
console.log("members page reached")
}
It works in all browsers on Windows, Android or Linux.
But the code somehow doesn't run on iOS devices. Is there something about location.pathname on iOS?
How can I get it to work on iOS device?

Closing Smart App Banner in iOS Appium test

I'm testing a website using Appium for iOS. The site has an associated app and uses Apple's Smart App Banners to promote the app. I'd like to test for the presence of the banner and close it at the beginning of my Appium test, but the banner doesn't appear to exist in the DOM. Is there any way to do this, short of mousing around with a pixel location?
Try to switch to native context:
driver.context("NATIVE_APP");
and check if it contains banner, for quick investigation you can print to console result of driver.getPageSource()

How to perform UITesting on an app I don't have source code for?

I have been reading up on Apple's new and improved XCTest/UITesting frameworks and I have some questions as a Android developer. In android, to launch an app that I do not have the source code for to run UiAutomator I would simply use
#Before
public void setup() {
//Init UiDevice instance
Instrumentation mInstrumentation = InstrumentationRegistry.getInstrumentation();
mDevice = UiDevice.getInstance(mInstrumentation);
//start from home screen on each new test
mDevice.pressHome();
//wait for launcher
final String launcherPackage = mDevice.getLauncherPackageName();
assertThat(launcherPackage, notNullValue());
mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT);
//launch app
Context mContext = InstrumentationRegistry.getContext();
final Intent intent = mContext.getPackageManager()
.getLaunchIntentForPackage(GMAIL_APP_PACKAGE);
//Clear any previous instances
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
mContext.startActivity(intent);
//wait for app to appear
mDevice.wait(Until.hasObject(By.pkg(GMAIL_APP_PACKAGE).depth(0)), LAUNCH_TIMEOUT);
mDevice.waitForWindowUpdate(null, 5000);
}
Using the above code, i am able to launch the package i want then use UiAutomatorView.bat to inspect the elements and get their resource id's (or find by text) then perform operations on them.
In iOS, all of the tutorials that i've found centre on testing apps that you have access to source code for. While I understand that it is much simpler to write these tests in iOS since you simply record the actions you wish to perform and xcode writes the code for you, I am unsure as to how to set the UI Test Target to an app that is currently installed on my device. I watched the WWDC video that went over multi-app testing using this:
var gmailApp: XCUIApplication!
gmailApp.launchArguments = "-StartFromCleanState", "YES"]
gmailApp.launch()
however this will not work since it has no target.
TL;DR: How do I set an app installed on my device, such as gmail, as my UI Test Target, and how do i discover package names in order to launch the app?
Thanks!
I don't believe this is possible unfortunately.
You only need the bundle identifier to launch another application.
https://developer.apple.com/documentation/xctest/xcuiapplication/2879415-initwithbundleidentifier?language=objc
I use this for macOS testing a lot so I guess it will work for iOS as well.

How to stop displaying "Error - The server was unable to process the request" - IBM MobileFirst 7.1.0

I am developing app for Android and IPhone using IBM MobileFirst Platform Foundation 7.1.0.
WL.Client.Connect is used inside wlcommoninit().
Still in few cases, I am able to see the below error dialog.
I am not able to exactly reproduce when I am getting this error dialog.
The logcat is attached here.
But is there any way that we can block showing this dialog to the user?
You could debug the application code to see which function is triggered when this specific dialog is displayed and then override the function by declaring it in your own code and simply keep it empty. In theory this should then not display it.
There is no built-in/provided option to simply not display it.

How can a Developer Hand Over a Web Request to a Native iOS Application without displaying an error if the application is not installed?

So, we've all pretty much seen it. I tap a google plus link in Safari and it opens in the native Google Plus app. If the app is not installed, it takes me to the store to download it. It's a seamless transition.
As a developer, I would like this type of integration with my web application and native application. I've seen a way to call the native app using a custom url scheme, but this throws a nasty alert if the app isn't on the device.
I thought that the way around it might be creating a Safari extension, but that's not do-able with mobile safari.
How can I achieve this seamless transition effect?
This answer might help you to determine whether the app was installed or not from web app.
iPhone browser: Checking if iPhone app is installed from browser
If it's not installed you can continue redirecting to your web app instead of myapp://
The code from one of our web apps
var iOS = /(iPad|iPhone|iPod)/g.test( navigator.userAgent );
var messageContainer=$("#message");
if(!iOS)
{
messageContainer.html("Please open the link in your Apple mobile device")
}
else
{
setTimeout(function () {
messageContainer.html("Please install the app");}, 25);
window.location.href = "myapp://someInfo";
}

Resources