JMeter WebDriver sampler Windows/Basic authentication

27 views Asked by At

I am trying to run a scenario using WebDriver sampler in JMeter 5.5 and my application has windows authentication. I have tried all possible ways and am not able to pass the authorization. I am using JMeter 5.5 version, with Selenium WebDriver 4.13.0 and Firefox 122.0, with groovy language.

I have tried passing the credentials in the URL and got to know that it is depricated. I tried using the Dev tools, but am getting an error message:

DevTools devTools = WDS.browser.getDevTools();
devTools.createSession();

devTools.send(Network.enable(Optional.of(10000), Optional.of(10000), Optional.of(10000)));
def auth = "admin:admin!";

String encodeToString = Base64.getEncoder().encodeToString(auth.getBytes());

Map<String, Object> headers = new HashMap<String, Object>();
headers.put("Authorization","Basic "+encodeToString);
devTools.send(Network.setExtraHTTPHeaders(new Header(headers)));

Am getting ERROR c.g.j.p.w.s.WebDriverSampler: javax.script.ScriptException: org.openqa.selenium.devtools.DevToolsException: You are using a no-op implementation of the CDP. The most likely reason for this is that Selenium was unable to find an implementation of the CDP protocol that matches your browser. Please be sure to include an implementation on the classpath, possibly by adding a new (maven) dependency of org.seleniumhq.selenium:selenium-devtools-vNN:4.13.0whereNN matches the major version of the browser you're using. error.

I also tried using the HasAuthentication method, but am getting the following error:

Predicate<URI> uriPredicate = uri -> uri.toString().contains(url);
Supplier<Credentials> authentication = UsernameAndPassword.of("admin", "admin!");

((HasAuthentication) WDS.browser).register(uriPredicate, authentication);


WDS.browser.get(url);

Error: ERROR c.g.j.p.w.s.WebDriverSampler: javax.script.ScriptException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'FirefoxDriver: firefox on windows (bbbfeb27-327f-4ad3-a18b-2c70c23059c9)' with class 'org.openqa.selenium.firefox.FirefoxDriver' to class 'org.openqa.selenium.HasAuthentication'

Request some help with either of these two methods or any other possible solution to pass the Basic authentication.

1

There are 1 answers

4
Ivan G On

When I look at FirefoxDriver JavaDoc I fail to see that it extends HasAuthentication interface so you won't be able to use UsernameAndPassword authentication object.

You will either need to switch to ChromeDriver or inject the credentials into URL.

For example this code:

WDS.sampleResult.sampleStart()
WDS.browser.get('https://guest:[email protected]/HTTP/Basic/')
WDS.log.info(WDS.browser.findElement(org.openqa.selenium.By.xpath('//p[3]')).getText())
WDS.sampleResult.sampleEnd()

Works just fine:

enter image description here

More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?