Back to Repositories

Validating Event Loading Sequence Implementation in nw.js

This test suite validates the proper loading and event handling sequence in NW.js applications using Selenium WebDriver. It specifically focuses on verifying DOM onload events and NW.js loaded events are triggered in the correct order.

Test Coverage Overview

The test provides comprehensive coverage of the NW.js application loading lifecycle.

Key areas tested include:
  • DOM onload event sequence
  • NW.js framework initialization
  • Event timing verification
  • Browser automation integration

Implementation Analysis

The implementation utilizes Selenium WebDriver with Chrome options to automate browser interactions. The test employs a wait-and-verify pattern to ensure proper event sequencing, using explicit content checks and timing controls to validate the application’s loading behavior.

Framework-specific features include:
  • Chrome WebDriver configuration
  • Custom NW.js app initialization
  • Element content verification
  • Automated cleanup procedures

Technical Details

Testing tools and configuration:
  • Selenium WebDriver for browser automation
  • Chrome Options for NW.js app configuration
  • Custom utility functions for element verification
  • Environment-based ChromeDriver path configuration
  • Implicit wait timing of 5 seconds
  • Try-finally block for proper resource cleanup

Best Practices Demonstrated

The test demonstrates several quality testing practices including proper resource management, explicit wait conditions, and robust error handling. Notable practices include:
  • Proper driver cleanup in finally block
  • Use of utility functions for element verification
  • Clear assertion conditions
  • Modular test structure
  • Environment variable usage for configuration

nwjs/nwJs

test/sanity/issue7306-loaded/test.py

            
import time
import os
import sys

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(5)
try:
    wait_for_element_id_content(driver, 'result', 'DOM onload event<br>NW.js loaded event<br>')
    driver.find_element_by_tag_name('a').click()
    time.sleep(1)
    result = driver.find_element_by_id('result').get_attribute('innerHTML')
    print(result)
    assert(result == 'DOM onload event<br>NW.js loaded event<br>')
finally:
    driver.quit()