Home > Back-end >  How can I browse the web randomly in a Chrome instance with a logged in Chrome extension?
How can I browse the web randomly in a Chrome instance with a logged in Chrome extension?

Time:09-21

I want to test a Chrome extension and to test it I need to have it browse the web randomly and visit random pages for a long period to see if it generates any errors. You need to be logged into the extension, which is why I am not using Selenium for this as I cannot find a way to log into the extension using Selenium.

Is there a way to make Selenium act on an existing or pre-set Chrome existence? Any other options?

CodePudding user response:

You can use web-ext. You can use Firefox, google Chrome, Chromium.

You can script your browser like this.

import webExt from 'web-ext';

webExt.cmd.run({
  // These are command options derived from their CLI conterpart.
  // In this example, --source-dir is specified as sourceDir.
  firefox: '/path/to/Firefox-executable',
  sourceDir: '/path/to/your/extension/source/',
}, {
  // These are non CLI related options for each function.
  // You need to specify this one so that your NodeJS application
  // can continue running after web-ext is finished.
  shouldExitProgram: false,
})
  .then((extensionRunner) => {
    // The command has finished. Each command resolves its
    // promise with a different value.
    console.log(extensionRunner);
    // You can do a few things like:
    // extensionRunner.reloadAllExtensions();
    // extensionRunner.exit();
  });

There should be an option to define --start-url. You can make this a random url with some programming... Not able to test it now, but you should be able to make it work

Or you just run from the commandline web-ext run --start-url www.mozilla.com

  • Related