DEV Community

Cover image for Selenium Webdriver - how to bypass server's basic authentication popup
Alan Schio
Alan Schio

Posted on

4

Selenium Webdriver - how to bypass server's basic authentication popup

Are you entering on E2E/Automated test world with selenium-webdriver and had faced this issue:

You need to access a page which has basic authentication popup, a secure server.

Basic auth popup

Well research and found how to do this was a little harsh, so this is a quick guide for you to don't suffer like i did.

The secret is the createCDPConnection. With selenium-webdriver we need to get to the browser api and perform a register


const { Builder, By } = require('selenium-webdriver');
const Chrome = require('selenium-webdriver/chrome');
const assert = require("assert");
const url = `https://my.server.com/`

describe('Server with basic auth', function () {

  before(async function () {
    driver = await new Builder().forBrowser('chrome').build();
  });

  beforeEach(async () => {
// this is what does the trick
    const connection = await driver.createCDPConnection('page');
    await driver.register("username", "password", connection);
// now you can go the url safety
    await driver.get(url);
  })


  it('Bypass the popup', async function () {
    const message = await driver.findElement(By.className("heading")).getText();
    assert.equal('Welcome!', message);
  })
  after(function () {
   await driver.quit()
  })
})

Enter fullscreen mode Exit fullscreen mode

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay