Back to Repositories

Testing Window Open Null Parameter Handling in NW.js

This test suite validates window opening behavior in NW.js applications using Selenium WebDriver for automation. It specifically tests handling of window.open() calls with null parameters, verifying both new instance creation and same instance reuse scenarios.

Test Coverage Overview

The test coverage focuses on window management functionality in NW.js applications, specifically verifying the behavior of window.open() calls. Key areas tested include:

  • New window instance creation
  • Same window instance reuse
  • Proper success state verification
  • Window handle management

Implementation Analysis

The implementation uses Selenium WebDriver with Python to automate browser interactions. The test leverages Chrome options for NW.js app configuration and implements a systematic approach to window management verification.

Key patterns include explicit waits, element location by ID, and attribute verification through innerHTML checks.

Technical Details

  • Selenium WebDriver for browser automation
  • Chrome Options for NW.js app configuration
  • Python test implementation
  • Implicit wait timing of 2 seconds
  • Chrome driver with verbose logging
  • Element location by ID selectors

Best Practices Demonstrated

The test demonstrates several testing best practices including proper resource cleanup in finally blocks, explicit success criteria validation, and clear test case separation. The code organization follows a linear flow with setup, execution, and verification phases clearly defined.

  • Proper exception handling
  • Resource cleanup
  • Clear success criteria
  • Systematic verification approach

nwjs/nwJs

test/sanity/issue4691-win-open-null/test.py

            
import time
import os
import subprocess

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, service_log_path="log", service_args=["--verbose"])
driver.implicitly_wait(2)
try:
    print(driver.current_url)
    driver.find_element_by_id('new-inst').click()
    result = driver.find_element_by_id('new-inst-result').get_attribute('innerHTML')
    print('opening new instance returned "%s"' % result)
    assert('success' in result)
    driver.find_element_by_id('same-inst').click()
    result = driver.find_element_by_id('same-inst-result').get_attribute('innerHTML')
    print('opening same instance returned "%s"' % result)
    assert('success' in result)
finally:
    driver.quit()