Appium: dealing with android system interactions - appium

I have a simple use-case. Within the android app, press a button and the browser app will open a URL.
The "Open With" dialog pop-up appears and allows you to select Browser or Chrome.
Which looks like this in the appium inspector:
<android.widget.ListView resource-id="android:id/resolver_list">
<android.widget.LinearLayout>
<android.widget.ImageView resource-id="android:id/icon">
<android.widget.LinearLayout>
<android.widget.TextView resource-id="android:id/text1">
<android.widget.LinearLayout>
<android.widget.ImageView resource-id="android:id/icon">
<android.widget.LinearLayout>
<android.widget.TextView resource-id="android:id/text1">
Attempting to automate this seems like it should be trivial, but is causing me trouble. I can get the text of both "Browser" and "Chrome" as discrete AndroidElements, but I cannot seem to be able to actually press the actual options.
Am I allowed to actually interact with these things or is this impossible because it's part of the android system itself?
To help figure this out, here is the setup of my page object.
#AndroidFindBy(id = "android:id/resolver_list")
private AndroidElement listParentElement;
public List<OpenWithOption> getOptions() {
/* ... */
List<MobileElement> elements = listParentElement
.findElementsById(SYS_ID_PREFIX + "text1"); // Here's where I can only get the text element itself but can't figure out how to get the elements above that.
return elements.stream()
.map(mobileElement -> new OpenWithOptionImpl(mobileElement.getText(), mobileElement))
.collect(toList());
}

This was a rookie mistake. Selecting the browser enabled the choice of "Just Once" or "Always" in the bottom of the screen and I didn't notice. I thought that just pressing the browser you wanted would launch it.

Related

In a Firefox extension, if I open a tab using a custom scheme, how do I close it, because my extension is not authorized for that scheme pattern?

I have a custom scheme mapped on my Windows machine: "dbn".
So, when I put dbn:/some/arguments in the Firefox address bar (or click on such a link), it launches in another application. This works great.
However, in a Firefox extension, I don't know how to "call" or "activate" this custom scheme except by opening a new tab, like this:
browser.tabs.create({ url: 'dbn:/some/arguments' });
That works fine, except now I have an open tab with dbn:/some/arguments as the URL. I have attempted to subsequently close it from my extension, but I can't because:
Error: Missing host permission for the tab
My extension doesn't have permissions for that "host."
I have tried to give it permissions via a match_patterns value of dbn:* but that throws an error when I try to reload the extension because those values apparently have to use one of the expected schemes (http, https, ftp, etc.).
I end up just having to close the tab manually, which isn't terrible, but is clearly sub-optimal.
So, two questions:
Is it possible to "call" a URL in such a way to activate a custom-mapped scheme on Windows without opening a tab? The only way I could think of doing this in such a way that it would activate my mapped command was to open a tab, but are there other ways?
If opening a new tab is the only way to do this, how do I close the tab I just opened without having the permissions problem I mention above?
Update
I don't think it's permissions anymore. The Promise simply won't resolve.
browser.tabs.create({ url: "some/url" })
.then(tab => console.error("I never get here"));
I've debugged up, down, and sideways. The new tab opens, and I can write to the log all around that operation, but the code in then just doesn't execute, no matter what I put in there. I tried to trap an error with try...catch, but that didn't trap anything.
I now think that permission above was coming from a different extension, not my extension. I don't think this has anything to do with the host.
AFA custom schemes, there is an open bug: Extend match patterns to handle custom protocol schemes
You can tabs.remove() a tab by its ID which you get from tabs.create().
async function fun() {
// note this is async
const tab = await browser.tabs.create({url: 'dbn:/some/arguments'});
// later remove it
browser.tabs.remove(tab.id);
}
// or
browser.tabs.create({url: 'dbn:/some/arguments'})
.then(tab => {
// do what is needed
// later remove it
browser.tabs.remove(tab.id);
});
Update:
Regarding the Promise, there is not enough information to pinpoint the issue.
Which permissions have been set?
Where is the code running?
Use catch to get more info about the Promise failure:
browser.tabs.create({url: "some/url"})
.then(tab => console.log(`Created new tab: ${tab.id}`))
.catch(error => console.log(error.message));

Unable to click button using NHtmlUnit

I have a unit test which simulates a login on Uber. The goal is to acquire a token that isn't otherwise accessible without an interactive login. I've had this working in the passed but it appears the Uber login experience has changed and now I'm having issues getting NHtmlUnit to successfully submit the login button.
Here's my latest attempt: https://github.com/wadewegner/uber-sdk-for-net/blob/42fd845fe43e11e3153b07d830ed40e3577b1ed3/src/UberSDKForNet.FunctionalTests/Tests.cs#L100
Here's the key area:
var loginFormButtons = loginForm.GetElementsByTagName("button");
Assert.IsNotNull(loginFormButtons);
var loginButton = (HtmlButton)loginFormButtons.First();
Assert.IsNotNull(loginButton);
var loginButtonText = loginButton.AsText();
StringAssert.Contains("sign in", loginButtonText.toLowerCase());
loginButton.SetAttribute("type", "submit");
loginForm.AppendChild(loginButton);
var consentPage = (HtmlPage)loginButton.Click();
Assert.IsNotNull(consentPage);
I know the code is verbose, but unit testing NHtmlUnit is a nightmare. I've also tried a ton of different permutations, but they pretty much all end up with a HtmlButton.
Everything works great until https://github.com/wadewegner/uber-sdk-for-net/blob/42fd845fe43e11e3153b07d830ed40e3577b1ed3/src/UberSDKForNet.FunctionalTests/Tests.cs#L174. What I'd expect is for this to take me to the consent page where I'd either allow or deny the Uber app access to my information. However, it appears to simply reload the original page and consentPage appears to simply be the same as loginPage.
Any NHtmlUnit experts who might have some ideas?
The only thing I'll also point out is that in the past I was able to successfully use HtmlSubmitInput instead of HtmlButton but this appears to be one of the changes made by Uber. Perhaps this is part of the problem?
Well, it's not perfect, but it appears setting the WebClient to FIREFOX_17 instead of CHROME solved it.
var webClient = new WebClient(BrowserVersion.FIREFOX_17);
See here: https://github.com/wadewegner/uber-sdk-for-net/blob/ceb1cdf80cebb31608744c050b649ddd6a75fb7a/src/UberSDKForNet.FunctionalTests/Tests.cs#L107

Unable to findByXpath using Leadfoot / Intern

Using Intern JS with WebDirver to communicate with Appium 1.4.1, I have a simple functional test, part of which should find a text input box on the login screen of our iOS app, tap into it and type the user's login name:
define([
'intern!object',
'intern/chai!assert',
'require'
], function (registerSuite, assert, require) {
registerSuite({
name: 'Suite Name',
'Login Screen': function () {
return this.remote
.setFindTimeout(50000)
.findByXpath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATextField[1]/UIATextField[1]")
.tap()
.type('student1#demo.com')
.end()
.then(function (pagetitle) {
assert.strictEqual(pagetitle, 'DEMO COLLEGE',
'Should land on app dashboard with school title displayed');
});
}
});
});
When executed using intern-runner everything appears to go well, Appium launches our app and awaits my input - but no matter what I try I can't find the element I need to type into using Leadfoot's findByXpath:
$ intern-runner config=tests/appium
Listening on 0.0.0.0:9000
Starting tunnel...
Initialised iOS on MAC 8.1
Test main - Suite Name - Login Screen FAILED on iOS on MAC 8.1:
NoSuchElement: [POST http://[appium-server-address]:4723/wd/hub/session/80e20453-452e-4181-8713-4f9e0cfa427f/element / {"using":"xpath","value":"//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATextField[1]/UIATextField[1]"}] An element could not be located on the page using the given search parameters.
at Server._post <../../.nvm/v0.10.35/lib/node_modules/intern/node_modules/leadfoot/Server.js:68:9>
Using Appium's GUI "inspector" I've confirmed the Xpath to the text-input-box element is:
"//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATextField[1]/UIATextField[1]"
Can anyone suggest where I'm going wrong please?
Looks like the Appium Inspector tool on my Mac was duplicating part of the path?
.findByXPath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATextField[1]/**UIATextField[1]**")
.type("wibble")
Remove the duplicated element in bold (the final UIATextField[1]) ....
.findByXPath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATextField[1]/**UIATextField[1]**")
.type("wibble")
And it works.
Thanks Appium Inspector. Thanks a lot.

sendkeys command causing exception in selenium webdriver on IOS safari

I have been trying to run some sample Remote WebDriver tests on the Safari browser on the IOS Simulator 7.0 (IPhone) but my tests give an exception every time I try to type in values on a text box. Just trying to use the example from iosdriver
DesiredCapabilities safari = IOSCapabilities.iphone("Safari");
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://<someip>:4444/wd/hub"), safari);
driver.get("http://hp.mobileweb.ebay.co.uk/home");
WebElement search = driver.findElement(By.id("srchDv"));
search.sendKeys("ipod");
search.submit();
gives me the exception
a "org.openqa.selenium.NoSuchElementException: cannot find element for criteria :{"AND":[{"l10n":"none","expected":"UIAElement","matching":"exact","method":"type"},{"l10n":"none","expected":"Address","matching":"exact","method":"name"}" .
Anyone else run into this? It is identifying the element but typing in values fail..It works fine when I try it on firefox on my desktop.
I am no expert, but am familiar with selenium webdriver..
Are you sure that the id for "search " --- ('srchDv') actually exists on the page you are trying to automate?
if so
i would then look into the UIA -Element Hierarchy / Accessibility link to UIA Element Class reference
Hope this is helpful
You have an incorrect selector. The page you are automating does not have an id srchDv. If you are getting the search box, then you need to use:
driver.findElement(By.id("gh-ac")).clear();
driver.findElement(By.id("gh-ac")).sendKeys("ipod");
Also, instead of using submit, personally i would follow the way that your user would commit the action, and that's by clicking the search button.
driver.findElement(By.id("gh-btn")).click();

having problem in blackberry

I am doing coding from beggining blackberry by Anthony Rizk.
I am stuck with this code as it is showing error again and again...
private void getURL() {
HttpRequestDispatcher dispatcher = new HttpRequestDispatcher(urlField.getText(),
"GET", this);
dispatcher.start();
}
Can anyone explain me why we are passing this as parameter and why actually this code is doing...
"this" refers to the main screen you passed to the class so you can alert the requestFailed string. Check the run method on page 170. You'll see screen.requestFailed("Unexpected...").
As for your error - I suggest adding this line:
System.out.println(" ----------------- HTTPREQUESTDISPATCHER ---------- " + urlField.getText());
right before your dispatcher.start(); line and then compile in debug mode to see what your console says. Just to make sure your URL to request is a valid web URL.
Additionally, make sure your simulator has MDS enabled. You need that to make web calls.
In eclipse it is under Run->run configurations-> simulator tab -> general -> checkbox for Mobile Data System.
I don't know where it is in the RIM package. If you're not using eclipse, you might want to switch over to it. It will highlight errors and try to help you resolve them.

Resources