Back to Repositories

Testing Window Workspace Visibility Implementation in nw.js

This test suite validates the window.setVisibleOnAllWorkspaces functionality in NW.js using Selenium WebDriver with Python. The test verifies that a window can be correctly set to display across all workspaces on non-Windows platforms.

Test Coverage Overview

The test ensures proper window visibility behavior across multiple workspaces in non-Windows environments. Key functionality includes:

  • Platform-specific execution control
  • Window visibility state verification
  • Cross-workspace display validation

Implementation Analysis

The implementation utilizes Selenium WebDriver with Chrome options for automated testing. The approach includes platform detection, Chrome WebDriver initialization, and element state verification. The test leverages Selenium’s find_element_by_id method to check the visible_on_all_workspaces property.

Technical Details

Testing components include:

  • Selenium WebDriver for browser automation
  • Chrome Options for NW.js app configuration
  • Platform module for OS detection
  • Environment variable integration for ChromeDriver path
  • Try-finally block for proper resource cleanup

Best Practices Demonstrated

The test exhibits several quality practices:

  • Proper resource management with driver cleanup
  • Platform-specific test handling
  • Clear assertion conditions
  • Environment variable usage for configuration
  • Structured error handling

nwjs/nwJs

test/sanity/window-setvisibleonallworkspaces/test.py

            
import os
import platform
import time

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

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, service_log_path="log", service_args=["--verbose"])
try:
    result = driver.find_element_by_id('visible_on_all_workspaces').get_attribute('textContent')
    assert(result == 'true')
finally:
    driver.quit()