Back to Repositories

Testing Window Context Management Workflow in NW.js

This test suite validates window opening functionality in NW.js using Selenium WebDriver with Python. It verifies proper window creation and state management across local and remote contexts.

Test Coverage Overview

The test suite provides comprehensive coverage of NW.js window management capabilities.

Key areas tested include:
  • Window creation and switching between local/remote contexts
  • Element interaction across window contexts
  • State verification of opened windows
  • Object property validation across window boundaries

Implementation Analysis

The implementation uses Selenium WebDriver with Python to automate window interaction testing. The approach leverages Chrome options and custom capabilities for NW.js-specific window handling.

Notable patterns include:
  • Custom Chrome driver configuration for NW.js testing
  • Window context switching validation
  • Asynchronous wait patterns for UI elements
  • Proper test cleanup and resource management

Technical Details

Testing tools and configuration:
  • Selenium WebDriver with Chrome driver
  • Python test framework with custom utilities
  • Chrome options with NW.js app path configuration
  • Custom page load strategy configuration
  • Verbose logging setup for debugging

Best Practices Demonstrated

The test implementation showcases several testing best practices:

  • Proper setup and teardown with try/finally blocks
  • Explicit wait patterns for reliable UI testing
  • Clear assertion messages and validation steps
  • Modular test utility functions
  • Comprehensive error logging and debugging support

nwjs/nwJs

test/sanity/window-open/test.py

            
import time
import os
import subprocess
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
from selenium.webdriver.common import utils

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

capabilities = {"pageLoadStrategy": "none"}

testdir = os.path.dirname(os.path.abspath(__file__))
os.chdir(testdir)

driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options, desired_capabilities = capabilities, service_log_path="log", service_args=["--verbose"])
try:
    wait_switch_window_name(driver, 'local')
    print(driver.current_url)
    driver.find_element_by_id('open').click()
    result = wait_for_element_id(driver, 'res')
    print('result=' + result)
    assert("object" in result)
    wait_switch_window_name(driver, 'remote')
    result = wait_for_element_id(driver, 'res')
    print(result)
    assert("ENABLED" in result)
finally:
    driver.quit()