Back to Repositories

Validating Window Position Persistence in NW.js

This test suite validates window position persistence and state management in NW.js applications. It ensures proper handling of window coordinates and user data directory across multiple application launches.

Test Coverage Overview

The test suite covers window position persistence and state management functionality in NW.js.

Key areas tested include:
  • Window position tracking and storage
  • User data directory management
  • Application state persistence across launches
  • Cross-platform compatibility (Windows, Linux, MacOS)

Implementation Analysis

The testing approach utilizes Python with Selenium WebDriver integration to automate NW.js application launches and verify window state persistence.

Technical implementation highlights:
  • Multiple application instance management
  • File system operations for state verification
  • Platform-specific executable path handling
  • Automated cleanup of test artifacts

Technical Details

Testing tools and configuration:
  • Python test framework with Selenium WebDriver
  • ChromeDriver integration
  • Platform-specific path resolution
  • Custom user data directory management
  • File-based state verification mechanism

Best Practices Demonstrated

The test demonstrates robust testing practices for desktop applications.

Notable practices include:
  • Proper test cleanup and isolation
  • Cross-platform compatibility handling
  • Deterministic state verification
  • Automated test environment setup
  • Clear assertion points for validation

nwjs/nwJs

test/sanity/window-id-pos/test.py

            
import os
import sys
import shutil
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

testdir = os.path.dirname(os.path.abspath(__file__))
os.chdir(testdir)

datadir = os.path.join(testdir, 'userdata')
try:
    shutil.rmtree(datadir)
except:
    pass

try:
    os.remove('last_pos.txt')
except:
    pass
try:
    os.remove('succeed.txt')
except:
    pass
try:
    os.remove('failed.txt')
except:
    pass

pkg1 = os.path.dirname(os.environ['CHROMEDRIVER'])

if platform.system() == 'Darwin':
    exe = os.path.join(pkg1, 'nwjs.app', 'Contents', 'MacOS', 'nwjs')
elif platform.system() == 'Linux':
    exe = os.path.join(pkg1, 'nw')
else:
    exe = os.path.join(pkg1, 'nw.exe')


p = subprocess.call([exe, "--user-data-dir="+datadir, "."])

assert(os.path.exists('last_pos.txt'))

p = subprocess.call([exe, "--user-data-dir="+datadir, "."])

assert(os.path.exists('succeed.txt'))