Testing WebView Node.js Integration in NW.js
This test suite validates the integration of Node.js functionality within WebView components of NW.js applications. It specifically tests the ability to access Node.js version information from within a WebView context, ensuring proper communication between the WebView and Node.js runtime.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
nwjs/nwJs
test/sanity/webview-node/test.py
import time
import os
import urllib.parse, urllib.request, urllib.parse, urllib.error
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from nw_util import *
def path2url(path):
return urllib.parse.urljoin(
'file:', urllib.request.pathname2url(path))
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
testdir = os.path.dirname(os.path.abspath(__file__))
os.chdir(testdir)
chrome_options = Options()
chrome_options.add_argument("nwapp=" + testdir)
chrome_options.add_experimental_option("windowTypes", ["webview"])
capabilities = {"pageLoadStrategy": "none"}
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options, desired_capabilities = capabilities, service_log_path="log", service_args=["--verbose"])
driver.implicitly_wait(5)
try:
print(driver.current_url)
wait_switch_window_url(driver, 'webview.html')
result = driver.find_element_by_id('ret').get_attribute('innerHTML')
print(result)
assert('version = v' in result)
finally:
driver.quit()