So recently I was tasked with creating a test suite for testing new instance deployments of our company’s product. We were founded in 1998 yet our product has never had a testing suite… this is beyond me but lets move forward and ensure everyone can easily get one setup for any website, product etc.
If you don’t know ruby don’t worry the language is very readable and selenium testing in general is pretty easy as long as you know basic css/html and can read some documentation.
Lets start with some basic examples to get your feet wet.
Does google search work?
#!/usr/bin/ruby
require 'selenium-webdriver'
require 'minitest/test'
require 'minitest/autorun'
class GoogleTest < Minitest::Test
def setup # Method called via autorun
@url = 'http://google.com' # The URL we are using available via @url
@driver = Selenium::WebDriver.for :firefox # WebDriver API for Firefox
end
def teardown # Method called on end
@driver.quit if @driver
end
def test_can_search # The actual test function
# All functions must begin with test_ to autorun
@driver.navigate.to @url # Navigate in FireFox to @url (google)
# id="lst-ib" this is the CSS ID for the input of the search
element = @driver.find_element(:id, 'lst-ib')
element.send_keys('abracadabra') # What are we searching for
sleep(2) # Give some time for ajaxy stuff
found_results = @driver.find_element(:id, 'resultStats') # Find resultStats id element
refute_nil(found_results) # Test if found_results is nil|undefined|null|etc
end
end
Here I hopefully commented enough to where even if the code isn’t readable you know exactly what’s going on. This base can be used to do any of your basic testing.
Output from the above example
maharris@maharris:~/Projects/Deployment_Selenium$ ruby google.test.rb
Run options: --seed 61686
# Running:
.
Finished in 7.099786s, 0.1408 runs/s, 0.1408 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
We see that there was 1 run and 1 assertion(passed test) so we now know that:
-
Google is up
-
Search is working as expected
Again, this is just a very basic example of testing using selenium and in general you would have a more robust test suite testing criteria like:
-
Are there results
-
Does pagination work
-
Other things
-
Stuff
-
Etc...
I hope to explore some more extensive QA testing in the future and look forward to sharing.