-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdriver-close.rb
More file actions
67 lines (57 loc) · 2.01 KB
/
driver-close.rb
File metadata and controls
67 lines (57 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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"
# 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
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')")
tabs = @driver.window_handles
assert_equal(3, tabs.size, "Expected 3 tabs but found #{tabs.size}")
sleep(1)
# 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)
# 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
def teardown
@driver.quit
end
end