Back to Repositories

Validating SDK Startup Stability in nw.js

This test suite validates NW.js SDK startup behavior to prevent crashes, utilizing Selenium WebDriver for automated browser testing. The test focuses on verifying proper window loading and version information display.

Test Coverage Overview

The test coverage ensures stable SDK initialization and window management in NW.js applications.

  • Verifies successful window loading with index.html
  • Validates version information display
  • Tests crash prevention during startup
  • Monitors window switching behavior

Implementation Analysis

The implementation leverages Selenium WebDriver with Chrome options for automated testing. The approach uses implicit waits and custom utility functions for reliable window state verification.

  • Custom Chrome configuration with nwapp argument
  • Page load strategy optimization
  • Window URL switching validation
  • Element presence verification

Technical Details

  • Selenium WebDriver with Chrome integration
  • Custom nw_util helper functions
  • ChromeDriver with verbose logging
  • Implicit wait timeout of 2 seconds
  • None page load strategy for performance
  • Environment-based ChromeDriver path configuration

Best Practices Demonstrated

The test implements robust automation practices for reliable SDK testing.

  • Proper test cleanup with driver.quit()
  • Try-finally block for resource management
  • Custom wait utilities for synchronization
  • Modular test structure with utility imports
  • Clear assertion messages

nwjs/nwJs

test/sanity/issue6171-sdk-start-crash/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__)))
capabilities = {"pageLoadStrategy": "none"}

driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options, desired_capabilities = capabilities, service_log_path="log", service_args=["--verbose"])
driver.implicitly_wait(2)
try:
    print('waiting for crash')
    wait_switch_window_url(driver, 'index.html')
    result = wait_for_element_id(driver, 'versions')
    #print result
    assert('NWjs version' in result)
    print('There is no crash')
finally:
    driver.quit()