angular2+ using Protractor with Modify Header Value (HTTP Headers) plug-in to complete Windows Authorization authentication

Source: Internet
Author: User

The new company in the second week, received a e2e test task, two days to write all the test conditions are finished, the results of the remaining three days are stuck in the Windows authorization authentication here.

Let's start with the logic of the company project authorize.

The first step, after entering the URL, redirects to the company's unified login site, which requires Windows Authorization.

Second, if the verification succeeds, it will jump to the company SSO website and return the cookie relative to the website.

Third, use cookies to access the websites that users want to visit

Failure idea One:

Just started very lazy want to use protractor to catch the input box and login button just fine. It turns out that the idea is too naïve. Because the Windows Authorization dialog box inside the browser does not exist on the DOM, Protractor is not caught in this window.

That's understandable, change the plan.

Failure Idea II:

Stackoverflow.com Dafa Good, after searching a circle, find the second method is to enter Http://username:[email protected] in the URL.

The results found not good use, carefully read the post, found that this is 2017 before the post, so I went to the Chrome website to check the relevant information, found that this method in V59 is banned.

Okay, next scenario.

Failure idea Three:

This is the time to think I can bypass the certification, directly take a cookie to verify it?

In this project, I sadly found that protractor can not do this, there is no way to configure the cookie inside the header, even if configured, and did not follow the logic to run.

such as Browser.manage (). Addcookie (), this method has not run according to my expectations, do not know if there is a great God can guide me

Maybe I didn't find the right way to do it ...

Failure Idea four:

is still stackoverflow.com, this method (Link) I did not succeed, do not know how the foreign big God is how to do, theoretically should be feasible. Here I can tell you the idea of this solution, this idea is successful, I will say the solution.

The core of this approach is to add a layer of proxy, when the Protractor launch, Chrome launches and visits to our testing site, then add a layer in the middle to configure the header and add a cookie to it.

This is the http-proxy in this, when the protractor started, all the information sent through the proxy added the corresponding header, so that the implementation of the Bypass Authentication page login site.

Results...... Too complicated, my brain has been down ...

So change the plan.

Failure Idea Five:

At this time, I think the Windows Authrization window will jump out anyway, then I will simulate the keyboard percussion:

1. Enter your account

2. Press the TAB key

3. Enter your password

4. Press the TAB key

5. When the login button gets the focus, press the ENTER key to

So I tried Robotjs and robot-js, the result is tragic, alas, this time the feeling is despair, really despair.

The groping process of successful scheme

One day left this week, eating a banana (program apes need to eat bananas to relieve stress ah)

Under the care and encouragement of my colleagues, I found another solution without being knocked down.

That's the challenge of using Chrome's plugin, which is a multi-fold, but it solves the problem.

Configuring the process:

Because we visit the site, if you want to skip the verification interface, add a direct header with a legitimate cookie.

1. So I downloaded a chrome extension difference Modify Header Value (HTTP Headers)

2. After the add is finished, open the plugin, URL that column add URL, header that column write Cookie,value that column to fill in the value of the cookie, point to the right of the plus button to save

3. After the plug-in must be started, access to the site we want to test, found that no password to enter the site

Problem found:

When you run the command ng e2e with ANGULAR-CLI, Chrome starts normally, but the plugin is not loaded, so the test is unsuccessful.

Survey questions:

The reason for this problem is that protractor just started the selenium inside the Chrome.exe, so he is very clean environment, just loaded a automation plug-in. The plugins we previously configured in Chrome were not loaded at all

Solve the problem:

Still search through StackOverflow method to load plug-in

Modify the code inside the Protractor.conf.js and add the code inside the Exports.config.

Exports.config = {allscriptstimeout:11000, specs: ['./e2e/**/*.e2e-spec.ts '], capabilities: {' browsername ': ' Chrome ', ' chromeoptions ': {' args ': ['--load-extension=c:/users/<user name>/appdata/local/google/chrome/us Er data/profile 1/extensions/cbdibdfhahmknbkkojljfncpnhmacdek/0.1.4_0 ', '--user-data-dir=c:/users/<user Name >/appdata/local/google/chrome/user Data '}}, Directconnect:true, ...}

--load-extension is the path that specifies the extention, and the following Cbdibdfhahmknbkkojljfncpnhmacdek is the name of the encrypted extension

--user-data-dir is specifying the history of the Chrome records we use, and if you don't specify this file, you will find that when Protractor launches the browser, even if the plugin is loaded, the previous saved data in the plugin will not be read


When you run the E2E test, you will see that the plugin is loaded, and that the cookie we set earlier is visible.

And the verification has been passed automatically.

Change a good solution:

Just had an idea to verify that this method is better

In fact, we've already opened Chrome, signed in to the website, and we've chosen to save the account and password, and we know that it's good to make sure that chrome from protractor starts reading the user files.

So I deleted the third-party plugin and changed the Exports.config as follows

Capabilities: {    ' browsername ': ' Chrome ',    ' chromeoptions ': {      ' args ': ['--user-data-dir=c:/users/yli135/ Appdata/local/google/chrome/user Data '    }}  ,

When this is done, protractor-enabled Chrome will read our previous login information and jump to the interface we want to test.

The solution is just a compromise, because when we first test, we need to open chrome and enter the account password and save it.

Hope to have a solution to the problem of the great God can share the experience, thank you!

Hope to be helpful to everyone

Happy testing!

angular2+ using Protractor with Modify Header Value (HTTP Headers) plug-in to complete Windows Authorization authentication

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.