Validating Node-Remote Integration Testing in NW.js
This test suite validates the node-remote functionality in NW.js using Selenium WebDriver with Python. It tests the ability to load remote content and execute Node.js code within the NW.js environment, ensuring proper integration between web and Node.js contexts.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
nwjs/nwJs
test/sanity/node-remote/test.py
import time
import os
import subprocess
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__)))
testdir = os.path.dirname(os.path.abspath(__file__))
os.chdir(testdir)
port = str(utils.free_port())
server = subprocess.Popen(['python3', 'http-server.py', port])
manifest = open('package.json', 'w')
manifest.write('''
{
"name":"test-node-remote",
"node-remote":"<all_urls>",
"main":"http://localhost:%s/index.html"
}
''' % (port))
manifest.close()
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options, service_log_path="log", service_args=["--verbose"])
driver.implicitly_wait(5)
try:
print(driver.current_url)
result = driver.find_element_by_id('result')
print(result.get_attribute('innerHTML'))
assert("success" in result.get_attribute('innerHTML'))
finally:
import platform
if platform.system() == 'Windows':
subprocess.call(['taskkill', '/F', '/T', '/PID', str(server.pid)])
else:
server.terminate()
driver.quit()