从0开始搭建⾃动化测试框架(⼀)
此系列是⾃⼰尝试搭建web⾃动化测试框架之路的记录,不定时更新。
1. IDE: IntelliJ IDEA(version 2020.1.3)
2. 框架: Selenium(Java) + TestNG + allure
3. 搭建过程:
Maven:
安装:这⾥以3.6.0版本为例, 下载.zip后,解压到任意⽬录,我解压⽬录是D:\apache-maven-3.6.0
IDEA ⾃带maven, 设置是在 file -> setting, 打开后到maven,如下:
Maven home directory: maven 的安装⽬录,这⾥是IDEA⾃带的maven, 所以⽬录⽐较奇怪
User settings file: ⽤户设置⽂件所在⽬录
Local repository: ⽤户本地仓库,⽤来存放从远程仓库下载下来的⽂件。
Maven project: IDEA⾥依次点击 file -> New - > Project ,如下所⽰,在Maven⾥选中Create from archetype,然后选择maven-archetype-quickstart,点击next
进⼊如下页⾯后,依次填⼊必要信息,这⾥project 名称我直接写成automation, GroupId根据个⼈情况填写,这⾥以Test为例。点击next
在如下页⾯填写对应信息,这⾥项⽬名就叫AutoTest. 点击next, 进⼊如下页⾯,我勾选了Local repository的 Override 复选框,即使⽤我指定的本地仓库,点击Finish完成项⽬创建。
项⽬创建完成后,IDEA会执⾏Maven初始化命令下载必要的包,下载完成后,进⾏l配置,如下:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mavenpiler.source>11.0</mavenpiler.source>
<mavenpiler.target>11.0</mavenpiler.target>
<xmlFileName&l</xmlFileName>
&port.dir>test-output</port.dir>
<aspectj.version>1.9.6</aspectj.version>
<ashot-version>1.5.4</ashot-version>
<allure-testng-version>2.13.10</allure-testng-version>
</properties>
<dependencies>
<dependency>
<groupId&stng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId&acle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.7.0.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId&le.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>${allure-testng-version}</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see /ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see /ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> <plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<skipTests>false</skipTests>
<suiteXmlFiles>
<suiteXmlFile>${xmlFileName}</suiteXmlFile>
</suiteXmlFiles>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<!-- path to generate allure-result -->
<systemProperties>
<property>
<name&sults.directory</name>
<value>./allure/allure-results</value>
</property>
</systemProperties>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see /ref/current/maven-core/lifecycles.html#site_Lifecycle --> <plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
log4j2 appender</pluginManagement>
</build>
View Code
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="/log4j/">
<!-- output log to file -->
<appender name="fileAppender" class="org.apache.log4j.FileAppender">
<!-- log file name -->
<param name="File" value="./src/main/java/com/changefinancial/log/logfile.log"/>
<param name="Append" value="false"/>
<param name="Threshold" value="INFO"/>
<!-- style of output log -->`
<layout class="org.apache.log4j.PatternLayout">
<!-- format of output log -->
<param name="ConversionPattern" value="[%d{MMdd HH:mm:ss SSS\} %-5p] [%t] %c{3\} - %m%n"/> </layout>
</appender>
<root>
<!-- set log level -->
<level value="INFO"/>
<appender-ref ref="fileAppender"/>
</root>
</log4j:configuration>
View Code
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论