Back to Repositories

Testing Hidden Window Initialization Behavior in NW.js

This test suite validates the behavior of NW.js applications when the show:false window property is used, specifically checking for crash prevention. It uses Selenium WebDriver to automate Chrome browser testing and verify proper window initialization.

Test Coverage Overview

The test ensures proper handling of hidden window initialization in NW.js applications.

  • Verifies window creation with show:false property
  • Tests crash prevention mechanisms
  • Validates proper DOM element accessibility
  • Checks window state management

Implementation Analysis

The implementation uses Selenium WebDriver with Python to automate Chrome browser testing. The test leverages Chrome options to configure the NW.js application environment and implements implicit waits for reliable element detection.

  • Chrome WebDriver initialization with custom options
  • DOM element verification using find_element_by_id
  • Assertion-based success validation
  • Proper resource cleanup in finally block

Technical Details

  • Selenium WebDriver for browser automation
  • Chrome Options for NW.js app configuration
  • Environment variable usage for ChromeDriver path
  • Implicit wait timing of 5 seconds
  • Element content validation via innerHTML attribute

Best Practices Demonstrated

The test implements several testing best practices for reliable automation.

  • Proper exception handling and resource cleanup
  • Environment-independent path resolution
  • Explicit success criteria validation
  • Configurable browser automation setup
  • Defensive programming with try-finally block

nwjs/nwJs

test/sanity/issue4114-show-false-crash/test.py

            
import time
import os

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__)))

driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
driver.implicitly_wait(5)
try:
    print(driver.current_url)
    result = driver.find_element_by_id('result').get_attribute('innerHTML')
    print(result)
    assert("success" in result)
finally:
    driver.quit()