• +43 660 1453541
  • contact@germaniumhq.com

Writing Your First Selenium-Germanium Test




Writing Your First Selenium-Germanium Test

Let’s assume someone finally convinced you it would be a good idea to have some browser integration tests using Selenium/Germanium. Where do you go from here?

In this article we’ll show the basics of how easy it is to get started with Germanium.

If you know Selenium, you need to download the binary drivers, the browsers, etc. A daunting task, and all these will need maintainance. You will need to update the drivers from time to time, as well as Selenium.

Germanium offers a way simpler way to do these tests. In order to install Germanium, all that is needed is:

1
pip install germanium

That’s it!

Germanium depends on Selenium and it will download it as well. Also, it packages the drivers in, and will add them automatically to the PATH, so here is no other setup required. We can jump straight in writing our first test.

We’ll include germanium, and open a browser:

1
2
3
from germanium.static import *

open_browser('chrome')

In this new browser instance that we obtained, we will go to germaniumhq.com.

1
go_to('http://germaniumhq.com')

Then we will check the title of the page:

1
assert get_germanium().title == 'Germanium'

You might see that the title is being read from the Germanium instance. Actually all the calls to the Germanium instance that are not part of the API, are just deferred to the WebDriver API. The previous code is actually equivalent to:

1
assert get_webdriver().title == 'Germanium'

Ok, we got to our website, and we checked the title, in order to do a basic interaction, we’ll just click a link for documentation:

1
click(Link('API Documentation'))

Then we wait for the new page to load and assert that the page contains a "Table of Contents" since it should be loaded:

1
2
get_germanium().wait_for_page_to_load()
assert Text("Table of Contents").exists()

Then obviously we need to close the browser:

1
close_browser()

Final Script

You can download it from here.

1
2
3
4
5
6
7
8
9
10
11
12
13
from germanium.static import *

open_browser('chrome')
go_to('http://germaniumhq.com')

assert get_germanium().title == 'Germanium'

click(Link('API Documentation'))

get_germanium().wait_for_page_to_load()
assert Text("Table of Contents").exists()

close_browser()