use of org.openqa.selenium.chrome.ChromeDriverService in project Bytecoder by mirkosertic.
the class BytecoderMavenMojo method wat2wasm.
private int[] wat2wasm(WASMCompileResult aResult) throws IOException {
String theChromeDriverBinary = System.getenv("CHROMEDRIVER_BINARY");
if (theChromeDriverBinary == null || theChromeDriverBinary.isEmpty()) {
throw new RuntimeException("No chromedriver binary found! Please set CHROMEDRIVER_BINARY environment variable!");
}
ChromeDriverService.Builder theDriverServiceBuilder = new ChromeDriverService.Builder();
theDriverServiceBuilder = theDriverServiceBuilder.withVerbose(false);
theDriverServiceBuilder = theDriverServiceBuilder.usingDriverExecutable(new File(theChromeDriverBinary));
ChromeDriverService theDriverService = theDriverServiceBuilder.build();
theDriverService.start();
File theTempDirectory = Files.createTempDir();
File theGeneratedFile = new File(theTempDirectory, "compile.html");
// Copy WABT Tools
File theWABTFile = new File(theTempDirectory, "libwabt.js");
try (FileOutputStream theOS = new FileOutputStream(theWABTFile)) {
IOUtils.copy(getClass().getResourceAsStream("/libwabt.js"), theOS);
}
PrintWriter theWriter = new PrintWriter(theGeneratedFile);
theWriter.println("<html>");
theWriter.println(" <body>");
theWriter.println(" <h1>Module code</h1>");
theWriter.println(" <pre id=\"modulecode\">");
theWriter.println(aResult.getData());
theWriter.println(" </pre>");
theWriter.println(" <h1>Compilation result</h1>");
theWriter.println(" <pre id=\"compileresult\">");
theWriter.println(" </pre>");
theWriter.println(" <script src=\"libwabt.js\">");
theWriter.println(" </script>");
theWriter.println(" <script>");
theWriter.println(" function compile() {");
theWriter.println(" console.log('Compilation started');");
theWriter.println(" try {");
theWriter.println(" var module = wabt.parseWat('test.wast', document.getElementById(\"modulecode\").innerText);");
theWriter.println(" module.resolveNames();");
theWriter.println(" module.validate();");
theWriter.println(" var binaryOutput = module.toBinary({log: true, write_debug_names:true});");
theWriter.println(" document.getElementById(\"compileresult\").innerText = binaryOutput.log;");
theWriter.println(" return binaryOutput.buffer;");
theWriter.println(" } catch (e) {");
theWriter.println(" document.getElementById(\"compileresult\").innerText = e.toString();");
theWriter.println(" console.log(e.toString());");
theWriter.println(" console.log(e.stack);");
theWriter.println(" }");
theWriter.println(" }");
theWriter.println(" </script>");
theWriter.println(" </body>");
theWriter.println("</html>");
theWriter.flush();
theWriter.close();
ChromeOptions theOptions = new ChromeOptions();
theOptions.addArguments("headless");
theOptions.addArguments("disable-gpu");
LoggingPreferences theLoggingPreferences = new LoggingPreferences();
theLoggingPreferences.enable(LogType.BROWSER, Level.ALL);
theOptions.setCapability(CapabilityType.LOGGING_PREFS, theLoggingPreferences);
DesiredCapabilities theCapabilities = DesiredCapabilities.chrome();
theCapabilities.setCapability(ChromeOptions.CAPABILITY, theOptions);
RemoteWebDriver theDriver = new RemoteWebDriver(theDriverService.getUrl(), theCapabilities);
theDriver.get(theGeneratedFile.toURI().toURL().toString());
ArrayList<Long> theResult = (ArrayList<Long>) theDriver.executeScript("return compile();");
int[] theBinaryDara = new int[theResult.size()];
for (int i = 0; i < theResult.size(); i++) {
long theLongValue = theResult.get(i);
theBinaryDara[i] = (int) (theLongValue);
}
List<LogEntry> theAll = theDriver.manage().logs().get(LogType.BROWSER).getAll();
for (LogEntry theEntry : theAll) {
System.out.println(theEntry.getMessage());
}
theDriver.close();
theDriverService.stop();
return theBinaryDara;
}
use of org.openqa.selenium.chrome.ChromeDriverService in project flow by vaadin.
the class ChromeBrowserTest method tryCreateHeadlessChromeDriver.
private static WebDriver tryCreateHeadlessChromeDriver(Consumer<ChromeOptions> optionsUpdater) {
ChromeOptions headlessOptions = createHeadlessChromeOptions();
optionsUpdater.accept(headlessOptions);
int port = findFreePort();
ChromeDriverService service = new ChromeDriverService.Builder().usingPort(port).build();
ChromeDriver chromeDriver = new ChromeDriver(service, headlessOptions);
return TestBench.createDriver(chromeDriver);
}
Aggregations