Back to Repositories

Testing Mixed Context Window Instance Management in NW.js

This test suite validates the handling of mixed context window instances in NW.js using Selenium WebDriver. It focuses on verifying proper behavior when spawning new renderer windows and checking undefined context variables.

Test Coverage Overview

The test suite covers critical functionality related to window instance management and context isolation in NW.js applications.

Key areas tested include:
  • Spawning new renderer windows
  • Window handle management
  • Context variable scope verification
  • Cross-window communication integrity

Implementation Analysis

The implementation utilizes Selenium WebDriver to automate browser interactions and validate window behaviors. The test employs a systematic approach using Chrome options for NW.js app configuration and explicit window handle management.

Key patterns include:
  • Chrome WebDriver initialization with custom options
  • Window handle switching and validation
  • Element interaction and attribute verification
  • Assertion-based result validation

Technical Details

Testing tools and configuration:
  • Selenium WebDriver with Chrome driver
  • Custom Chrome options for NW.js integration
  • Python test framework
  • Environment-based driver path configuration
  • Window handle management utilities

Best Practices Demonstrated

The test implementation showcases several testing best practices for web application automation.

Notable practices include:
  • Proper test cleanup with driver quit in finally block
  • Explicit wait mechanisms for window handling
  • Clear assertion conditions for validation
  • Modular test utility integration
  • Robust error handling structure

nwjs/nwJs

test/sanity/issue7344-new-inst-mixctx/test.py

            
import time
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from nw_util import *

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)
try:
    print(driver.current_url)
    driver.find_element_by_id('spawnRender').click()
    print('wait for window open')
    wait_window_handles(driver, 2)
    print(driver.window_handles)
    print('switch to 1st window')
    driver.switch_to.window(driver.window_handles[-1])
    result1 = driver.find_element_by_id('result').get_attribute('innerHTML')
    print(result1)
    assert('undefined' in result1) 
finally:
    driver.quit()