Firefox NTLM not working when Firefox web driver is used


#1

Hello:
We want to test firefox with our internal IIS site. However, when we open firefox manually and use the same URL that we use in the instantiation, NTLM passthrough works. When We run the script, the user name and password is still being requested, causing the test to fail. We have successfully enabled NTLM in IE11, Edge and Chrome. Firefox is the only browser that seems to have a problem with this and it is only when the Firefox driver is in control.Is there anything we can enable on the driver side to make this work?


#2

As far as I know you can setup trusted URIs for NTLM access globally for Firefox (see here). Now the way you described above sounds like you’ve pretty much done something similar.

The reason why it might fails with the geckodriver is due to a lacking profile setting or an issue with the driver itself.

Anyways, perhaps meanwhile this may be used as an workaround

Alert alert = driver.switchTo().alert();
alert.sendKeys(yourUsername + Keys.TAB.toString()+yourPassword);
alert.accept();

Now you actually most likely only want to do this for Firefox. So to do so, from inside a test file you have access to the inherited TestNgTestBase class which provides a prop called endpointBrowserName.
So here’s an, untested sample, of how you could modify your open method.

class MyTest extends TestNgTestBase {
  @Test
   public void DemoTest() {
     WebDriver driver = getDriver();
     YourPO po = new YourPO(driver);

     po.open("https://your.url", this.endpointBrowserName);
   }
}

// in the po file
class YourPO {
  ...

  public YourPO open(String url, String browser) {
        this.driver.get(url);

        if (browser == "firefox") {
            Alert alert = driver.switchTo().alert();
            alert.sendKeys("yourUsername" + Keys.TAB.toString()+"yourPassword");
            alert.accept();
        }

        return this;
    }
  ...
}

Even if you get it to work with auto NTLM handshakes in whatever way, I’d propose to create at least one fallback test which makes use of manual auth. The reason is that profiles might get screwed up for whatever reason, e.g client misconfiguration for users. So you want to make sure that in worst case manual logging always works.


#3

Thanks for the help!
–Michele


#4

Hi. I tried to implement the code above and ran into some problems. Can you assist? I am getting compile errors in the test.java file.I am a bit fuzzy how I should fix it. Thanks for your help!

CodeErrorTestFile POCode


#5

hey there @micheleaz.

I’m super sorry but my sample was wrong a bit. As you see the open method now takes 2 arguments and your call in the smoke test just passes one. So instead of the two home calls they should be like this:

home.open("http://172.31.30.240/sep19/Projects/Summary/?project_id=6", this.endpointBrowserName);

#6

Hi. Thanks but that didn’t work. Webtestit would not launch the browser…

Cleaning Project…
Cleaned Project.
Setting up local WebDrivers …
Starting test run…
[INFO] Scanning for projects…

[INFO]
[INFO] ------------------------------------------------------------------------

[INFO] Building sepsmoke 1-0
[INFO] ------------------------------------------------------------------------

[INFO]

[INFO] — maven-resources-plugin:3.0.2:resources (default-resources) @ sepsmoke —

[INFO] Using ‘UTF-8’ encoding to copy filtered resources.

[INFO] skip non existing resourceDirectory C:\Users\mdashiell\Documents\sepsmoke\src\main\resources

[INFO]
[INFO] — maven-compiler-plugin:3.7.0:compile (default-compile) @ sepsmoke —

[INFO] No sources to compile

[INFO]
[INFO] — maven-resources-plugin:3.0.2:testResources (default-testResources) @ sepsmoke —

[INFO] Using ‘UTF-8’ encoding to copy filtered resources.

[INFO] Copying 11 resources

[INFO]
[INFO] — maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ sepsmoke —

[INFO] Changes detected - recompiling the module!

[INFO] Compiling 29 source files to C:\Users\mdashiell\Documents\sepsmoke\target\test-classes

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/dataWarehouseSmoke.java:[19,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;
required: java.lang.String,java.lang.String
found: java.lang.String
reason: actual and formal argument lists differ in length

[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/ProjectPlanSmoke.java:[19,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;
required: java.lang.String,java.lang.String
found: java.lang.String
reason: actual and formal argument lists differ in length
[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/reportsSmoke.java:[18,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;
required: java.lang.String,java.lang.String
found: java.lang.String
reason: actual and formal argument lists differ in length
[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/MessagesSmoke.java:[20,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;
required: java.lang.String,java.lang.String
found: java.lang.String
reason: actual and formal argument lists differ in length
[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/metricsSmoke.java:[19,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;
required: java.lang.String,java.lang.String

found: java.lang.String
reason: actual and formal argument lists differ in length
[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/fmeaSmoke.java:[19,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;
required: java.lang.String,java.lang.String
found: java.lang.String
reason: actual and formal argument lists differ in length
[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/synthesisExplorerSmoke.java:[18,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;
required: java.lang.String,java.lang.String
found: java.lang.String
reason: actual and formal argument lists differ in length
[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/ProjectSummary.java:[18,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;
required: java.lang.String,java.lang.String
found: java.lang.String
reason: actual and formal argument lists differ in length
[INFO] 8 errors

[INFO] -------------------------------------------------------------

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

[INFO] Total time: 1.770 s
[INFO] Finished at: 2019-10-01T09:39:50-07:00

[INFO] Final Memory: 15M/60M
[INFO] ------------------------------------------------------------------------

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile (default-testCompile) on project sepsmoke: Compilation failure: Compilation failure:
[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/dataWarehouseSmoke.java:[19,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;
[ERROR] required: java.lang.String,java.lang.String
[ERROR] found: java.lang.String
[ERROR] reason: actual and formal argument lists differ in length
[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/ProjectPlanSmoke.java:[19,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;
[ERROR] required: java.lang.String,java.lang.String
[ERROR] found: java.lang.String
[ERROR] reason: actual and formal argument lists differ in length
[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/reportsSmoke.java:[18,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;
[ERROR] required: java.lang.String,java.lang.String
[ERROR] found: java.lang.String
[ERROR] reason: actual and formal argument lists differ in length

[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/MessagesSmoke.java:[20,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;
[ERROR] required: java.lang.String,java.lang.String
[ERROR] found: java.lang.String
[ERROR] reason: actual and formal argument lists differ in length
[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/metricsSmoke.java:[19,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;
[ERROR] required: java.lang.String,java.lang.String
[ERROR] found: java.lang.String
[ERROR] reason: actual and formal argument lists differ in length

[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/fmeaSmoke.java:[19,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;
[ERROR] required: java.lang.String,java.lang.String
[ERROR] found: java.lang.String
[ERROR] reason: actual and formal argument lists differ in length
[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/synthesisExplorerSmoke.java:[18,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;
[ERROR] required: java.lang.String,java.lang.String
[ERROR] found: java.lang.String
[ERROR] reason: actual and formal argument lists differ in length
[ERROR] /C:/Users/mdashiell/Documents/sepsmoke/src/test/java/uitest/tests/ProjectSummary.java:[18,13] method open in class uitest.pageobjects.HomePo cannot be applied to given types;

[ERROR] required: java.lang.String,java.lang.String
[ERROR] found: java.lang.String
[ERROR] reason: actual and formal argument lists differ in length
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException


#7

according to this is sounds like you still have somewhere a place where you’re calling open with just one parameter. Check your other tests as well, they might have that somewhere with the old 1 param approach.


#8

You were right that I had a one parameter open hanging around in there. Here is the issue now. I have added all of the specified code and everything compiles, but the username and password are not being handled and selenium will not log in.


#9

Hi. One more fun fact :slight_smile: I tried to include the code
Alert alert = driver.switchTo().alert();
alert.sendKeys(yourUsername + Keys.TAB.toString()+yourPassword);
alert.accept();
In my test file. I got the following error:

I imported the following so it would compile:
import org.openqa.selenium.Alert;
import org.openqa.selenium.Keys;
Thank you for all your help! Do you have any more ideas on how to handle Firefox?


#10

Hi @micheleaz!
What you could also try to handle the windows authentication window is with the help of the AutoIt. Using this tool, you can quickly create a script that will send your username and password details and handle the login window easily with Firefox.
Download the tool from here, open up the SciTE ScriptEditor and create a simple script that will send the keys to the username and password fields. For example:

After you have finished, save the script in .au3 format. The next step is to convert it into .exe format. For that you need to do right click on the .au3 file and select “ Compile Script “, and the same-named .exe file will be created. This is the script file that we will use in the test.

compile

A detailed guide on how to create your scripts with AutoIt can be found here
After you have created your script, include it in your test.
After the step where you open the browser and get to the credentials prompt add the following line ( Runtime.getRuntime().exec("C:\\Path\\to\\the\\scrpit.exe"); ) in the try/catch block:

  try {
		Runtime.getRuntime().exec("C:\\Path\\to\\the\\scrpit.exe");
		} catch (IOException e) {
			//  Print the error stack trace if this fails
			e.printStackTrace();
		}

This should run the previously created script and fill out the credentials for you, and you can continue with your testing :slight_smile:
Kind Regards!


#11

Hi again @micheleaz
It seems like that, in the meantime, the support for native auth dialogs is out of scope for the WebDriver. This is why you are getting this User prompt of type promptUserAndPass is not supported error.
Now, the code

 Alert alert = driver.switchTo().alert();
            alert.sendKeys("yourUsername" + Keys.TAB.toString()+"yourPassword");
            alert.accept();

wont work as a result of that. The issue ragarding this is raised on GitHub and you can follow the updates there.
For handling authentication, there is only the way to send user/password info in the .open() method, for example:

@Test
   public void DemoTest() {
     WebDriver driver = getDriver();
     YourPO po = new YourPO(driver);

     po.open("https://username:[email protected]");

or the usage of 3rd party tools like the autoIT example above, but this is not recommended, hence the script is stored locally, and running a test on a remote endpoint would result in a failure.


#12

OK Thank you! We have back burnered Firefox testing at this time.
Thanks!
Michele