Back to Repositories

Testing VM Crash Handling Integration in NW.js

This test suite validates VM crash handling in NW.js using Selenium WebDriver integration. It focuses on verifying proper behavior when executing JavaScript code in the VM context, ensuring stability and proper error handling.

Test Coverage Overview

The test provides essential coverage for VM-related crash scenarios in NW.js applications. It specifically targets the issue #4018 related to VM stability.

  • Tests VM execution stability
  • Verifies proper crash handling
  • Validates WebDriver integration
  • Checks element state management

Implementation Analysis

The implementation leverages Selenium WebDriver with Chrome options for automated testing. It utilizes a custom page load strategy and specific Chrome configurations to create an isolated test environment.

  • Custom Chrome options configuration
  • WebDriver session management
  • Element wait mechanisms
  • Assertion-based validation

Technical Details

  • Selenium WebDriver for browser automation
  • Chrome Options for NW.js app configuration
  • Custom page load strategy settings
  • Environment-specific ChromeDriver path
  • Directory path management utilities
  • Custom wait_for_element_id utility

Best Practices Demonstrated

The test demonstrates robust automation practices with proper resource cleanup and error handling. It implements proper setup/teardown patterns and uses explicit waits for reliable testing.

  • Proper driver cleanup in finally block
  • Explicit wait patterns
  • Environment configuration management
  • Isolated test environment setup

nwjs/nwJs

test/sanity/issue4018-vm-crash/test.py

            
import time
import os
import subprocess
import sys
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
from selenium.webdriver.common import utils

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

capabilities = {"pageLoadStrategy": "none"}

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

driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options, desired_capabilities = capabilities)
try:
    result = wait_for_element_id(driver, 'ret')
    print('result=' + result)
    assert("success" in result)
finally:
    driver.quit()