In this note, I will describe the implementation of launching an autotest for the ChromeDriver browser Chrome, which launches an autotest module translated from C++ using Emscripten, reads the console output and returns the test result.
First you need to install selenium, for python3-ubuntu it is done like this:
pip3 install selenium
Next, download ChromeDriver from the official website, put chromedriver, for example, in /usr/local/bin, after that you can start implementing the autotest.
Below I will provide the code of the autotest, which launches the Chrome browser with the Emscripten autotest page open, checks for the presence of the text “Window test succeded”:
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
capabilities = DesiredCapabilities.CHROME
capabilities['goog:loggingPrefs'] = { 'browser':'ALL' }
driver = webdriver.Chrome()
driver.get("http://localhost/windowInitializeTest/indexFullscreen.html")
time.sleep(2)
exitCode = 1
for entry in driver.get_log('browser'):
if entry["source"] == "console-api":
message = entry["message"]
if "Window test succeded" in message:
print("Test succeded")
exitCode = 0
driver.close()
exit(exitCode)
Save the test as main.py and run python3 main.py