Skip to content

Commit

Permalink
修改窗口大小
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-roy committed Nov 28, 2024
1 parent faba009 commit 5ba2bbc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import com.google.common.base.Throwables;
import io.github.bonigarcia.wdm.WebDriverManager;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
Expand All @@ -18,6 +15,10 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

import static com.goodluck.checkin.utils.SeleniumUtils.safeWaitForElement;

/**
Expand All @@ -41,9 +42,13 @@ private static WebDriver initBrowser() {
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
// options.addArguments("--start-maximized");
options.addArguments("--headless"); // 启用无头模式
options.addArguments("--no-sandbox"); // 在某些 Linux 环境下需要
options.addArguments("--disable-dev-shm-usage"); // 解决共享内存问题
// 启用无头模式
options.addArguments("--headless");
// 在某些 Linux 环境下需要
options.addArguments("--no-sandbox");
// 解决共享内存问题
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--window-size=1920,1080");
WebDriver browser = new ChromeDriver(options);
return browser;
}
Expand All @@ -62,6 +67,9 @@ public void loginAndCheckIn() {
By.cssSelector("a.login-btn.navbar-button")));
loginTriggerButton.click();

// File screenshot = ((TakesScreenshot) browser).getScreenshotAs(OutputType.FILE);
// Files.copy(screenshot.toPath(), Paths.get("screenshot.png"));

// 等待表单内容加载完成
WebElement usernameField = wait.until(ExpectedConditions.visibilityOfElementLocated(
By.cssSelector("input[name='username']")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ private static WebDriver initBrowser() {
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
// options.addArguments("--start-maximized");
options.addArguments("--headless"); // 启用无头模式
options.addArguments("--no-sandbox"); // 在某些 Linux 环境下需要
options.addArguments("--disable-dev-shm-usage"); // 解决共享内存问题
// 启用无头模式
options.addArguments("--headless");
// 在某些 Linux 环境下需要
options.addArguments("--no-sandbox");
// 解决共享内存问题
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--window-size=1920,1080");
WebDriver browser = new ChromeDriver(options);
return browser;
}
Expand Down

0 comments on commit 5ba2bbc

Please sign in to comment.