Finding downloaded files with Selenium webdriver - selenium-webdriver

I'm using selenium web driver with chrome to create some test.
The test clicks on a button which causes a zip file to be downloaded to the host.
How can I find the file after downloading?

This file will land in the default download location from Google Chrome
unless set explicitly in your code with DesiredCapabilities and ChromeOptions as describe here.
Default location of Downloads folder.
nix systems:
String location = System.getProperty("user.dir") + "/Downloads";
Windows:
String location = System.getProperty("user.dir") + "\\Downloads";

Related

How can i configure in Appium the URL of an application?

I have the url of an application, (not the .ipa file), how can i configure this url in appium? i don't have the path for that file. The application is coded by Angular JS.
If the problem is only The path, this is how i do it:
zip the app folder (testapp.app.zip)
put zip file in a folder (~/server/)
open a terminal and cd to folder (cd ~/server)
run command python -m SimpleHTTPServer 8000
Your application address is http://localhost:8000/testapp.app.zip.
This is done on the appium side, your test code can be anywhere. localhost is what appium see, so there is no problem if you run test from another system.
You can do it via your code,
capa = new DesiredCapabilities();
capa.setCapability("app", "http://example.com/appname.ipa");
Providing the URL shouldn't have any credentials.
If its for safari use the below capabilities in the code not Appium gui
DesiredCapabilities capabilities=new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME,"Appium");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,MobilePlatform.IOS);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION,"7.1");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME,"safari");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"iPhone Simulator");
IOSDriver driver=new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.get("http://google.com");
Thread.sleep(4000);
driver.quit();
I have solved my problem by 2 ways :
I put in URL the path for * > /Debug-iphonesimulator/UICatalog.app
Adding app : "safari" and i run appium with npm version 1.5.5 like
that :
appium --default-capabilities
'{"app":"safari","browserName":"safari","appium-version":"1.5.1","platformName":"iOS","platformVersion":"9.3","deviceName":"iPad Air","nativeInstrumentsLib":true}' --command-timeout "0"
--pre-launch
--nodeconfig "/Users/me/nodeconfig.json" --launch-timeout "180000"

How to open safari browser using Selenium WebDriver?

Can anyone please explain me the below doubt?
How to open google page in safari browser using Selenium WebDriver?
I am using the below code to open the safari browser.
WebDriver driver = new SafariDriver();
driver.get("http://www.google.com/");
But I am getting "SafariDriver requesting connection at ws://localhost:40921" error message
Can anyone please help me for the above?
You need to install Safari Extensions Developer Certificate in your machine and also install selenium webdriver as an extension in Safari Browser.
Also there are some stability issues with Safari browser & Selenium combination on Mac 10.9 OS and below.
The stability is much better on Mac Yosemite OSX & Safari 8.0.x combination along with Selenium v2.45.0
Have you checked out these links?
http://code.google.com/p/selenium/wiki/SafariDriver
http://code.google.com/p/selenium/issues/detail?id=3827
Prerequisite: Install Safari on Windows if it is not already installed
Go to http://docs.seleniumhq.org/download/
Scroll down -> Go to the section "SafariDriver" and download "SafariDriver.safariextz"
Double click on "SafariDriver.safariextz" (previously downloaded)
Safari would open with a pop up containing "Install" button -> Click Install button
Now go to Preferences of Safari -> Extensions tab : you would see WebDriver (in my case WebDriver 2.48.0) is installed (Enable WebDriver checkbox is checked))
It's now time to instantiate SafariDriver and get the desired URL by using Java. Please find the code:
WebDriver driver = new SafariDriver();<br>
driver.get("https://www.lynda.com/Ripon-Al-Wasim/8496323-1.html");
First of all, you don't need to download safaridriver if you having MacOS High Sierra and later, as its already present by default at
cd /usr/bin
ls -a
Can check here safaridriver is already present
so how to configure this safaridriver in test files
private static final String KEY_SAFARI_WEBDRIVER = "webdriver.safari.driver";
private static final String SAFARI_WEBDRIVER_PATH = "/usr/bin/safaridriver";
System.setProperty(KEY_SAFARI_WEBDRIVER, SAFARI_WEBDRIVER_PATH);
WebDriver driver=new SafariDriver();
By default automation testing option is disabled in safari,
can enable it from safari browser
Develop -> Allow remote automation
reference: https://www.lambdatest.com/blog/selenium-safaridriver-macos/
Try this instead:
System.setProperty("webdriver.safari.driver","C:/safaridriver.exe")
WebDriver driver = new SafariDriver();

Launch chrome browser

I am trying to launch chrome browser (version 26.0) using webdriver.
I am getting the following error message.
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver.
at com.google.common.base.Preconditions.checkState(Preconditions.java:176)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:69)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
at googleSearch.main(googleSearch.java:13)
Code I used:
driver = new ChromeDriver();
driver.navigate().to("http://www.google.com/");
I use mac 10.8.2.
For this to work, you need to:
Install Chrome
Install Chrome Web Driver
Make sure you have the chrome web driver in you path, for example on Windows something pointing to chromedriver2_win32_0.8. You can put that in your path by either: (a) Modifying your windows path environment variable, or; (b) adding the following to your java command line options:
-Dwebdriver.chrome.driver='/path/to/driver'
In case of using selenium grid
-Dwebdriver.chrome.driver='/path/to/driver'
has to be added while creating a node from command line.
1) In case of using selenium without GRID:
System.setProperty("webdriver.chrome.driver","/absolute/path/to/chromedriver");
driver = new ChromeDriver();
does the job.
2) In case of using selenium with GRID:
System.setProperty("webdriver.chrome.driver","/absolute/path/to/chromedriver");
driver = new ChromeDriver();
And from command line, while creating a node for chrome browser one needs to pass
-Dwebdriver.chrome.driver='/absolute/path/to/chromedriver'
The above two changes did the job for me, apart from this I was getting this libnss3.so not found error which I solved by creating a symlink of libnss3.so present in /usr/lib/x86_64-linux-gnu/ folder to /usr/lib/
ln -s /usr/lib/x86_64-linux-gnu/libnss3.so /usr/lib/libnss3.so
PS: Also make sure that you are using 64bit OR 32bit version of chrome driver as per your system.
For chrome to work with selenium-webdriver you need to have not only a working chrome browser installed, but also the chromedriver executable. Note that these are TWO different executable files that both need to be specified.
change the permission of file and then run your code again.
Open command prompt and navigate to directory where your chrome exe exists and write
chmod 777 filename
Hope it will solve your problem.

Selenium IDE - local (non-webhosted) file access for testing?

My Problem
When Selenium IDE is used to run a test, the "Base URL" is always accessed via http on some web server.
I need to know if (and how) its possible to get Selenium IDE to run a test on a locally stored file. When opening a file in Firefox, the path looks something like this in the Address Bar: file:///C:/Documents and Settings/username/My Documents/somehtml.html
However, Selenium gives a nasty error when I put this path in the Selenium IDE's Base URL field for my test (See bottom of my post).
What I tried
I run Windows XP and have tried switching the file path slashes to backslashes while keeping the protocol (file:///) slashes as is. I tried replacing spaces with %20 too.
I also considered whether my Firefox proxy settings might be causing an issue, but it isn't because if i open the file in Firefox it does so without issue.
The solution I'm working on is to avoid Selenium WebDriver at this phase. I know it is better on a technical but there are practical reasons why I can't use that at this point. Selenium IDE must be used for now.
Error
Error thrown when attempting to open local file:
[error] Unexpected Exception: name -> NS_ERROR_FAILURE, QueryInterface
-> function QueryInterface() { [native code] }, message -> Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)
[nsIDOMLocation.href], result -> 2147500037, filename ->
chrome://selenium-ide/content/selenium-core/scripts/selenium-browserbot.js,
lineNumber -> 686, columnNumber -> 0, location -> JS frame ::
chrome://selenium-ide/content/selenium-core/scripts/selenium-browserbot.js
:: BrowserBot.prototype.setOpenLocation :: line 686, inner -> null,
data -> null, initialize -> function initialize() { [native code] }
open about:config then change security.fileuri.strict_origin_policy to false. enjoy
One solution is to use the open command as the first line in your test, and set the local path as the target. This is fine for a handful of tests, but may not be sufficient for larger test suites.
command: open
target: file///c:/path/to/your/file.html
I had the same issue. Just solved it. Here is how:
Remove the base url.
Enter open or openWindow in command
Enter the file url in target e.g. file:///C:/temp/junk/SomeSiteAutomation/ABC.htm
Worked for me on FF 26 and Selenium 2.5
Open Selenium IDE - chrome extension
As soon as we open it will ask for project name and project url - just cancel it
Go to selenium IDE
In selenium IDE - in "command" text box select "open"
in "target" text box enter the path to sample html file as below
"file:///D:/index2.html"
Then this will show up in the command, target and value columns of the selenium ide.
Now just run the test. This will open up the local html file
I faced the same problem. I'm using Ubuntu and apache, but on Windows you can do the same.
move your index.html to /var/www/html (localhost points per default to this folder)
use http://127.0.0.1 as base_url in selenium ide
Right click on the Selenium IDE icon in the upper right of the browser window. Select "Manage Extensions" from the context menu. Toggle on "Allow access to file URLs" in the settings dialog.
This works in Chrome/Windows 10 and Version 3.17.0 of Selenium IDE.

How to handle Windows Download dialog box using selenium web driver

I am using selenium web driver (Not selenium RC). I need to download a xml file by clicking a link. I have did some Google search, and I have found in some answers an using AutoIT in order to handle OS related dialog boxes.
But is there any other option using selenium to handle this without using AutoIT tool.
Kindly suggest some ideas.
Can you be a bit more specific which browser you are using. If it's firefox you can have a greater control on the file download. Any other browser including firefox you can use robot class. This can be used to perform the click on ok button for downloads. If its chorme then file download happens automatically without any intervention.
For the newest version of Firefox (as of writing), these are the arguments that I needed to avoid the download box. Note that you need to specify a directory that you can write to as seen in the third statement:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference( "browser.download.folderList", 2 );
profile.setPreference( "browser.download.dir", <YOUR DOWNLOAD PATH> );
profile.setPreference( "plugin.disable_full_page_plugin_for_types", "application/pdf" );
profile.setPreference(
"browser.helperApps.neverAsk.saveToDisk",
"application/csv,text/csv,application/pdfss, application/excel" );
profile.setPreference( "browser.download.manager.showWhenStarting", false );
profile.setPreference( "pdfjs.disabled", true );
Note that the last line with pdfjs is required for the newer versions of Firefox, where it wasn't before. More info Here
I face Authentication Proxy pop-up issue in my project. So I tried below solution and it is working fine.
When we run Script from Selenium Web driver on Security Environment following Setup needs to be done to handle Authentication Proxy.
First you need to know below details,
network.proxy.autoconfig_url (Example: "http://example.com/abc.pac")
network.proxy.http (Example: abc-proxy.com)
network.proxy.http_port (Example: 8080)
private static WebDriver initFirefoxDriver(String appURL)
{
System.out.println("Launching Firefox browser..");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("network.proxy.type", 1);
firefoxProfile.setPreference("network.proxy.autoconfig_url", "http://example.com/abc.pac");
firefoxProfile.setPreference("network.proxy.http", " abc-proxy.com");
firefoxProfile.setPreference("network.proxy.http_port", 8080);
WebDriver driver = new FirefoxDriver(firefoxProfile);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.navigate().to(appURL);
//driver.get(appURL);
return driver;
}

Resources