Windows&Appium&Java&Python自動化測試-開發環境
一、摘要
本篇博文,主要介紹借助Appium做移動端自動化測試的開發環境搭建,包括Java和Python
Java環境:Appium+Maven+Idea+TestNG+Ngreport
Python環境:Appium+Pycharm+Unittest
二、Java環境
用MAVEN建立項目的好處:
優點一:項目非常大時,可借助Maven將一個項目拆分成多個工程,最好是一個模塊對應一個工程,利於分工協作。而且模塊之間還是可以發送消息的。
優點二:借助Maven,可將jar包僅僅保存在“倉庫”中,有需要該文件時,就引用該文件接口,不需要復制文件過來占用空間。
優點三:借助Maven可以以規範的方式下載jar包,因為所有的知名框架或第三方工具的jar包已經按照統一的規範存放到了Maven的中央倉庫中。
優點四:Maven會自動將你要加入到項目中的jar包導入,不僅導入,而且還會將該jar包所依賴的jar包都自動導入進來。
官方地址:http://maven.apache.org/download.cgi
下載安裝後配置MVN環境變量,如下圖所示
變量名可用M2_HOME或者MAVEN_HOME
變量值就是安裝目錄,如果JDK配的很遛,這個同理
PATH:%M2_HOME%\bin;
檢查Maven環境
配置MVN本地倉庫物理地址,也就是maven會從中央倉庫下載需要的jar包到本地
再次路徑下打開setting.xml,配置項如下,註意XML節點,地址隨意
配置MVN中央倉庫
保存配置後,將該文件復制如下路徑下
此處單配置了一個鏡像地址,是阿裏雲的地址,官方地址下載太慢可以通過這個位置的配置代替
配置IDEA,IDEA官方下載地址:https://www.jetbrains.com/idea/download/,默認安裝即可
打開IDEA,新建一個maven項目,檢查Maven的配置如圖所示,箭頭所指兩個配置已經更新到了前邊步驟中的位置
IDEA會在右下角(註意右下角)提示你是否需要自動安裝pom配置的jar包,一旦出現,就要enable它
找到pom.xml文件,打開它,配置項目所需的依賴包,如下圖配置
1 <dependencies> 2 <!--- 導入webdriver相關--> 3 <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server --> 4 <dependency> 5 <groupId>org.seleniumhq.selenium</groupId> 6 <artifactId>selenium-server</artifactId> 7 <version>3.12.0</version> 8 </dependency> 9 10 <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> 11 <dependency> 12 <groupId>org.seleniumhq.selenium</groupId> 13 <artifactId>selenium-java</artifactId> 14 <version>3.12.0</version> 15 </dependency> 16 17 <!-- https://mvnrepository.com/artifact/org.testng/testng --> 18 <dependency> 19 <groupId>org.testng</groupId> 20 <artifactId>testng</artifactId> 21 <version>6.14.3</version> 22 <scope>test</scope> 23 </dependency> 24 <!-- https://mvnrepository.com/artifact/io.appium/java-client --> 25 <dependency> 26 <groupId>io.appium</groupId> 27 <artifactId>java-client</artifactId> 28 <version>4.0.0</version> 29 </dependency> 30 <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api --> 31 <dependency> 32 <groupId>org.apache.logging.log4j</groupId> 33 <artifactId>log4j-api</artifactId> 34 <version>2.11.1</version> 35 </dependency> 36 <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core --> 37 <dependency> 38 <groupId>org.apache.logging.log4j</groupId> 39 <artifactId>log4j-core</artifactId> 40 <version>2.11.1</version> 41 </dependency> 42 <dependency> 43 <groupId>log4j</groupId> 44 <artifactId>log4j</artifactId> 45 <version>1.2.17</version> 46 <scope>test</scope> 47 </dependency> 48 </dependencies>
配置監聽
1 <build> 2 <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> 3 <plugins> 4 <plugin> 5 <groupId>org.apache.maven.plugins</groupId> 6 <artifactId>maven-surefire-plugin</artifactId> 7 <version>2.20.1</version> 8 <configuration> 9 <properties> 10 <property> 11 <name>usedefaultlisteners</name> 12 <value>false</value> 13 </property> 14 <property> 15 <!--使用reportng的 listener 生成測試報告--> 16 <name>listener</name> 17 <value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value> 18 </property> 19 </properties> 20 <testFailureIgnore>true</testFailureIgnore> 21 <!--指定testng.xml的位置--> 22 <suiteXmlFiles> 23 <file>testng.xml</file> 24 </suiteXmlFiles> 25 <workingDirectory>target/</workingDirectory> 26 <forkMode>always</forkMode> 27 </configuration> 28 </plugin> 29 <plugin> 30 <artifactId>maven-clean-plugin</artifactId> 31 <version>3.0.0</version> 32 </plugin> 33 <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> 34 <plugin> 35 <artifactId>maven-resources-plugin</artifactId> 36 <version>3.0.2</version> 37 </plugin> 38 <plugin> 39 <artifactId>maven-compiler-plugin</artifactId> 40 <version>3.7.0</version> 41 </plugin> 42 <plugin> 43 <artifactId>maven-jar-plugin</artifactId> 44 <version>3.0.2</version> 45 </plugin> 46 <plugin> 47 <artifactId>maven-install-plugin</artifactId> 48 <version>2.5.2</version> 49 </plugin> 50 <plugin> 51 <artifactId>maven-deploy-plugin</artifactId> 52 <version>2.8.2</version> 53 </plugin> 54 </plugins> 55 </pluginManagement> 56 </build>
到此Java環境完成
Pom中配置的依賴可以在MVN的中央庫http://mvnrepository.com/, 檢索到你想要的包,配置進去即可
三、Python環境
Python的環境相對簡單很多,因為已經有了unittest,我們再安裝Appium相關模塊即可
在CMD中運行 pip install Appium-Python-Client
Pycharm官方下載地址:https://www.jetbrains.com/pycharm/download/
Windows&Appium&Java&Python自動化測試-開發環境