autoauth firefox plugin didn't work - selenium

Good day to all.
I'm use Selenium WebDriver to automatically test execute. But on development site using HTTP base autentification. I found AutoAuth addon for Firefox. It save login/password and don't need type credentional each time.
But this plugin don't save credentions. I'm reinstall addon and firefox, delete cookie, but nothing. On this machine in other user plugin work successfylly. Maybe, anybody have and resolve this problem?
To author of addon I wrote already.
Way:https://login:passwd#host don't help too...

Do you mean plugin not working on invoking with webdriver? simple way to create profile and call that provide in webdriver.
Here is the way to create firefox profile. Install that add-in and save credentials.
Call above saved profile in webdriver
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("selenium");
WebDriver driver = FirefoxDriver(profile);
Thank You,
Murali

If it's a HTTP Basic Authentication, then you can set the credentials in the URL. Note that it requires to set the "network.http.phishy-userpass-length" preference to enable it.
Here is a working example with Selenium / Firefox / Python:
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference("network.http.phishy-userpass-length", 255)
driver = webdriver.Firefox(profile)
driver.get("http://admin:admin#the-internet.herokuapp.com/basic_auth")

The approach I've used very successfully is to set up an embedded Browsermob proxy server (in Java code) and register a RequestInterceptor to intercept all incoming requests (that match the host / URL pattern in question).
When you have a request that would otherwise need Basic auth, add an Authorization HTTP header with the credentials required ('Basic ' + the Base64-encoded 'user:pass' string. So for 'foo:bar' you'd set the value Basic Zm9vOmJhcg==)
Start the server, set it as a web proxy for Selenium traffic, and when a request is made that requires authentication, the proxy will add the header, the browser will see it, verify the credentials, and not need to pop up the dialog.
You won't need to deal with the dialog at all.
Other benefits:
It's a pure HTTP solution, it works the same across all browsers and operating systems.
No need for any hard-to-automate add-ons and plugins, any manual intervention.
No need for custom profiles, custom preferences etc.
You control credentials in your test code, and don't store them elsewhere.

Related

Selenium Webdriver with Chrome browser not displaying authentication pop-up

I am automating an internal application of my client which is having LDAP authentication.
I am using Selenium 3.141.59 with C#, Chrome browser 78.
Issue:
When I have open browser manually and place url then browser displaying sign-in Pop-up to enter the userID and password. (refer screenshot)
Same time when Selenium launch browser instance then navigate to same url, it's not showing any sign-in pop-up.
Due this I was unable to continue next steps in automation.
I have tried send the userID and password along with url as blow but it's also not redirecting.
https://userID:password#url
Can anyone help me, how to resolve this issue.
What you have tried is not supported any more. You now have to include authentication headers in requests. In your case I would recommend to set up a proxy which would add headers to all outcoming messages of your browser
For example you can use Browsermob Proxy that you can configure just in your tests. Some details of how basic authentication works you can find here. It is solution for Java, however you can find which headers to set up and which values to assign (In short: header - Authorization: Basic username:password Realm="" where username:password is credentials pair encoded in Base64).
This also might be useful for you: How do I encode and decode a base64 string?
UPD: This is solution for Python Selenium.

SPNEGO authentication with Selenium Web Driver

I have SPNEGO authentication for my applications and am doing automated testing using selenium HtmlUnitDriver.
I have tried running the browser automation code inside login context of SPNEGO authentication, but it seems like it is not working,
The body of the lambda is in authentication context already. And SPNEGO is working for REST calls, but not for HtmlUnitDriver.
myACtion -> {
WebDriver driver = new HtmlUnitDriver();
driver.navigate().to(url);
}
Subject.doAs(loginContext.getSubject(), myAction);
If someone can tell me how to use SPNEGO keytab authentication with HtmlUnitDriver in selenium, I would really appreciate.
There is no support so far.
If you like to see this supported i can offer this:
implement a complete working minimal sample using only org.apache.httpcomponents 4.5.10 (maybe this might help https://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html)
open a HtmlUnit issue on github and provide your sample code
i will add the required support to HtmlUnit

How can I make testcafe to copy and use same headers as the actual website?

I am running testcafe tests on an authentication page and I can see that testcafe is modifying/removing/adding the headers when sending the requests to the website and this is blocking me to do 2FA on this page
As soon as I got the issue, I tried to do the automation with Selenium just to confirm it is testcafe issue. As selenium doesn't create a proxy to insert the js scripts and automate the website I could do the automation with selenium, but I want to use testcafe as the site is developed in react.
await t.typeText(this.emailInput, config.userEmail)
.click(this.nextButton)
.typeText(this.passwordInput, config.userPassword)
.click(this.nextButton)
.click(this.otpOption)
.typeText(this.otpInput, this.token)
.click(this.signinButton)
}
When clicking on the next button I should have the 2FA form asking for the code, but I got a page saying was not possible to do the authentication (Something wrong happened) and I saw the response code for the BeginAuth endpoint was 222 without any response instead of 200.
The URL is that I am using to authenticate looks like this one:
https://login.microsoftonline.com/client uuid/oauth2/authorize?response_type=code%20id_token&response_mode=form_post&client_id=client uuid&scope=openid&x-client-Ver=4.0.0
Testcafe team found out this is a bug on testcafe-hammerhead, they have fixed and it is going to be included in the next release.
https://github.com/DevExpress/testcafe-hammerhead/issues/2052
For now I am generating the cookie in the automation and sending it in the header.

SFDC application asking for 2 step verification for each Selenium Run

Currently I am working on some Automation testing on Salesforce using Selenium webdriver.Salesforce system asks for a two step verification code(mobile/email OTP) apart from the usual credentials.Now, once you verify the user with the OTP, the application supposedly saves it in the cookies. So, from next instances only user id-pwd combination is sufficient to logon.
So, for that I have created a custom profile in firefox and tried to launch it through my code.But each time I am running it, a new temp profile is getting created where the cookie details are not saved already.
This is the snippet of the code:
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("SFDC");
WebDriver driver = new FirefoxDriver(profile);
When I am trying to log in manually this(2 step verification) is not happening.The automated execution was working properly before 27th Jan.
Can you please help?
You might want to look at this post in the Salesforce Stack Exchange: https://salesforce.stackexchange.com/questions/107027/selenium-testing-two-factor-authentication-problems/107368
There they have a solution where you can disable the 2-factor authentication by white-listing your IP in Salesforce. It worked for me.

How do you test pages that require authentication with Selenium?

I need to test a web application using Selenium. The app is fairly common in its setup: it requires signing in for most of the functionality to be exposed. Upon loading a page, if the user is not authenticated, it will redirect to a login form and then back to the requested page once credentials are supplied.
What's the usual way to go around this with Selenium? I take it people are not logging in on every single test as this would cause significant overhead on big test suites. Is there a way to set up a session in a test and then use the cookie information for subsequent tests, or do a conditional sign-in (without incurring in massive code repetition!)?
I am using PHPUnit with Selenium ATM.
Thank you!
Gonzalo
(I'm using C#+NUnit+Selenium RC)
Most of the time, each test goes through the login form. However, if I'm writing a series of tests that are very short (< 10 seconds each) and there are a lot of them, I usually share the same browser instance across tests by moving the selenium start\close calls from the SetUp\TearDown methods to the Test Fixture SetUp\TearDown methods. This avoids the cost of re-authenticating as well as the cost of launching a new browser every time. I'm sure you can do something similar with PHPUnit.
If this is basic http auth you can use the username/password with the url request as documented in the Selenium FAQ: http://wiki.openqa.org/display/SEL/Selenium+Core+FAQ#SeleniumCoreFAQ-HowdoIuseSeleniumtologintositesthatrequireHTTPbasicauthentication%28wherethebrowsermakesamodaldialogaskingforcredentials%29%3F
How do I use Selenium to login to
sites that require HTTP basic
authentication (where the browser
makes a modal dialog asking for
credentials)?
Use a username and password in the
URL, as described in RFC 1738: Test
Type open
http://myusername:myuserpassword#myexample.com/blah/blah/blah
Note that on Internet Explorer this
won't work, since Microsoft has
disabled usernames/passwords in URLs
in IE. However, you can add that
functionality back in by modifying
your registry, as described in the
linked KB article. Set an
"iexplore.exe" DWORD to 0 in
HKEY_CURRENT_USER\Software\Microsoft\Internet
Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE.
If you don't want to modify the
registry yourself, you can always just
use Selenium Remote Control, which
automatically sets that that registry
key for you as of version 0.9.2.