Back to Repositories

Testing Render Window Process Isolation in NW.js

This test suite validates the instance isolation behavior in NW.js by spawning multiple render windows and verifying their process independence. The test ensures proper window management and process separation using Selenium WebDriver for automation.

Test Coverage Overview

The test suite focuses on verifying process isolation between multiple render windows in NW.js.

Key areas covered include:
  • Spawning multiple render windows
  • Window handle management
  • Process ID verification
  • Cross-window interaction testing

Implementation Analysis

The test implements a Selenium WebDriver approach to automate window management and verification.

Notable patterns include:
  • Chrome WebDriver configuration with NW.js app path
  • Window handle switching and management
  • DOM element interaction and attribute extraction
  • Process ID comparison validation

Technical Details

Testing tools and configuration:
  • Selenium WebDriver with Chrome driver
  • Python test framework
  • Custom nw_util helper functions
  • Chrome options configuration for NW.js app
  • Window handle management utilities

Best Practices Demonstrated

The test exhibits strong quality practices in automated UI testing.

Notable practices include:
  • Proper test cleanup with driver.quit()
  • Explicit wait conditions for window handling
  • Clear assertion messages
  • Structured window navigation
  • Error handling with try-finally blocks

nwjs/nwJs

test/sanity/issue5163-new-instance/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()
    driver.find_element_by_id('spawnRender').click()
    print('wait for window open')
    wait_window_handles(driver, 3)
    print(driver.window_handles)
    print('switch to 1st window')
    driver.switch_to.window(driver.window_handles[-2])
    result1 = driver.find_element_by_id('result').get_attribute('innerHTML')
    print(result1)
    print('switch to 2nd window')
    driver.switch_to.window(driver.window_handles[-1])
    result2 = driver.find_element_by_id('result').get_attribute('innerHTML')
    print(result2)
    assert result1 != result2, "renders should not share same pid"
finally:
    driver.quit()