from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import unittest
class TestChromeOptions(unittest.TestCase):
def setUp(self):
chrome_options = Options()
chrome_options.add_argument('--window-size=1024,768')
self.driver = webdriver.Chrome(options=chrome_options)
def test_window_size_and_navigation(self):
self.driver.get('https://www.example.com')
width = self.driver.execute_script('return window.innerWidth')
height = self.driver.execute_script('return window.innerHeight')
self.assertEqual(width, 1024, 'Window width should be 1024')
self.assertEqual(height, 768, 'Window height should be 768')
self.assertIn('Example Domain', self.driver.title, 'Page title should contain Example Domain')
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main()This test uses ChromeOptions to set the browser window size before launching Chrome. The --window-size=1024,768 argument sets the window size. After launching, the test navigates to https://www.example.com. It then uses JavaScript to get the actual window inner width and height and asserts they match the expected size. It also checks the page title to confirm navigation succeeded. The test uses Python's unittest framework for structure and assertions. The tearDown method ensures the browser closes after the test to keep the environment clean.