Back to Repositories

Testing MacOS Window Creation Crash Prevention in NW.js

This test suite validates the handling of window creation and crash scenarios in NW.js on macOS platforms. It specifically tests the application’s stability when creating new windows and verifies proper URL loading behavior.

Test Coverage Overview

The test coverage focuses on macOS-specific window handling and crash prevention in NW.js applications. Key functionality includes:

  • Platform-specific execution validation
  • Window handle management
  • URL loading verification
  • Crash prevention assessment

Implementation Analysis

The testing approach utilizes Selenium WebDriver to automate browser interactions and validate window behavior. The implementation employs Chrome options for NW.js app configuration and implements explicit wait patterns for reliable window handle verification.

  • Window switching logic
  • URL validation checks
  • Timeout handling
  • Cleanup procedures

Technical Details

Testing tools and configuration:

  • Selenium WebDriver with Chrome driver
  • Python test framework
  • Platform-specific conditionals
  • Custom NW.js utility functions
  • Environment variable configuration for ChromeDriver

Best Practices Demonstrated

The test implementation showcases several testing best practices for desktop application validation:

  • Proper exception handling and cleanup
  • Platform-specific test skipping
  • Explicit wait patterns
  • Clear assertion messages
  • Resource cleanup in finally block

nwjs/nwJs

test/sanity/issue6113-mac-create-crash/test.py

            
import time
import os
import platform
import sys

if platform.system() != 'Darwin':
    print('Skipped for non Mac platform')
    sys.exit(0)

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

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

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(2)
try:
    wait_window_handles(driver, 2)
    handles = driver.window_handles
    print(handles)
    driver.switch_to_window(handles[1])
    output = driver.current_url
    print(output)
    print('waiting for crash')
    time.sleep(5)
    assert driver.title == "Google"
    assert("https://www.google.com/" in output)
    print('There is no crash')
finally:
    driver.quit()