Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SarahElson/6c45d4ecd3aa0b02a67bf1d80ec99792 to your computer and use it in GitHub Desktop.
Save SarahElson/6c45d4ecd3aa0b02a67bf1d80ec99792 to your computer and use it in GitHub Desktop.
Getting Started With Automation Testing Using Selenium Ruby
require 'selenium-webdriver'
require 'test-unit'
class EcommerceTests < Test::Unit::TestCase
def setup
username= "{LAMBDATEST_USERNAME}"
accessToken= "{LAMBDATEST_ACCESS_KEY}"
gridUrl = "hub.lambdatest.com/wd/hub"
capabilities = {
'LT:Options' => {
"user" => username,
"accessKey" => accessToken,
"build" => "Ecommerce Test v.1",
"name" => "Ecommerce Tests",
"platformName" => "Windows 11"
},
"browserName" => "Firefox",
"browserVersion" => "100.0",
}
@my_driver = Selenium::WebDriver.for(:remote,
:url => "https://"+username+":"+accessToken+"@"+gridUrl,
:desired_capabilities => capabilities)
@url = "https://ecommerce-playground.lambdatest.io/"
@wait = Selenium::WebDriver::Wait.new(:timeout => 30)
#get url
@my_driver.get(@url)
@my_driver.manage.timeouts.implicit_wait = 30
end
def test_search_functionality_should_yield_results
@wait.until{@my_driver.title.include? "Your Store"}
search_box = @my_driver.find_element(:name, "search")
# First test assertion - title has loaded
assert_equal("Your Store", @my_driver.title.to_s)
search_box.clear
search_box.send_keys("phone")
search_box.submit
sleep(5)
search_title = @my_driver.find_element(:xpath, '//*[@id="entry_212456"]/h1').text
# Second test assertion - title has loaded
assert_equal("Search - phone", search_title)
end
def teardown
@my_driver.quit
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment