0

How to launch specific chrome profile for Web automation using webdriverIO?

Requirement: My website is launched with the "Login with Google Option", so I want to launch it through Automation with already stored profile in chrome browser. So it will bypass the login and directly getting launched inside the App.

Tools: WebDriverIO web Automation with JavaScript

Framework: Mocha

login.spec.js file:

const { Options } = require('webdriverio/build/ChromeOptions');
const { remote } = require('webdriverio');

const options = new Options();
options.addArguments("user-data-dir=/Users/dhrumilsoni/Library/Application Support/Google/Chrome/");
options.addArguments("--profile-directory=Profile 2");
options.addArguments("--start-maximized");

describe('App Admin Portal', () => {

let browser;

  before(async () => {
    browser = await remote({
      capabilities: {
        browserName: 'chrome',
        'goog:chromeOptions': {
          args: options.args,
        },
      },
    });
    await new Promise(resolve => setTimeout(resolve, 5000));
  });

  beforeEach(async () => {
    // Wait for the browser to load the URL before each test case
    await browser.url('https://google.com');
  });

  afterEach(async () => {
    await browser.deleteSession();
  });
    
  it.only('login title verification',async () => {

        browser.pause(3000);

        try {
            const title = await browser.getTitle();
            expect(title).toEqual("TL");
          } catch (error) {
            console.error(error);
          }
    });
});

But I'm getting error post running "npx wdio" command.

Error:  Unable to load spec files quite likely because they rely on `browser` object that is not fully initialised.`browser` object has only `capabilities` and some flags like `isMobile`.

1 Answers1

0

Tools: WebDriverIO web Automation with JavaScript

Framework: Mocha

Yes, It's possible to launch the specific chrome profile using the webdriverIO.

As per my project requirement, I want to bypass the login every time. So I created chrome profile and stored my URL along with credentials to make sure it automatically logged into the Application when I launch it.

Solution approach:

wdio.conf.js

capabilities: [{
    maxInstances: 5,
    browserName: 'chrome',
    'goog:chromeOptions': {
        args:[
        'disable-web-security',
        'allow-running-insecure-content',
        'user-data-dir=/Users/dhrumilsoni/Library/Application Support/Google/Chrome/',
        'profile-directory=Profile 27'
]},

In your test,

describe("Master Test Plan", ()=>{
    
before(async ()=>{
       await browser.url('https://google.com');
       await browser.pause(5000);
    })

after(async () => {
    await browser.deleteSession();
});

it("Chrome profile launch to bypass login screen", async ()=>{

      try {
        const title = await browser.getTitle();
        expect(title).toEqual("XXXX");
      } catch (error) {
        console.error(error);
      } 
});
});