microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
63.84k stars 3.46k forks source link

[Question]: Pass NTLM authentication in API testing #17881

Open boris-meerovich-sp opened 1 year ago

boris-meerovich-sp commented 1 year ago

Your question

Hi, How can I pass NTLM authentication in API testing? Now, I have only HttpCredentials to pass and I need NetworkCredential to be passed.

My API is behind the IIS Windows Authentication.

Please, advise.

yury-s commented 1 year ago

There is no built in support for it at the moment. However, you still should be able to respond to the security challenge manually using the APIRequestContext APIs. Leaving this open as a feature request to collect more feedback.

monikandy commented 1 year ago

It would be great to have it out of the box. I have just stumbled on it and as an ugly temporary solution used powershell step with curl where I can pass -UseDefaultCredentials directly.

boris-meerovich-sp commented 1 year ago

There is no built in support for it at the moment. However, you still should be able to respond to the security challenge manually using the APIRequestContext APIs. Leaving this open as a feature request to collect more feedback.

Thanks for the response. Any chance you have any examples about forwarding credentials via APIRequestContext?

mailtogagan commented 1 year ago

It would be great to have NTLM authentication support for HTTP proxy. In our case our Web application is having NTLM authentication hence all of our scenarios are blocked as of now. I would appreciate if we can prioritize NTLM authentication support for HTTP proxy, in upcoming releases.

Abdulhasiib commented 1 year ago

It would be great to have it out of the box. I have just stumbled on it and as an ugly temporary solution used powershell step with curl where I can pass -UseDefaultCredentials directly.

I am facing the same problem with NTLM Authentication. Please could you share more information about this workaround with Curl and PowerShell? I can get it working with RestSharp by passing -UserDefaultCredentials, but couldn't find a way to pass Curl in PlayWright APIRequest.

monikandy commented 1 year ago

It would be great to have it out of the box. I have just stumbled on it and as an ugly temporary solution used powershell step with curl where I can pass -UseDefaultCredentials directly.

I am facing the same problem with NTLM Authentication. Please could you share more information about this workaround with Curl and PowerShell? I can get it working with RestSharp by passing -UserDefaultCredentials, but couldn't find a way to pass Curl in PlayWright APIRequest.

I have a TS+Pw project, I have wrapped PS part in a method:

  private static async powershellCall(endpoint: string) {
    const {exec} = require('child_process');
    const lock = `curl -Method PUT -UseDefaultCredentials -Headers @{'Accept'='application/json';} http://${process.env.ENVIRONMENT}/api/${endpoint}`;
    exec(lock, {'shell': 'powershell.exe'}, (error, stdout, stderr) => {
    });
    return exec;
  }
Abdulhasiib commented 1 year ago

It would be great to have it out of the box. I have just stumbled on it and as an ugly temporary solution used powershell step with curl where I can pass -UseDefaultCredentials directly.

I am facing the same problem with NTLM Authentication. Please could you share more information about this workaround with Curl and PowerShell? I can get it working with RestSharp by passing -UserDefaultCredentials, but couldn't find a way to pass Curl in PlayWright APIRequest.

I have a TS+Pw project, I have wrapped PS part in a method:

  private static async powershellCall(endpoint: string) {
    const {exec} = require('child_process');
    const lock = `curl -Method PUT -UseDefaultCredentials -Headers @{'Accept'='application/json';} http://${process.env.ENVIRONMENT}/api/${endpoint}`;
    exec(lock, {'shell': 'powershell.exe'}, (error, stdout, stderr) => {
    });
    return exec;
  }

Thanks for sharing code snippet. That's helpful. I have one more question. How you're passing this method to the PlayWright APIRequest?

I got working curl command for my API call, but not sure how I link it to PlayWright APIRequest!

Is there a way to pass curl to PlayWright API call or need to continue using curl only for API testing.

Thanks again for your time and support.

monikandy commented 1 year ago

Thanks for sharing code snippet. That's helpful. I have one more question. How you're passing this method to the PlayWright APIRequest?

I am not passing it to Pw API Request, it is hidden in service and I just call it as a step in test, e.g. await commonElements.unlockElementViaApi(elementGuid); - so it is rather nasty hack then universal solution to a NTLM problem :)

ChristopherVR commented 11 months ago

Any chance on this being implemented soon or is there perhaps an alternative way I can use NTLM auth when running the tests in TypeScript?

AtefBellaaj commented 10 months ago

We are facing a similar issue trying to test an api behind windows authentication NTLM

MahmoudOrban commented 10 months ago

Same challenges, Is there any update or expected release to handle this scenario

mailtogagan commented 8 months ago

@yury-s Apologies for tagging you directly. Any plans for getting this implemented in near future? Any suggestions on how to open Web Application using playwright with NTLM authentication.

prlyons commented 3 months ago

This would be very useful for my organization. NTLM is the default sign on method for us.

ssnignite commented 3 months ago

Any updates on this?

jaikumarqa commented 1 month ago

Anyone have any hack to over come this issue on playwright

Pls help me on this. thanks