Pārlūkot izejas kodu

修改测试firefox接口

xuzuoyun 5 gadi atpakaļ
vecāks
revīzija
9e54164a7c

+ 18 - 5
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/TestJob.java

@@ -1,18 +1,22 @@
 package org.jeecg.modules.ctop.job;
 
 import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.chrome.ChromeDriverService;
 import org.openqa.selenium.firefox.FirefoxDriver;
 import org.openqa.selenium.firefox.FirefoxOptions;
+import org.openqa.selenium.firefox.GeckoDriverService;
 import org.quartz.Job;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
 
+import java.io.File;
 import java.util.concurrent.TimeUnit;
 
 public class TestJob implements Job {
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
         System.setProperty("webdriver.gecko.driver", "/usr/lib/geckodriver");
+        GeckoDriverService service = new GeckoDriverService.Builder().usingDriverExecutable(new File("/usr/lib/geckodriver")).usingAnyFreePort().build();
         FirefoxOptions options = new FirefoxOptions();
         options.addArguments("--headless");
         options.addArguments("--incognito");
@@ -20,10 +24,19 @@ public class TestJob implements Job {
         options.addArguments("--disable-gpu");
         options.addArguments("--window-size=1290,1080");
         WebDriver driver = new FirefoxDriver(options);
-        driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
-        driver.manage().timeouts().setScriptTimeout(5, TimeUnit.SECONDS);
-        driver.get("http://b.e.kuaishou.com");
-        System.out.println(driver.getPageSource());
-        driver.quit();
+        try {
+            service.start();
+            driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
+            driver.manage().timeouts().setScriptTimeout(5, TimeUnit.SECONDS);
+            driver.get("http://b.e.kuaishou.com");
+            System.out.println(driver.getPageSource());
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            driver.quit();
+            service.stop();
+        }
+
+
     }
 }