Validating User Agent Configuration Implementation in NW.js
This test suite validates the user agent configuration in NW.js applications using Selenium WebDriver and Python. It ensures proper user agent string handling and verification through an automated testing approach.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
nwjs/nwJs
test/sanity/user-agent/test.py
import time
import os
import subprocess
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__)))
testdir = os.path.dirname(os.path.abspath(__file__))
os.chdir(testdir)
server = subprocess.Popen(['python3', '-u', 'echo-user-agent.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(server.stdout.readline())
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
driver.implicitly_wait(5)
try:
print(driver.current_url)
user_agent = server.stdout.readline().decode()
print("user agent: " + user_agent)
server.terminate()
assert("test-agent" in user_agent)
finally:
driver.quit()