Adobe AIR air.navigateToURL works very strangely - air

I want to open a link in a default browser window, so I tried the method in this post:
http://sevenwire.com/blog/2009/08/26/adobe-air-opening-external-links-in-another-browser.html
But it sometimes works, sometimes doesn't. Very strange.
Is there anyway to force the air app open a link in a new default browser window/tab?

Yes. The second parameter in navigateToUrl() defines where to open the page.
If you use:
var url:URLRequest=new URLRequest("http://something.example.com/page.html");
navigateToURL(url,"_blank");
It will open the page in the new tab/page in default browser. More info at Adobe Actionscript Reference

Related

Switching to browser from a native android app with Appium

I'm trying to handle the opening browser from a native app.
I have a native android app. When I click a link on it, it opens a browser. I'm trying to switch to that browser but couldn't do it. My code block is:
Set<String> contextNames = ((AppiumDriver) webDriver).getContextHandles();
for (String contextName : contextNames) {
if (contextName.contains("android.browser")) {
((AppiumDriver) webDriver).context(contextName);
}
}
After I debugged some (for further questions)
My app contains a vebview on all pages. Here's what I get when I check with getContextHandles() on any page:
0 = "NATIVE_APP"
1 = "WEBVIEW_com.dmall.app"
If I switch context to webview and getPageSource(), I see there is an empty view.
html xmlns="http://www.w3.org/1999/xhtml">head>/head>body>iframe name="chromedriver dummy frame" src="about:blank">/iframe>/body>
(I removed some chars because of this page accept html)
I started the test again and after click the link that opens a browser and check getContextHandles(), I see
0 = "NATIVE_APP"
1 = "WEBVIEW_com.dmall.app"
2 = "WEBVIEW_com.android.browser"
Everything looks as it should be, right?
Then I'm doing:
((AppiumDriver) webDriver).context(WEBVIEW_com.android.browser);
when I check the page source, I see the same empty webview
html xmlns="http://www.w3.org/1999/xhtml">
By the way, I can't switch to other webview after this point, it says:
"An unknown server-side error occurred while processing the command. Original error: We already have a chromedriver instance running (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 134 milliseconds"
I guess this is normal
So, how can I switch to browser, any idea, solution, questions, brain storming, anything can be useful.
My capabilities is here:
DesiredCapabilities capability = DesiredCapabilities.android();
capability.setCapability(MobileCapabilityType.APP, "http://172.20.0.196:8088/android/mfandroid-debug.apk");
capability.setCapability(MobileCapabilityType.DEVICE_NAME, "AndroidEmulator" + RandomStringUtils.randomNumeric(3));
capability.setCapability(MobileCapabilityType.PLATFORM, "Android");
capability.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");
capability.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 3000);
capability.setCapability("autoAcceptAlerts", "true");
capability.setCapability("sendKeyStrategy", "setValue");
Thanks
I have faced this issue before so I think I am the right person to answer this question.
You can switch to webView of the app under test [AUT] only and not to the webView of any other app. Which means your app under test is app1 and you want to switch to webView of app2.
To switch to webView of app2 you need to change the app Capabilites at run time after you perform some actions on app1. I suggest you to do:
Close the driver once you click on the link in your first native app (I hope after clicking the link will be opened in the app2).
Re-initialise the driver with new app capabilities of app2.
Now, you should able to switch to webView of app2 (browser).

Open images from Windows store application

I have created a windows store application and I want the user to open Documents, Excel files and picture from the app. I want the files to open in their default application. i.e. Docs in word and pictures in windows picture viewer.
I have used the following code:
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.FileTypeFilter.Add(".Doc");
openPicker.FileTypeFilter.Add(".Docx");
openPicker.FileTypeFilter.Add(".png");
openPicker.FileTypeFilter.Add(".jpg");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file!=null)
{
await Windows.System.Launcher.LaunchFileAsync(file);
}
When I run this and browse to a word document the file opens up fine using word, great.
But if I browse to an image file, it doesn't do anything. I don't get any errors.
Any ideas what I need to do?
Thanks
There is no error and, simply, nothing happens? That's strange.
Here's my go-to syntax, but it's basically yours:
Let's consider what should happen. When you "launch" a docx you are basically asking the default viewer to open for that file, in that case Word. With an image you are asking the image viewer to launch. Should it work? Yes.
Launching a docx when Word is not installed should not result in the behavior your are seeing. No. You should get prompted to find a viewer in the Store. Same with an image. Even without a viewer you should get something.
Not to be a dork here, but have you rebooted? It really sounds more like something strange has happened. You might also try appending "file:///" to the front of the URL to perhaps invoke the file viewer more explicitly. None of that should be necessary however.
Best of luck
One other thing you can do is to force app picker if default program could not be launched like following:
if (file != null)
{
var options = new Windows.System.LauncherOptions();
options.DisplayApplicationPicker = true;
bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
}

Automate a button click on chrome://extensions page using selenium webdriver

I'm trying to write an automated test that will automate the process of updating a google chrome extension. I'm not aware of another method of doing this automatically so here is what I'm currently trying to do:
Open the chrome extensions page (as far as I'm aware this is just an html page unless I'm missing something).
Click on the "Update extensions" button
Here is what I have tried having opened the chrome extensions page:
IwebElement UpdateButton = driver.findelement(By.Id("update-extensions-now"));
UpdateButton.Click();
For some reason the button click is not registering. I have tried some other locators such as CSS path and Xpath but they don't work either. Also, when I debug this test, it passes fine so I know it's not an issue with any of my locators. I have (as a test) tried to automate clicks on the other elements on this page and it's the same issue. I can't get a handle on any elements on the chrome://extensions page at all.
Has anyone encountered this or have any ideas as to what's going on?
You can use the Chrome extensions API to auto-update required extension.
Find the file "manifest.json" in the default Google Chrome
C:\Users\*UserName*\AppData\Local\Google\Chrome\User Data\Default\Extensions
There find the update URL of your extension:
{
"name": "My extension",
...
"update_url": "http://myhost.com/mytestextension/updates.xml",
...
}
The returned XML by the Google server looks like:
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='yourAppID'>
<updatecheck codebase='http://myhost.com/mytestextension/mte_v2.crx' version='2.0' />
</app>
</gupdate>
appid
The extension or app ID, generated based on a hash of the public key, as described in Packaging. You can find the ID of an extension or Chrome App by going to the Extensions page (chrome://extensions).
codebase
A URL to the .crx file.
version
Used by the client to determine whether it should download the .crx file specified by codebase. It should match the value of "version" in the .crx file's manifest.json file.
The update manifest XML file may contain information about multiple extensions by including multiple elements.
Another option is to use the --extensions-update-frequency command-line flag to set a more frequent interval in seconds. For example, to make checks run every 45 seconds, run Google Chrome like this:
chrome.exe --extensions-update-frequency=45
Note that this affects checks for all installed extensions and apps, so consider the bandwidth and server load implications of this. You may want to temporarily uninstall all but the one you are testing with, and should not run with this option turned on during normal browser usage.
The request to update each individual extension would be:
http://test.com/extension_updates.php?x=id%3DyourAppID%26v%3D1.1
You can find even more detailed information on exntesions developers site: https://developer.chrome.com/extensions
If you look at the HTML of the "chrome://extensions" page you will notice that the "Update extensions now" button is contained within an iframe. You need to switch to the iframe before trying to register a button click. i.e:
(This is in c#. Note that this code is written from memory so it may not be 100% accurate. Also, you will want to write more robust method. This code just quickly demonstrates that by switching to the iframe, it will work ok)
String ChromeExtensionsPage = "chrome://extensions";
driver.Navigate().GoToUrl(ChromeExtensionsPage);
driver.Switchto().Frame("DesiredFrame");
IwebElement UpdateButton = driver.findelement(By.Id("DesiredButtonID"));
UpdateButton.Click();

Open flash in new page

New to Flash and I am working with Flash 5, actionscript 2.
I have the following code,
b1.onPress = function()
{getURL("http://rosswarner.com/lion.html");
}
I want the page to be opened in a blank page.
I have tried the usual HTML way, no luck, done some looking, no luck so here I am.
Please change the above code to what it has to be if possible.
Thanks.
By Default GetURL uses the parameter "_self"... you need the parameter "_blank"
You can do this by using
getURL("http://rosswarner.com/lion.html";, "_blank");
Other parameters include "_parent" and "_top"

Safari extension options pages with access to background page

I'm developing a cross-platform browser extension, and have based all my code on the Chrome-way of doing this. I have counted on that the background page will be accessible from the options page, which in Safari extensions turns out to be not possible (since there is no such thing as an options-page). You can only access safari.extension.globalPage.contentWindow from within the extension popup, and the background page itself.
Now, I have an options page, which is an html-page within the extension bundle, and so far I haven't found a way for Safari to give it extension "rights". The closest I have come is adding a content script that's only added on the options page. This seems a bit silly, since the html page itself is in the extension bundle?!
Others have suggested using asynchronous ping-pong style message event handlers, and even the canLoad-mechanism (which is "only" able to run in a beforeload-event). I have been able to hack the canLoad-mechanism for synchronous messaging by forging the BeforeLoadEvent:
// Content script (run from anywhere)
var result = safari.self.tab.canLoad(new BeforeLoadEvent, "data")
-> "return value"
// Background page
safari.application.addEventListener('message', function(e) {
if ( e.name === "canLoad" )
e.message = "return value";
}, true);
It's a hack, but it works. However, I am crippled by the message transport serialization, since I need to be able access methods and data on my objects from the background page. Is there anyway around this?
Possible ways that might work but I don't know if possible:
Access options-page window-object from backgrounds page. Is that possible?
Message passing, need to bypass message serialization
Any shared/global object that I can attach objects to and fetch from the options page?
Make Safari run the options.html page from outside the content-script sandbox? It works in Chrome since they are both within the extension-bundle. It's quite annoying that safari doesn't do this too.
Run the options-page from within the popup. This is promising, but it crashes safari (which is very promising!). However, from the looks of it it's just something to do with a CSS animation in my options.html page. The biggest issue is that it has to be able to open an OAuth2 popup, but thanks to being able to programmatically open the popover, it might be a non-issue. However, this option is the most realistic, but I would rather have it open in a new tab.
Any suggestions and hackish workarounds would really help.