Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I'm using Selenium (python) to automate some tests on websites. Because selenium's API is quite limited, I'm using a web extension to perform advanced javascript tests.

What would be the proper way to communicate results from the webextension back to the python script? So far, I'm passing them trough console.log messages, but it fails if the target site overrides console.log() (and it seems quite hack-y anyway).

1 Answer

0 votes
by (62.9k points)

I'd probably tackle this the following way:

Firstly, if you have got control over the web extension's source code, then you would add a simple method that serializes your data into a nice format, then stores it into the browser's native storage.

Note: If you haven't worked with this, don't worry, there are multiple examples on the internet. You have got to keep into consideration that you are also restricted to a 5-10 MB native storage limit for your data (varying across browsers).

Secondly, you'd have to read the localStorage values. I see 2 ways to do this:

  1. Make use of your underlying Selenium-based framework's API (usually all of them have some kind of localStorage/cookies API call). For example: in most frameworks you'll be able to use the .execute() command (or executeScript) to set the native storage value: browser.execute('localStorage.setItem('PerduData', <dataObject>);');

  2. Use plain JavaScript within your scripts to set the same local storage value

Browse Categories

...