Testing is often the last thing that Developer thinks about. But with Selenium WebDriver it’s easy and even spectacular while running.
I choose python, since it’s native in Ubuntu. First we need to install selenium driver:
pip install selenium
And we can check if it works. Let’s create a python file test1.py
sudo touch test1.py sudo chmod +x test1.py sudo vi test1.py
copy and paste this contetns
#!/usr/bin/env python from selenium import webdriver driver = webdriver.Chrome() driver.get('http://google.com'); inputElement = driver.find_element_by_name("q") inputElement.send_keys("selenium")
then run your first test
As a result we should see the browser window open and Google page with selenium phrase searched.
What we just did
We created a driver for Chrome browser.
driver = webdriver.Chrome()
Next we tell the browser to open url
And then we get the search input by it’s name and enter “selenium” phrase.
inputElement = driver.find_element_by_name("q") inputElement.send_keys("selenium")
You can read some more about WebDriver.
Ok, let’s go to Automatic tests with Selenium – part #2.