Back to Repositories

Testing Window Navigation and Object Handling in NW.js

This test suite validates window navigation and object handling in NW.js applications using Selenium WebDriver. The test verifies proper window switching, element interactions, and event handling across multiple browser windows.

Test Coverage Overview

The test provides comprehensive coverage of window management and DOM interactions in NW.js applications.

  • Window handle switching between parent and child windows
  • Element interaction across multiple windows
  • Event propagation validation
  • Window closure handling and cleanup

Implementation Analysis

The test implements a Selenium WebDriver approach using Python to automate browser interactions.

  • Chrome WebDriver configuration with NW.js specific options
  • Window handle management using switch_to_window
  • DOM element selection and interaction
  • Assertion-based result validation

Technical Details

  • Selenium WebDriver with Chrome driver
  • Python test implementation
  • Chrome Options configuration for NW.js
  • Implicit wait timing configuration
  • HTML element interaction via tag name and ID selectors

Best Practices Demonstrated

The test exemplifies robust automation practices for window-based testing.

  • Proper resource cleanup in finally block
  • Explicit window handle management
  • Strategic wait implementation
  • Clear assertion patterns
  • Error handling with try-finally structure

nwjs/nwJs

test/full/wopen-obj-navigate/test.py

            
import time
import os

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(5)
time.sleep(1)
try:
    print driver.current_url
    driver.switch_to_window(driver.window_handles[-1])
    driver.find_element_by_tag_name('a').click()  #navigate
    driver.switch_to_window(driver.window_handles[0])
    driver.find_element_by_tag_name('button').click() #get target window
    result = driver.find_element_by_id('result').get_attribute('innerHTML')
    print result
    assert('success' in result)
    driver.switch_to_window(driver.window_handles[-1])
    driver.find_element_by_tag_name('button').click() #click close button
    driver.switch_to_window(driver.window_handles[0])
    result = driver.find_element_by_id('result2').get_attribute('innerHTML')
    print result
    assert('success' in result)
finally:
    driver.quit()