我正在尝试为 CI/CD 创建一个 dockerfile 和图像。我的项目堆栈是:Maven、Cucumber BDD、java、junit,在 pom.xml 中使用 bonigarcia 的 webdrivermanager 依赖项。
我们能够使用 dockerfile(如下所述)运行“hello world”打印语句,但是当我们尝试运行 chrome 并尝试将 chromebrowser 导出到位置时:
它给出了以下 错误:
我的 Dockerfile 是
enter code here`enter code here` FROM openjdk:8-jdk-alpine
RUN apk add --no-cache curl tar bash
ARG MAVEN_VERSION=3.3.9
ARG USER_HOME_DIR="/root"
RUN mkdir -p /usr/share/maven /usr/share/maven/ref \&& curl -fsSLhttp://apache.osuosl.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz \
| tar -xzC /usr/share/maven --strip-components=1 \&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"
RUN mvn -version
#FROM alpine:latest
#RUN apk update
#RUN apk fetch openjdk8
#RUN apk add openjdk8
ENV JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk
ENV PATH="$JAVA_HOME/bin:${PATH}"
RUN java -version
RUN javac -version
COPY src /usr/src/app/src
COPY pom.xml /usr/src/app
WORKDIR /usr/src/app
RUN pwd
RUN mvn test
#CMD ["mvn" , "test"]
我的步骤定义
@Given("User navigate to homepage")
public void userNavigateToHomepage() throws InterruptedException {
BasicConfigurator.configure();
WebDriverManager.chromedriver().setup();
System.setProperty("webdriver.chrome.silentOutput", "true"); //THIS will surpress all logs expect INFO
java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF); // this could be used to stop INFO logging in chrome driver
ChromeOptions options = new ChromeOptions();
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(ChromeOptions.CAPABILITY, options);
options.setHeadless(true);
options.addArguments("--no-sandbox"); // Bypass OS security model, MUST BE THE VERY FIRST OPTION
options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-extensions");
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("start-maximized"); // open Browser in maximized mode
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--proxy-server='direct://'");
options.addArguments("--proxy-bypass-list=*");
options.addArguments("--window-size=1920,1080");
options.addArguments("--start-maximized");
options.addArguments("--incognito");
options.merge(cap);
ChromeDriver driver = new ChromeDriver(options);
logger.info("......Hello world.......");
logger.info("......Hello world.......");
logger.info("launching url");
driver.get("https://opensource-demo.orangehrmlive.com/");
String actual = driver.getTitle();
logger.info("Title of the page is :" + actual);
driver.findElement(By.id("txtUsername")).sendKeys("admin");
Thread.sleep(3000);
logger.info(".......Closing the test now......");
logger.info(".......Closing the test now......");
logger.info(".......Closing the test now......");
driver.quit();
}
}
文件
enter code here <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>TestDocker</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cucumber.version>4.3.0</cucumber.version>
<selenium.version>3.141.5</selenium.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.5</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
<build>
<defaultGoal>compile</defaultGoal>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<includes>
<include>TestRunner</include>
</includes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
我尝试了各种链接的解决方案,但没有任何效果。有人可以指导我。提前致谢