标签:maven 查找 webdriver enter property command resources comm repo
由于项目情况以及时间问题,本篇暂时仅用于记录当时web项目自动化配置相关信息(历史篇:在草稿箱存了老久了??)
Java 工程的 pom 文件配置信息
<?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>auto-tests</groupId>
<artifactId>auto-test-punish</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<!-- 文件拷贝时的编码 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- 编译时的编码 -->
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<aspectj.version>1.8.10</aspectj.version>
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!--testng 配置, 配置最新版本报错 RELEASE -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
</dependency>
<!-- allure 生成报告 mvn io.qameta.allure:allure-maven:serve -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.13.0</version>
</dependency>
<!-- fast json -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
<!-- slf4j 日志门面,无具体实现
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
</dependency>
-->
<!-- log4J 无法格式化日志输出
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>
<!-- apache io 处理 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<!-- 打包配置 mvn package assembly:single; mvn clean install 会install 到 maven 仓库-->
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>log4j.properties</include>
</includes>
</resource>
</resources>
<plugins>
<!-- 指定maven JDK 编译版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF8</encoding>
</configuration>
</plugin>
<plugin>
<!-- maven-surefire-plugin 用于 allure 查找测试用例 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<!-- 测试失败后,是否忽略并继续测试 -->
<testFailureIgnore>true</testFailureIgnore>
<suiteXmlFiles>
<!-- testng 配置文件名称 src 路径后续修改-->
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<!--设置参数命令行 -->
<argLine>
<!-- UTF-8编码 -->
-Dfile.encoding=UTF-8
<!-- 配置拦截器 -->
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<systemPropertyVariables>
<!-- 配置 allure 结果存储路径, 且会覆盖 allure 中的配置-->
<allure.results.directory>${project.build.directory}/allure-results/${maven.build.timestamp}</allure.results.directory>
</systemPropertyVariables>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
<!-- maven-assembly-plugin 支持自定义的打包结构插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<archive>
<manifest>
<mainClass>com.zzw.PunishCenterTest</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
官网 http://allure.qatools.ru/
文档 https://docs.qameta.io/allure/
下载 https://github.com/allure-framework/allure2/releases
下载后配置环境变量,即可使用 allure 命令
<properties>
<aspectj.version>1.8.10</aspectj.version>
<!-- 与下列 allure 结果生成有关 -->
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
</properties>
<dependencies>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.13.0</version>
<!-- <scope>test</scope> 只限于 test 测试包 -->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<argLine> -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"</argLine>
<systemPropertyVariables>
<!-- 配置 allure 结果存储路径, 且会覆盖 allure 中的配置-->
<allure.results.directory>${project.build.directory}/allure-results/${maven.build.timestamp}</allure.results.directory>
</systemPropertyVariables>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
格式: allure [options] [command] [command options]
Options:
--help 打印命令行帮助信息
-q, --quiet 打开静音模式,默认为 false
-v, --verbose 打开详细模式,默认为 false
--version 打印 allure 版本号
Commands:
generate 生成报告命令
Usage: generate [options] 生成的 allure 结果目录
Options:
-c, --clean 在生成新的 Allure 报告目录之前,清除该目录. 默认不清除
--config Allure 命令行配置路径. 如果通过--profile and --configDirectory 覆盖指定值
--configDirectory Allure命令行配置目录。默认使用ALLURE_HOME 目录.
--profile Allure 命令行配置文件
-o, --report-dir, --output 生成 Allure 报告的目录. 默认为 allure-report
serve 报告服务命令
Usage: serve [options] The directories with allure results
Options:
--config Allure 命令行配置路径. 如果通过--profile and --configDirectory 覆盖指定值
--configDirectory Allure命令行配置目录。默认使用ALLURE_HOME 目录.
-h, --host 指定用于启动报告 web 服务的主机
-p, --port 指定用于启动报告 web 服务的端口,默认为 0
--profile Allure 命令行配置文件
open 打开生成的报告
Usage: open [options] 报告目录
Options:
-h, --host 指定用于启动报告 web 服务的主机
-p, --port T指定用于启动报告 web 服务的端口,默认为 0
plugin 生成报告
Usage: plugin [options]
Options:
--config Allure 命令行配置路径. 如果通过--profile and --configDirectory 覆盖指定值
--configDirectory Allure命令行配置目录。默认使用ALLURE_HOME 目录.
--profile Allure 命令行配置文件
allure generate -c <directory-with-results> -o <directory-with-report>
ChromeOptions options = new ChromeOptions();
// Chrome 75 版本以下
// options.addArguments("disable-infobars");
// Chrome 75 版本以上, 去除自动化控制
options.setExperimentalOption("useAutomationExtension", false);
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
// 去除密码保存提示
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
// 直接最大化
options.addArguments("start-maximized");
// 去除 [SEVERE]: Timed out receiving message from renderer: 0.100 信息
// https://stackoverflow.com/questions/61201270/timed-out-receiving-message-from-renderer-in-selenium
System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true");
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "D:\\tools\\Python\\Python37\\chromedriver.exe");
ChromeDriver chrome = new ChromeDriver(options);
// 会有个变化过程
// chrome.manage().window().maximize();
EventFiringWebDriver eventFiringWebDriver = new EventFiringWebDriver(chrome);
eventFiringWebDriver.register(new WebEventListener());
driver = eventFiringWebDriver;
标签:maven 查找 webdriver enter property command resources comm repo
原文地址:https://www.cnblogs.com/zeo-to-one/p/13513300.html