Last active
July 29, 2022 10:01
-
-
Save SarahElson/c455a3e88b2df2a347885c695efb62d1 to your computer and use it in GitHub Desktop.
How To Maximize Browser In Selenium Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'selenium-webdriver' | |
require 'test-unit' | |
class BrowserWindowTests < Test::Unit::TestCase | |
def setup | |
username = "#{ENV['LAMBDATEST_USERNAME']}" | |
access_token = "#{ENV['LAMBDATEST_ACCESS_KEY']}" | |
grid_url = "hub.lambdatest.com/wd/hub" | |
capabilities = { | |
'LT:Options' => { | |
"user" => username, | |
"accessKey" => access_token, | |
"build" => "Browser Maximizing Test v.1", | |
"name" => "Browser Maximizing Tests", | |
"platformName" => "Windows 11" | |
}, | |
"browserName" => "Firefox", | |
"browserVersion" => "100.0", | |
} | |
@my_driver = Selenium::WebDriver.for(:remote, | |
:url => "https://"+username+":"+access_token+"@"+grid_url, | |
:capabilities => capabilities) | |
@url = "https://ecommerce-playground.lambdatest.io/" | |
#get url | |
@my_driver.get(@url) | |
@wait = Selenium::WebDriver::Wait.new(:timeout => 30) | |
end | |
def test_page_resizing | |
# Assert that title is loaded | |
@wait.until { @my_driver.title.include? "Your Store" } | |
sleep(2) | |
# We maximize the window to occupy the full page | |
@my_driver.manage.window.maximize | |
# Here we minimize the browser window to the taskbar | |
@my_driver.manage.window.minimize | |
sleep(2) | |
# Here we resize the browser window to a width and height of 500(width) by 1000(height) | |
@my_driver.manage.window.resize_to(500, 1000) | |
sleep(2) | |
# We maximize the browser window again to occupy the full page | |
@my_driver.manage.window.maximize | |
# Here we resize the browser window to a width and height that's bigger than a normal screen size | |
@my_driver.manage.window.resize_to(6000, 6000) | |
sleep(2) | |
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