Back to Repositories

Testing localStorage URL Crash Prevention in NW.js

This test suite validates the handling of localStorage.getItem() behavior with URL parameters in NW.js, specifically focusing on crash prevention. The test ensures proper null handling and URL state management across different platforms.

Test Coverage Overview

The test suite provides coverage for localStorage.getItem() functionality with specific focus on URL-related crash scenarios.

Key areas covered include:
  • Platform-specific execution handling (Darwin/Mac skipping)
  • URL state verification
  • Null value handling in localStorage operations
  • Crash prevention validation

Implementation Analysis

The implementation utilizes Selenium WebDriver for browser automation, with Chrome-specific configurations for NW.js testing.

Notable patterns include:
  • Chrome WebDriver initialization with custom options
  • Implicit wait implementation for element synchronization
  • Try-finally block structure for proper driver cleanup
  • Platform-aware test execution

Technical Details

Testing infrastructure includes:
  • Selenium WebDriver for browser automation
  • Chrome Options configuration for NW.js app testing
  • Custom utility functions from nw_util
  • Platform detection mechanisms
  • Environment variable integration for ChromeDriver path

Best Practices Demonstrated

The test demonstrates robust testing practices including proper resource cleanup, platform-specific handling, and explicit assertion checks.

Key practices include:
  • Proper driver initialization and cleanup
  • Platform-specific test skipping
  • Clear assertion messages
  • Structured error handling
  • Modular test organization

nwjs/nwJs

test/sanity/issue5947-localStorage_getItem_url_crash/test.py

            
import time
import os
import platform
import sys

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

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)
driver.implicitly_wait(2)
try:
    print(driver.current_url)
    res = wait_for_element_id_content(driver, "result", "URL is: null")
    print(res)
    assert("URL is: null" in res)
    print("There is no crash")

finally:
    driver.quit()