How to handle basic authentication with protractor?

前端 未结 7 1080
长情又很酷
长情又很酷 2020-12-25 13:08

I\'m trying protractor to write a few tests in a non angular application. I have to login in a page trough basic authentication in google chrome, but i have no idea how.

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-25 13:48

    As of version 59 Chrome no longer supports URLs with embedded credentials.

    To work around this I wrote the authenticator-browser-extension Node module, which might be useful if you're using Protractor, WebDriver.io or similar test runners.

    To use the module install it from npm:

    npm install --save-dev authenticator-browser-extension
    

    And import in the protractor.conf.js:

    const { Authenticator } = require('authenticator-browser-extension');
    
    exports.config = {
        capabilities: {
            browserName: 'chrome',
    
            chromeOptions: {
                extensions: [
                    Authenticator.for('username', 'password').asBase64()
                ]
            }
        },
    }
    

    Pro tip: remember not to commit your credentials with your code, consider using env variables instead.

    Hope this helps!

    Jan

提交回复
热议问题