Edge driver untrusted cert capability (Selenium) - java

I'm doing automated tests in browsers, using Selenium Grid architecture and I use JSON configuration files to setup the nodes.
Is there any capability for Microsoft Edge driver similar to acceptSslCerts ? This option doesn't work I just tested it.
There's no documentation about it on DesiredCapabilities documentation and I cannot find it in Edge Webdriver documentation

C# code, but can be easily adapted to Java:
var edgeOptions = new EdgeOptions();
//Set Internet Explorer browser to accept the SSL Certificates by default
edgeOptions.AddAdditionalCapability(CapabilityType.IsJavaScriptEnabled, true);
edgeOptions.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true);

Related

Is it possible to download excel or CSV report file in selenium grid at desire location?

I am trying to download excel and CSV report file in Selenium Grid but can't able to see downloaded file at desire location.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting",false);
String path=System.getProperty("user.dir");
System.out.println(path);
profile.setPreference("browser.download.dir",path);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/msword,application/x-rar-compressed," + "application/octet-stream,application/csv,text/csv");
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability(FirefoxDriver.PROFILE, profile);
cap.setBrowserName("firefox");
cap.setPlatform(Platform.WINDOWS);
WebDriver driver = new RemoteWebDriver(new URL("GRID_URL"),cap);
//WebDriver driver= new FirefoxDriver(profile);
driver.get("http://www.winzip.com/landing/open-rar-file.html");
driver.findElement(By.xpath("//*[#id='lan_img']")).click();
System.out.println("File downloaded at location::"+path);
The file is being downloaded in the node machine to which the Grid Hub routed your test and NOT to your local machine [ This becomes complicated when your test is being triggered from a different machine and the node is running on a different machine ]
Ideally speaking you should not be automating tests that involve file downloads.
If its an absolute must, then I would suggest that you extract out the cookies from your web session and then rely on http client to download the file programmatically (wherein selenium is not involved).
I would suggest that you please take a look at this in-depth blog post by Mark Collins, wherein he elaborately talks about selenium and file downloads, the pros and cons and what alternatives can be used.
Some of the helpers he talks about in his blog are also available on github.

When i run selenium webdriver code Firefox webdriver not starting through given webaddress

When i tried to start on Firefox web driver its not starting its showing firefox default page
WebDriver dr = new FirefoxDriver();
dr.get("https://www.google.co.in/");
dr.manage().window().maximize();
its not starting its showing firefox default page
Below i attach output image screenshot
https://www.mozilla.org/en-US/firefox/43.0.4/firstrun/learnmore/
Firefox is one of the most compatible browsers with selemium, and at the same time, is one of the least compatible.
I say this because if you do not have the correct version of the selenium library to go with the version of firefox you are running, or vice-versa, it will always fail.
I would start by attempting to switch to a different version of Firefox. Selenium version 2.48.0 supports Firefox versions 24-41, so if your firefox version does not fit within that range, it is more than likely the problem.
I faced the same issue. The solution to this problem is to update the selenium version. When the page u mentioned i.e https://www.mozilla.org/en-US/firefox/43.0.4/firstrun/learnmore/ opens on firefox launch go to Options -> Addons -> Extensions. You will be able to see the Error there. I got "Forefox Webdriver could not be loaded and is disabled".
This was on Firefox 43 with selenium 2.44. Updating to selenium 2.51 rectified the issue.
Sorry, I cannot comment yet but I would like to help. I got the similar issue when I used selenium webdriver integrated in my python script. The problem was with credentials (particularly with the SSL protocols while declaring a new webdriver object). The code I used looked as the following:
driver = webdriver.PhantomJS(executable_path = "/opt/local/bin/phantomjs", service_args=['--ignore-ssl-errors=true'])
As you can see I use a key that ignores ssl errors. This solved my issue, so I am not sure what platform you use to write the code but hope you can find the similar call for the object.
I found the way how people handle untrusted certificates here. Particularly, for FireFox:
//It creates firefox profile
FirefoxProfile profile=new FirefoxProfile();
// This will set the true value
profile.setAcceptUntrustedCertificates(true);
// This will open firefox browser using above created profile
WebDriver driver=new FirefoxDriver();
driver.get("pass the url as per your requirement");
Hope it helps you!
Best.
-Petr.
Try this.. This will resolve the issue..
FirefoxProfile fpi = new FirefoxProfile();
fpi.setPreference("browser.startup.homepage_override.mstone", "ignore");
fpi.setPreference("startup.homepage_welcome_url.additional", "about:blank");
wd = new FirefoxDriver(fpi);
wd.get("http://www.google.com");
if you want to over-ride the properties of firefox, then,
1.first to find the list of browser properties, type "about:config" in the address url
2.use, setPreference method to set/assign the values..

Selenium WebDriver - What is "Selenium Client & WebDriver Language Bindings"

In the selenium download page, I see a section "Selenium Client & WebDriver Language Bindings"
1) What is a Language Binding? and
2) What is a Client Driver?
(I am not from from a technical background)
Can someone please explain the following taken from selenium download page :(http://docs.seleniumhq.org/download/)
*
In order to create scripts that interact with the Selenium Server
(Selenium RC, Selenium Remote Webdriver) or create local Selenium
WebDriver script you need to make use of language-specific client
drivers. These languages include both 1.x and 2.x style clients. While
language bindings for other languages exist, these are the core ones
that are supported by the main project hosted on google code.
*
Some of that documentation is old. It comes from the old Selenium 1.x versions. Selenium WebDriver is much different now, with 2.x versions (the latest being 2.31). Selenium 2.x versions have bindings hidden from your view. You define capabilities and start a new RemoteWebDriver and the Hub+Node handles the binding under the covers.
Now, to interact similar to RC you need:
1. To start a Grid Hub on port 4444
2. Start 1 Node Hub on port 5555 on either your local machine or a remote machine. It has configuration that tells it how to connect to the Hub.
3. In your script, start a new client using:
URL hubURL = new URL("127.0.0.1:4444"); // always use IP address
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
RemoteWebDriver driver = new RemoteWebDriver(new URL(hubURL), capability);
I have an example project you can try here.
2) What is a Client Driver?
Selenium uses many client drivers java,python.... so to work with each programming language there is a different driver.This is nothing but a JAR in my understanding.

Using Personal SSL certificates with Webdriver (Selenium 2.0)

I am testing a website which requires personal SSL certificates in order to do certain things, such as sign-in.
I have a Webdriver (Selenium 2.0) test that I have set up with a proxy:
Proxy localhostProxy = new Proxy();
localhostProxy.setProxyType(Proxy.ProxyType.MANUAL);
localhostProxy.setHttpProxy("www-proxyname:port");
FirefoxProfile profile = new FirefoxProfile();
profile.setProxyPreferences(localhostProxy);
driver = new FirefoxDriver(profile);
And this will access the homepage fine. The test then clicks the sign in button, enters in the correct credentials and clicks on submit. At this point the browser then goes into a loading state, and I'm assuming it's because the SSL certificate is missing from my side and therefore cannot connect to the sign in service.
I searched for different proxy solutions, and found this:
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(true);
So I added it into my code, but it doesn't seem to do what I want. I think I'm looking for a way to tell WebDriver that my ssl certificate is in x directory, please use it when accessing this site. Does anyone know how to do this?
My Test code is:
#Test
public void userSignsInAndVerifiesDrawerViews(){
driver.get("www.url.com");
waitFor(5000);
driver.findElement(By.xpath("//a[contains(text(), 'Sign in')]")).click();
waitFor(3000);
String username = "seleniumtest";
String password = "seleniumtest1";
driver.findElement(By.id("username")).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.xpath("//signin")).click();
waitFor(30000);
String signInLinkText = driver.findElement(By.xpath("//xpath")).getText();
assertEquals(signInLinkText, username);
}
Webdriver has no built in mechanism for adding a personal cert.
If you are using firefox the only way that I have found to do this is to create a firefox profile and add the certificate to it. You can then either reuse the profile when you run your tests OR, and this is my prefered option, take the cert8.db and key3.db files and add them to the profile that webdriver creates at runtime.
I am not sure how yo do this in java, but in ruby I override the layout_on_disk method of FirefoxProfile to add the extra files I required. Java has the same class so you should be able to do this same thing.
No need to overwrite the method layout_on_disk() as suggested.
You can simply load as profile a folder containing the files cert8.db and key3.db.
Selenium will complete the profile for you.
Then you can add the preferences you need to the firefox profile.
The resulting code looks like this:
FirefoxProfile firefoxProfile = new FirefoxProfile(
new File("/folder/location"));
FirefoxOptions options = new FirefoxOptions();
options.setProfile(firefoxProfile);
WebDriver driver = new RemoteWebDriver(
new URL("http://localhost:4444/wd/hub"),
options.toCapabilities());
Tested with selenium 3.5.3.
Webdriver can do this, although Derek is right and it isn't built in.
All you need to do is make a custom Trust Manager that trusts all certs and then also override the "hostname verifier" to allow a non-real domain name.
There is somewhat of an example I found on Google here:
http://grepcode.com/file/repo1.maven.org/maven2/org.seleniumhq.selenium.server/selenium-server-coreless/1.0.3/org/openqa/selenium/server/TrustEverythingSSLTrustManager.java
This is the same method you would use with Apache HC components to override SSL settings without using WebDriver. I've used this method a lot with direct HTTP posts using Apache HT components and it "appears" that from the link above , this concept should also work with WebDriver.

How to perform Basic Authentication for FirefoxDriver, ChromeDriver and IEdriver in Selenium WebDriver?

I am using the Selenium-Firefox-driver and Selenium-Chrome-Driver version 2.0a5 (Web Driver API), and I am trying to test a web app that has BASIC authentication (there is a popup that come up to authenticate the user when I hit whatever page, the popup is not part of the HTML).
Now, I need to a strategy to authenticate the user in Firefox, Chrome and IE (I'm going to import the IE Driver soon).
I was reading in few articles that I can set a Firefox profile for instance..something like:
FirefoxProfile ffProfile = new FirefoxProfile();
ffProfile.setPreference("network.http.phishy-userpass-length", 255);
WebDriver driver = new FirefoxDriver(ffProfile);
driver.get("http://username:password#hostname");
but it doesn't seem to work for me. Does anyone have a working solution for those browsers?
I got it to work with Firefox webdriver by the following:
profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", "google.com");
driver = new FirefoxDriver(profile);
driver.Navigate().GoToUrl("http://user:pwd#google.com");
True, BASIC HTTP authentication is not currently supported but I got it working now for FF and for Chrome.
The code I wrote in the questions works for those drivers. I just tried using FF3.6 as Firefox default browser (installed in Firefox folder) instead of FF4 (not supported yet). For IE, i may try to disable the authentication through Windows Registry.
This page http://code.google.com/p/selenium/issues/detail?id=34 may help.
For more portability, this can be handled by stub API and using Alert.
Example Java code (sample):
import org.openqa.selenium.Alert;
import org.openqa.selenium.security.Credentials;
public void authenticateUsing(Credentials credentials) {
private final Alert alert;
alert.authenticateUsing(credentials);
}
See also: auth_tests.py
Or by sending keys manually like:
SendKeys("user");
SendKeys("{TAB}");
SendKeys("password");
SendKeys("~"); // Enter
See also the following feature request: #453 Portable BASIC Auth at GitHub
Related:
How to send Basic Authentication headers in Selenium? at QA SE
Add this New Firefox Profile on your code
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("myProjectProfile"); //replace "myProjectProfile" with your profile"
WebDriver driver = new FirefoxDriver(myprofile);
Firefox configuration settings
This works fine without prompting any authentication when you do the following settings..
Type "about:config" on your FF url
Now type "Proxy" in the search field
Make sure "signon.autologin.proxy" is set "true" (By default
it is "false")
Load Default/Custom Chrome Profile to run tests using Selenium
WebDriver
Download chromedriver.exe
Extract the chromedriver_win_26.0.1383.0.zip folder and locate .exe file to C:/ folder
Add this Script on your JAVA code
DesiredCapabilities capability = DesiredCapabilities.chrome();
System.setProperty("webdriver.chrome.driver", "C:/chromedriver.exe");
capability.setCapability("chrome.switches", Arrays.asList("–disable-extensions"));
capability.setCapability("chrome.binary", "C:/Users/user_name/AppData/Local/Google/Chrome/Application/chrome.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data/Default");
driver = new ChromeDriver(capability);
Note: IE doesn't need profile setup to run tests because they run on Server user while Firefox and Chrome works with binary.
If you want to enable the http auth in Internet explorer, you have to edit the registry and add this (create keys if they are not present):
in HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE, create a DWORD iexplore.exe with a value of 0
in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE, create a DWORD iexplore.exe with a value of 0
Close and reopen Internet explorer
If you have a x64 IE, the path is a bit different :
HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE
There is a solution for performing authentication with Selenium 1.x by manually setting the HTTP headers at http://mogotest.com/blog/2010/06/23/how-to-perform-basic-auth-in-selenium but I don't think this is transferable to Selenium 2, as you don't have access to the headers.
According to the information here 'Basic Authentication support for Selenium 2' was added in Selenium 2 Beta 2 but looking through the source code I can only see it implemented as a way of securing Remote Selenium Servers against anonymous access.
So I think the answer is that BASIC HTTP authentication is not currently supported.
I was not able to use the basic authentication with Selenium 2 and Chrome (Due a bug with Chrome), so I created an extension for Chrome that sends the basic authentication credentials automatically (See https://chrome.google.com/webstore/detail/basic-authentication-auto/dgpgkkfheijbcgjklcbnokoleebmeokn).
Multipass extension of Firefox made automation engineers life easy. Through this, we can handle the basic authentication pop-up in any browser using any programing language. PFB the steps:
Open the Firefox browser and download the plug-in
-> https://addons.mozilla.org/en-US/firefox/addon/multipass/
Now go to the below location to get the XPI file that is the 'multipass' executable file for firefox
-> C:\Users\Your user name\AppData\Roaming\Mozilla\Firefox\Profiles\oleovwxr.extensionUser\extensions
Copy the file 'multipass#gilles.crettenand.info.xpi' from the above directory and past it to your project directory inside any folder of the resource package.
Now use the below code snippet to configure the Firefox driver.
public WebDriver config() {
System.setProperty("webdriver.gecko.driver", "Path to geco driver");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "firefox");
capabilities.setCapability(CapabilityType.PLATFORM_NAME, "WINDOWS");
capabilities.setCapability("acceptSslCerts", true);
capabilities.setCapability("marionette", true);
FirefoxProfile profile = new FirefoxProfile();
//Give the multipass path
profile.addExtension(new File("c:/your project name/src/main/resources/multipass#gilles.crettenand.info.xpi"));
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(profile);
firefoxOptions.merge(capabilities);
return new FirefoxDriver(firefoxOptions);
}
Now the main challenge is to get the UUID of the downloaded multipass extension as whenever we run it changes. So we are taking every time when run.
public void setup() throws InterruptedException {
WebDriver driver = config();
driver.get("about:debugging#/runtime/this-firefox");
Thread.sleep(4000);
String uuid = driver.findElement(By.xpath("//span[#title='MultiPass for HTTP basic authentication']/parent::li/section/dl/div/dt[contains(text(),'UUID')]/parent::div/dd")).getText();
System.out.println("My Url:::" + "moz-extension://" + uuid + "/popin.html");
driver.get("moz-extension://" + uuid + "/popin.html");
//change below URL with your URL and username and password
driver.findElement(By.id("url")).sendKeys("http://mywebsite.com");
driver.findElement(By.id("username")).sendKeys("site user name");
driver.findElement(By.id("password")).sendKeys("site password");
driver.findElement(By.xpath("//button[.='Add']")).click();
//Now change below URL with your url, note:: the domain should math with above multipass url
driver.get("http://mywebsite.com/homeLogin.html");
}
I have tested with the below selenium version selenium-java 4.1.1 and selenium-server 3.141.59.

Categories

Resources