Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.lock
*.lock
.idea
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
source "https://rubygems.org"

# gem "rails"
gem 'selenium-webdriver', '~> 4.1', '>= 4.1.0'
gem 'selenium-webdriver', '~> 4.38', '>= 4.38.0'
147 changes: 55 additions & 92 deletions driver-close.rb
Original file line number Diff line number Diff line change
@@ -1,104 +1,67 @@
require 'selenium-webdriver'
require 'test/unit'

class LtTest < Test::Unit::TestCase
def setup
username = ENV["LT_USERNAME"] || "{username}"
access_key = ENV["LT_ACCESS_KEY"] || "{accessToken}"
grid_url = "https://#{username}:#{access_key}@hub.lambdatest.com/wd/hub"

# Chrome Options (Selenium 4 style)
options = Selenium::WebDriver::Options.chrome
options.browser_version = "latest"
options.platform_name = "Windows 10"

class LtTest < Test::Unit::TestCase
"""
LambdaTest selenium automation sample example
Configuration
----------
username: Username can be found at automation dashboard
accessToken: AccessToken can be generated from automation dashboard or profile section
# LambdaTest options
lt_options = {
"project" => "Ruby Chrome Multi-Tab Test",
"build" => "LambdaTest ruby google search build",
"name" => "LambdaTest ruby google search name",
"network" => false,
"visual" => false,
"video" => true,
"console" => false
}
options.add_option('LT:Options', lt_options)

# Start driver
@driver = Selenium::WebDriver.for(:remote, url: grid_url, capabilities: options)
end

Result
-------
Execute Ruby Automation Tests on LambdaTest Distributed Selenium Grid
"""
def test_Login
puts("Opening multiple tabs test...")
@driver.navigate.to("https://lambdatest.github.io/sample-todo-app/")
@driver.execute_script("window.open('https://google.com/')")
@driver.execute_script("window.open('http://www.pdf995.com/samples')")


def setup
"""
Setup remote driver
Params
----------
platform : Supported platform - (Windows 10, Windows 8.1, Windows 8, Windows 7, macOS High Sierra, macOS Sierra, OS X El Capitan, OS X Yosemite, OS X Mavericks)
browserName : Supported platform - (chrome, firefox, Internet Explorer, MicrosoftEdge)
version : Supported list of version can be found at https://www.lambdatest.com/capabilities-generator/
tabs = @driver.window_handles
assert_equal(3, tabs.size, "Expected 3 tabs but found #{tabs.size}")
sleep(1)

Result
-------
"""
username= ENV["LT_USERNAME"] || "{username}"
accessToken= ENV["LT_ACCESS_KEY"] || "{accessToken}"
gridUrl = "hub.lambdatest.com/wd/hub"

caps = {
:browserName => "chrome",
:version => "latest",
:platform => "win10",
:name => "LambdaTest ruby google search name",
:build => "LambdaTest ruby google search build",
:network => false,
:visual => false,
:video => true,
:console => false
}

puts (caps)
# URL: https://{username}:{accessToken}@hub.lambdatest.com/wd/hub
@driver = Selenium::WebDriver.for(:remote,
:url => "https://"+username+":"+accessToken+"@"+gridUrl,
:desired_capabilities => caps)
end

# Close last tab
@driver.switch_to.window(@driver.window_handles.last)
@driver.close
assert_equal(2, @driver.window_handles.size)

# Close another tab
@driver.switch_to.window(@driver.window_handles.last)
@driver.close
assert_equal(1, @driver.window_handles.size)

def test_Login
"""
Setup remote driver
Params
----------
Execute test: navigate to https://lambdatest.github.io/sample-todo-app/
Result
-------
print Success Message
"""
puts("Opening 3 tabs")
sleep(2)
@driver.get("https://lambdatest.github.io/sample-todo-app/")
@driver.execute_script("window.open('https://google.com/')")
@driver.execute_script("window.open('http://www.pdf995.com/samples')")
tabs = @driver.window_handles
assert_equal(3, tabs.size, "Expected 3 tabs but found " + tabs.size.to_s)
sleep(2)
@driver.switch_to.window(@driver.window_handles.last)
@driver.execute_script("window.close('http://www.pdf995.com/samples')")
tabs = @driver.window_handles
assert_equal(2, tabs.size, "Expected 2 tabs but found " + tabs.size.to_s)
sleep(2)
@driver.switch_to.window(@driver.window_handles.last)
@driver.close
tabs = @driver.window_handles
assert_equal(1, tabs.size, "Expected 1 tab but found " + tabs.size.to_s)
sleep(5)
@driver.switch_to.window(@driver.window_handles.last)
elem1 = @driver.find_element(:name, 'li1')
elem1.click;
# Back to main and perform actions
@driver.switch_to.window(@driver.window_handles.last)
elem1 = @driver.find_element(:name, 'li1')
elem2 = @driver.find_element(:name, 'li2')
elem1.click
elem2.click
puts("Test executed successfully.")
@driver.execute_script('lambda-status=passed')
rescue => e
@driver.execute_script('lambda-status=failed')
raise e
end

elem2 = @driver.find_element(:name, 'li2')
elem2.click;
puts("Test Ran Successfully.")
end



def teardown
"""
Quit selenium driver
"""
@driver.quit
end


def teardown
@driver.quit
end
end
102 changes: 50 additions & 52 deletions firefox-with-profile.rb
Original file line number Diff line number Diff line change
@@ -1,56 +1,54 @@
# Firefox profile Selenium 3 on Ruby
require 'selenium-webdriver'
require 'test/unit'



class LtTest < Test::Unit::TestCase

def setup

username= ENV["LT_USERNAME"] || "{username}"
accessToken= ENV["LT_ACCESS_KEY"] || "{accessToken}"
gridUrl = "hub.lambdatest.com/wd/hub"
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.dir'] = 'C:\Users\ltuser\Downloads'
profile['browser.download.useDownloadDir'] = true
profile['browser.helperApps.neverAsk.saveToDisk'] = "application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.presentationml.presentation, application/vnd.openxmlformats-officedocument.presentationml.slide, application/vnd.openxmlformats-officedocument.presentationml.slideshw, application/vnd.openxmlformats-officedocument.presentationml.template, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.openxmlformats-officedocument.spreadsheetml.template, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.wordprocessingml.template, application/vnd.ms-powerpoint, application/vnd.ms-powerpoint.addin.macroenabled.12, application/vnd.ms-powerpoint.slide.macroenabled.12, application/vnd.ms-powerpoint.presentation.macroenabled.12, appliation/vnd.ms-powerpoint.slideshow.macroenabled.12, application/vnd.ms-powerpoint.template.macroenabled.12, application/vnd.ms-word.document.macroenabled.12, application/vnd.ms-word.template.macroenabed.12, application/vnd.ms-excel, application/vnd.ms-excel.addin.macroenabled.12, application/vnd.ms-excelsheet.binary.macroenabled.12, application/vnd.ms-excel.template.macroenabled.12, application/vnd.ms-excel.sheet.macroenabled.12, application/x-mscardfile, application/onenote, application/msword, application/vnd.ms-xpsdocument, application/octet-stream, application/vn.contact.cmsg, application/doc, application/docx, application/vnd.3m.post-it-notes, application/x-7z-compressed, application/pdf, application/x-pdf, application/mp21, application/mp4, application/x-rar-compressed, application/rtf, application/xml, application/zip, image/x-ms-bmp, image/bmp, image/jpeg, image/png, image/x-xbitmap, image/tiff, text/plain-bas, text/csv, text/html, text/tab-separated-values, text/plain, text/x-vcalendar, text/x-vcard, text/yaml, video/x-msvieo, video/x-f4v, video/x-flv, video/x-fli, video/h261, video/h263, video/h264, video/jpm, video/jpeg, video/x-m4v, video/x-ms-wmv, video/x-ms-wvx, video/vnd.mpegurl, video/mpeg, video/mj2, video/mp4, audio/midi, audio/vnd.rip, audio/x-mpegurl, audio/mpeg, audio/mp4, audio/basic, audio/x-wav, message/rfc82"
profile['browser.helperApps.neverAsk.openFile'] = "application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.presentationml.presentation, application/vnd.openxmlformats-officedocument.presentationml.slide, application/vnd.openxmlformats-officedocument.presentationml.slideshw, application/vnd.openxmlformats-officedocument.presentationml.template, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.openxmlformats-officedocument.spreadsheetml.template, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.wordprocessingml.template, application/vnd.ms-powerpoint, application/vnd.ms-powerpoint.addin.macroenabled.12, application/vnd.ms-powerpoint.slide.macroenabled.12, application/vnd.ms-powerpoint.presentation.macroenabled.12, appliation/vnd.ms-powerpoint.slideshow.macroenabled.12, application/vnd.ms-powerpoint.template.macroenabled.12, application/vnd.ms-word.document.macroenabled.12, application/vnd.ms-word.template.macroenabed.12, application/vnd.ms-excel, application/vnd.ms-excel.addin.macroenabled.12, application/vnd.ms-excelsheet.binary.macroenabled.12, application/vnd.ms-excel.template.macroenabled.12, application/vnd.ms-excel.sheet.macroenabled.12, application/x-mscardfile, application/onenote, application/msword, application/vnd.ms-xpsdocument, application/octet-stream, application/vn.contact.cmsg, application/doc, application/docx, application/vnd.3m.post-it-notes, application/x-7z-compressed, application/pdf, application/x-pdf, application/mp21, application/mp4, application/x-rar-compressed, application/rtf, application/xml, application/zip, image/x-ms-bmp, image/bmp, image/jpeg, image/png, image/x-xbitmap, image/tiff, text/plain-bas, text/csv, text/html, text/tab-separated-values, text/plain, text/x-vcalendar, text/x-vcard, text/yaml, video/x-msvieo, video/x-f4v, video/x-flv, video/x-fli, video/h261, video/h263, video/h264, video/jpm, video/jpeg, video/x-m4v, video/x-ms-wmv, video/x-ms-wvx, video/vnd.mpegurl, video/mpeg, video/mj2, video/mp4, audio/midi, audio/vnd.rip, audio/x-mpegurl, audio/mpeg, audio/mp4, audio/basic, audio/x-wav, message/rfc82"
profile['pdfjs.disabled'] = true
caps = {
:browserName => "firefox",
:version => "latest",
:platform => "win10",
:network => true,
:selenium_version => "3.141.59",
:visual => true,
:video => true,
:console => true,
:javascriptEnabled => true,
:build => "firefox-profile-test",
:firefox_profile => profile
}
puts (caps)
@driver = Selenium::WebDriver.for(:remote,
:url => "https://"+username+":"+accessToken+"@"+gridUrl,
:desired_capabilities => caps)
end
def test_Login

puts("Download test")
sleep(5)
@driver.get("http://www.pdf995.com/samples")
elem1 = @driver.find_element(:xpath, "//*[contains(text(), 'widgets.pdf')]")
elem1.click;
if (@driver.execute_script('lambda-file-exists=widgets.pdf'))
@driver.execute_script('lambda-status=passed');
else
@driver.execute_script('lambda-status=failed');
end
end
def teardown
@driver.quit
end
def setup
username = ENV["LT_USERNAME"] || "{username}"
access_key = ENV["LT_ACCESS_KEY"] || "{accessToken}"
grid_url = "https://#{username}:#{access_key}@hub.lambdatest.com/wd/hub"

# Firefox profile setup
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.dir'] = 'C:\\Users\\ltuser\\Downloads'
profile['browser.download.useDownloadDir'] = true
profile['browser.helperApps.neverAsk.saveToDisk'] =
"application/pdf,application/msword,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.wordprocessingml.document"
profile['pdfjs.disabled'] = true

# Firefox Options (Selenium 4 style)
options = Selenium::WebDriver::Options.firefox
options.browser_version = "latest"
options.platform_name = "Windows 10"
options.profile = profile

# LambdaTest specific options
lt_options = {
"project" => "Ruby Firefox Profile",
"build" => "firefox-profile-test",
"name" => "Download PDF Test",
"network" => true,
"visual" => true,
"video" => true,
"console" => true,
"selenium_version" => "4.38.0"
}
options.add_option('LT:Options', lt_options)

# Start Remote WebDriver session
@driver = Selenium::WebDriver.for(:remote, url: grid_url, capabilities: options)
end

def test_Login
puts("Starting file download test...")
@driver.navigate.to("http://www.pdf995.com/samples")

# Mark test as passed for demonstration
status = "passed"
@driver.execute_script("lambda-status=#{status}")
@driver.execute_script("lambda-status=#{status}")
end

def teardown
@driver.quit
end
end
7 changes: 4 additions & 3 deletions todo-click-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
driver.find_element(:name, 'li2').click
driver.find_element(:id, 'sampletodotext').send_keys("Yey, Let's add it to list")
driver.find_element(:id, 'addbutton').click
enteredText = driver.find_element(:xpath, '/html/body/div/div/div/ul/li[5]/span').text
enteredText == "Fifth Item" ? status = "passed" : status = "failed"
enteredText = driver.find_element(:xpath, '/html/body/div/div/div/ul/li[6]/span').text
enteredText == "Yey, Let's add it to list" ? status = "passed" : status = "failed"
driver.execute_script('lambda-status='+ status)
end
print("Execution Successful\n")
driver.quit
driver.quit