Search code examples
pythonseleniumpython-unittestheadless-browserselenium-grid2

Selenium best way to chrome headless parallel instances python


I'm getting really confused with python and selenium. I've set up both chrome and Phantomjs with selenium on mac and it's working ok.

However, I can only run phantomjs as headless, and it's getting really frustrating having to code things twice (for phantom and chrome), just so I can see what is happening. Especially, since they work quite differently.

From what I understand there are these two things:

Docker selenium - https://github.com/elgalu/docker-selenium

This allows headless firefox and chrome, using VNC to see what is happening.

Selenium Grid Extension - https://github.com/zalando/zalenium

This allows parallel execution. However, I'm wondering do I really need this, since I wrote my parallel execution routine already in unittest?

From previous research my understanding is that selenium grid doesnt really work for Python (its java based)

If anyone can set me straight on what to use that would be great.

I'm thinking to just use the chrome headless and hopefully I will still be able to do my parallel execution in unittest


Solution

  • You're mixing a bunch of things, let's clarify:

    • PhantomJS is a headless browser that uses the WebKit rendering engine (not exactly like Chrome) and it can't run with UI.
    • You don't need to code twice, you can get the browser name from a config file and work with the interface webdriver to create whichever browser you want.
    • If you want to run specifically Chrome headless, try this, though AFAIK it's in beta stages and only on Linux.
    • Running in parallel can be achieved in multiple ways (docker, grid, a test framework, etc...). Depending on your case, you should choose what suits you. In your case I think docker and a grid is an overhead and you should continue using unittest: 1. Docker does let you run Chrome with a virtual display (sort of headless), but it's specialty is in scaling fast which I assume you don't need. 2. Selenium Grid mostly used for browser, OS matrix. It doesn't matter that it's Java based because it's a standalone server you connect to using remotewebdriver in whatever language.

    So I hope it's

    set you straight

    ;)