The Issue

You may encounter some sites/applications that require Basic HTTP Authentication to proceed. A standard text field would entail finding the element identifier for the field and inputting text; doing this for Basic HTTP Authentication will not work. Instead, we can use a specific Ruby & Watir Webdriver method to ensure that we can bypass the authentication.

The Answer

We will be inputting the credentials for our authentication in the URL of our desired page. So here is our standard URL:

We will input the credentials in front of the https:// and before the www, which will look like username:password@.  In this case, our username is httpwatch and password will be test98auth13:

Again, the format we entered our username/password was httpwatch:test98auth13@.

The Code

Now that we understand how to bypass the authentication, lets implement our solution into an automated test script. We will click a button to reveal an image, which would ordinarily trigger the basic auth, as seen below:

124124Capture

The Basic HTTP Authentication popup window is required to access the image.

However, as we are using our Watir Webdriver method of inputting the credentials in the URL, we will bypass the basic auth alert.

The Results

We can save and run our file (BasicAuth.rb) and view the results:

  • Browser opens
  • Browser navigates to our test page with credentials in URL
  • Button to show image is clicked
  • Image presence is validated

Here is what we will see when bypassing the authentication successfully:


BASICauthcapture

The Takeaway

Tackling Basic HTTP Authentication will now be a much easier task, as simply adding your credentials in the URL will allow you to enter to your desired page. This takes out two birds with one stone in your automated tests: your URL step is also your credential validation step. Experiment with different pages/applications and see how versatile this Ruby & Watir Webdriver method is.