Back to Repositories

Testing DOM Storage Quota Implementation in NW.js

This test suite validates DOM storage quota functionality in NW.js using Selenium WebDriver. It automates browser interactions to verify storage limits and quota management, ensuring proper implementation of web storage constraints.

Test Coverage Overview

The test coverage focuses on DOM storage quota verification through automated browser testing.

  • Validates storage success conditions via DOM elements
  • Tests multiple storage operations through result elements
  • Verifies proper quota enforcement and success states
  • Covers cross-platform compatibility scenarios

Implementation Analysis

The testing approach utilizes Selenium WebDriver with Chrome options for NW.js app testing.

Key implementation patterns include:
  • Chrome WebDriver initialization with custom app directory
  • Implicit wait handling for DOM element availability
  • Element location and attribute validation
  • Automated cleanup through driver quit operations

Technical Details

  • Selenium WebDriver for browser automation
  • Chrome Options configuration for NW.js testing
  • Environment-based ChromeDriver path configuration
  • DOM element identification using ID selectors
  • Assertion-based validation of storage operations

Best Practices Demonstrated

The test implementation showcases robust automated testing practices for web storage functionality.

  • Proper test cleanup and resource management
  • Explicit success criteria validation
  • Error handling through try-finally blocks
  • Platform-independent test execution
  • Clear separation of setup and verification logic

nwjs/nwJs

test/sanity/dom-storage-quota/test.py

            
import time
import os
import shutil
import platform

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

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

driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
try:
    print(driver.current_url)
    driver.implicitly_wait(5)
    result = driver.find_element_by_id('result')
    print(result.get_attribute('innerHTML'))
    assert("success" in result.get_attribute('innerHTML'))
    result = driver.find_element_by_id('result2')
    print(result.get_attribute('innerHTML'))
    assert("success" in result.get_attribute('innerHTML'))
finally:
    driver.quit()