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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay