page object watir cucumber test for file being downloaded - cucumber

I'm trying to test that a file downloaded is initialized when i click on an image. So far i've been unable to find anything that seems to work with page object.
More specifically i'm looking for a way to handle the download dialogue pop up and to verify that file.exe has begun downloading.
Thank you

You can activate some option when you launch your browser. Here an example I use :
# create the folder location
download_directory = "#{Dir.pwd}/downloads/"
download_directory.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows?
# Create the firefox profile
profile['browser.download.folderList'] = 2
profile['browser.download.dir'] = download_directory
profile['download.prompt_for_download'] = false
profile['browser.helperApps.neverAsk.saveToDisk'] = "application/octet-stream,text/csv,application/pdf"
profile['network.http.use-cache'] = false
# launch FF
#browser = Watir::Browser.new :firefox, profile: profile
Then you don't need to handle the window, but only to check the downloaded file in the folder you define.
For chrome, you can't use a profile, but should use preferences.
# Create the prefs
prefs = {
download: {
prompt_for_download: false,
default_directory: #download_directory
}
}
# Launch chrome
#browser = Watir::Browser.new :chrome, prefs: prefs
And no, I don't find a solution for internet explorer yet.

Related

Safari in fullscreen mode ahref target "_blank" does not open in new window

We have an app that opens in a new window (popup) with defined window size. There are links in the app that open another external links.
We have a code to handle ahref links to open in a new window using target as "_blank".
It works fine with all the browsers except in Safari when the popup window is changed to fullscreen mode. Once in fullscreen mode the external links (even with _blank) open in the same window and replace the content of the main window.
I want to open the external links in a new tab/window always.
Please help.
handleLinks: function (link) {
var url = link.href;
if (url && !url.indexOf('http')) {
link.target = '_blank'
link.rel = 'external';
} else if (url && !url.indexOf('mailto')) {
// FIX FOR CHROME BROWSER NOT TO OPEN IN A BROWSER TAB FOR MAIL CLIENT
link.target = '_top';
}
}

Android Studio - prompt to open a downloaded file with any application available

I have an application which receives urls from a server, using Firebase. When the url is received, the file at that url is automatically saved on the local storage (they are gpx files).
But after this, I want my application to prompt the user to open the downloaded file with whatever navigation application they have installed on their phone. Something similar to when you go to the file manager yourself, click on a file, and the system shows you all applications which could open that file, and lets you chose (or opens it directly with your default setting, if you have one).
I have not been able to find anything about this, and searches containing "android studio" and "open file" show mostly tutorials about how to manage the source files themselves, so they are not helpful at all.
You could do something like:
String mimeType = myMime.getMimeTypeFromExtension(fileExt(getFile()).substring(1));
newIntent.setDataAndType(Uri.fromFile(getFile()),mimeType);
private String fileExt(String url) {
if (url.indexOf("?") > -1) {
url = url.substring(0, url.indexOf("?"));
}
if (url.lastIndexOf(".") == -1) {
return null;
} else {
String ext = url.substring(url.lastIndexOf(".") + 1);
if (ext.indexOf("%") > -1) {
ext = ext.substring(0, ext.indexOf("%"));
}
if (ext.indexOf("/") > -1) {
ext = ext.substring(0, ext.indexOf("/"));
}
return ext.toLowerCase();
}
}
This allows you to get the type based on file extension. Then just startActivity passing in the newIntent. This should achieve what you are looking for.

Swift WKWebView Configuration

I have a small application. I am opening youtube in webview and see the videos.
Everything is good but when I click the video it is opening new page and start video automaticly full screen.
I do not want auto start play video.
How can I do it?
My code:
let conf = WKWebViewConfiguration()
conf.allowsInlineMediaPlayback = false //Tried and Did not work
conf.requiresUserActionForMediaPlayback = true //Tried and Did not work
super.init(frame: CGRect.zero, configuration: conf)
Try it conf.allowsInlineMediaPlayback = true .

Run file after chrome.downloads.download

I have a background script in my Chrome Extension which downloads a file called install.bat from the extensions directory. That works perfectly. But when I want to call chrome.downloads.open(id); the following error gets thrown:
Unchecked runtime.lastError while running downloads.open: User gesture required
I have requested both permissions (["downloads", "downloads.open"]) in the manifest.json file which are required for this procedure.
Is there a workaround for this problem or even a plain solution?
So after I read the discussion #abielita mentioned in his comment, I found a solution for my problem. Notifications are now counted as User gesture again.
But being not able to open downloads automatically when the permission downloads.open is requested in the manifest makes this permission just useless.
So here is my solution (with wich I'm not really satisfied with, because the download doesn't open automatically) but it worked for me:
var downloadID = 123;
var nIcon = chrome.extension.getURL("icons/icon_48.png");
var nTitle = "My Extension - Client Installer";
var nMessage = "Please click the button below to run the installer.";
var nButtons = [{ title: "Run the installer..." }];
var nOptions = { type: "basic", iconUrl: nIcon, priority: 2, title: nTitle, message: nMessage, buttons: nButtons };
chrome.notifications.create("hello_world", nOptions, function (nIDa) {
chrome.notifications.onButtonClicked.addListener(function (nIDb, nButtonIndex) {
if (nIDb === nIDa) {
chrome.downloads.open(downloadID);
}
});
});

content script - window.location.href = url_b; lands on about:blank page

In my content script
var url_b = 'chrome-extension://abcdefghijklmnopqrstuv/page_b.html';
window.location.href = url_b;
takes me to about:blank instead of chrome file
'chrome-extension://abcdefghijklmnopqrstuv/page_b.html' url is valid and works when opened in a new tab
same code if url_b = 'www.gmail.com'
takes me to gmail. works fine.
to reproduce.
1.open gmail.com in a tab
2.open console and command in 'window.location.href = chrome-extension://any sample file'
3.about:blank opens
4.run step 2 again
5.sample page opens

Resources