Back to Repositories

Testing Window Size Management Implementation in NW.js

This test suite validates window sizing behavior in NW.js applications using Selenium WebDriver. It specifically examines window dimensions during initial opening and subsequent resizing operations, ensuring consistent behavior across multiple browser sessions.

Test Coverage Overview

The test suite provides comprehensive coverage of window sizing functionality in NW.js applications.

Key areas tested include:
  • Initial window size verification
  • Dynamic window resizing operations
  • Size persistence across multiple browser sessions
  • Size attribute validation through DOM elements

Implementation Analysis

The implementation utilizes Selenium WebDriver with Python to automate browser interactions. The test employs a two-phase approach, first verifying window resize capabilities and then confirming size persistence in a subsequent session.

Notable patterns include:
  • Chrome WebDriver configuration with NW.js specific arguments
  • Implicit wait handling for element synchronization
  • DOM element size extraction and validation
  • Multiple browser session management

Technical Details

Testing components and configuration:
  • Selenium WebDriver for browser automation
  • Chrome Options for NW.js app configuration
  • Python’s native assertion framework
  • Environment-specific ChromeDriver path configuration
  • DOM element targeting using getElementById
  • Exception handling with try-finally blocks

Best Practices Demonstrated

The test implementation showcases several testing best practices for window management validation.

Notable practices include:
  • Proper test session cleanup and resource management
  • Clear separation of test phases
  • Explicit verification points for size attributes
  • Flexible size assertion allowing for minor variations
  • Descriptive logging for test execution tracking

nwjs/nwJs

test/sanity/issue4493-win-open-size/test.py

            
import time
import os
import platform

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("nwapp=" + os.path.dirname(os.path.abspath(__file__)))

# open first time
print('Open first time')
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
driver.implicitly_wait(10)
try:
    print(driver.current_url)
    size = driver.find_element_by_id('size').get_attribute('innerHTML')
    print('open size %s' % size)
    driver.find_element_by_id('resize-window').click()
    size = driver.find_element_by_id('resize').get_attribute('innerHTML')
    print('resize to %s' % size)
finally:
    driver.quit()

# open second time
print('Open second time')
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
driver.implicitly_wait(10)
try:
    print(driver.current_url)
    size = driver.find_element_by_id('size').get_attribute('innerHTML')
    print('open size %s' % size)
    assert(size == '666x333' or size == '667x334')
finally:
    driver.quit()