Phantomime headless browser

Lately I’ve had lots of front-end testing to do and I’ve messed around with Selenium and Python’s Selenium bindings.

After building up some confidence I decided to develop a quick way of writing tests based on the two while not having to manually start a Selenium server and having easy access to most methods required for testing stuff in visually pleasing code blocks.

What do you need before trying it out?

Phantomime uses Docker to start up Selenium in a container. It supports any selenium/standalone-* images available on Docker Hub.

You’ll also need Python’s Selenium bindings.

How to use Phantomime browser

Because I’m usually lazy when it comes to writing documentations and stuff, I’ll just show commented bits of code and commands…

First you’ll need to grab Phantomime from my github repository and grab some not-so required stuff

git clone https://github.com/psyb0t/Phantomime.git phantomime
cd phantomime
./update-requirements

Now to start using it

Create a python file

% touch test_phantomime.py

Guide yourself using the following steps

Import Phantomime

from phantomime import Phantomime

Set pre-init variables and initialize

Phantomime.verbose = True
Phantomime.window_size = (2560, 1600)
Phantomime.set_driver('firefox')
Phantomime.init()

Load a page

page_source = Phantomime.load_page('http://9gag.com/')

Wait for page to be ready

if not Phantomime.wait_page_ready(10):
  sys.exit('Page failed to be ready in 10 seconds!')

Get page title

page_title = Phantomime.page_title()

Perform a scroll-down

Phantomime.scroll_page()

Take a screenshot and save it as screenshot_file.png

Phantomime.screenshot('file', 'screenshot_file')

Cute, eh? xD

Here’s the repo on my github which has the entire module explained https://github.com/psyb0t/Phantomime