Back to Repositories

Testing NW.js Application Loading and DOM Content Verification in nw.js

This test suite validates the loading and rendering of NW.js application content using Selenium WebDriver integration. It focuses on verifying proper initialization and DOM element accessibility within the NW.js runtime environment.

Test Coverage Overview

The test suite provides coverage for basic NW.js application loading and DOM manipulation verification.

Key areas tested include:
  • Application initialization and URL loading
  • DOM element access and content verification
  • Chrome WebDriver integration with NW.js runtime
  • Proper cleanup of browser resources

Implementation Analysis

The implementation uses Selenium WebDriver with Chrome options specifically configured for NW.js testing. The test leverages Python’s unittest framework with explicit WebDriver wait conditions and element location strategies.

Notable patterns include:
  • Custom Chrome options configuration for NW.js compatibility
  • Implicit wait timing for DOM loading
  • Try-finally structure for proper resource cleanup
  • Element location by tag name and attribute verification

Technical Details

Testing tools and configuration:
  • Selenium WebDriver for browser automation
  • Chrome Options for NW.js runtime configuration
  • Python sys and os modules for path management
  • Custom nw_util helper functions
  • ChromeDriver executable specified via environment variable

Best Practices Demonstrated

The test demonstrates several testing best practices for NW.js applications.

Quality aspects include:
  • Proper resource cleanup in finally block
  • Explicit path management for test directory
  • Clear assertion conditions for content verification
  • Modular test setup with utility imports
  • Appropriate wait conditions for DOM loading

nwjs/nwJs

test/sanity/issue7197-load/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
from selenium.webdriver.common import utils

test_dir = os.path.dirname(os.path.abspath(__file__))
chrome_options = Options()
chrome_options.add_argument("nwapp=" + test_dir)

driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
driver.implicitly_wait(5)
try:
    print(driver.current_url)

    result = driver.find_element_by_tag_name('h1')
    ret = result.get_attribute('innerHTML')
    print(ret)
    assert("NW.js" in result.get_attribute('innerHTML'))

finally:
    driver.quit()