mvn test 傳遞系統變量給TestNG
廢話一下。因為五一我們國內BPM要遷移數據庫,所以需要留一部分測試來協助運維,在遷移完成后點檢整個項目,我很自覺地報名(安排)了
然后之前剛好寫了一個點檢所有模塊文檔的功能,這次又可以用上了。但是單個環境執行的話需要的時間太久了,所以在想能不能根據每個領域來點檢(我們是每個人負責幾個領域),如果自己點檢自己的領域,然后哪個模塊點檢失敗自己去看就效率高很多了
一開始是想著把領域寫死,對應的人寫對應的領域執行對應的程序包,隨即一想不行太low了便作罷,于是便搜索一下,發現還真有解決辦法,下面上我的實施過程(這是原帖地址:http://www.rzrgm.cn/wade-xu/p/4857471.html)
1,我是直接在plugin里加了一個標簽systemPropertyVariables,在里面加上自定義的系統變量標簽moduleNumber
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<forkMode>once</forkMode>
<argLine>-Dfile.encoding=UTF-8</argLine>
<encoding>UTF-8</encoding>
<suiteXmlFiles>
<!--你的testng.xml文件路徑-->
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<moduleNumber>${bpm.autotest.moduleNumber}</moduleNumber>
</systemPropertyVariables>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
2,然后定義profile,給自定義moduleNumber賦值,我們領域定位的方式剛好可以用nth:child(index)來定位,所以對應的領域寫好對應的index即可
<profiles>
<profile>
<id>所有領域</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<bpm.autotest.moduleNumber>0</bpm.autotest.moduleNumber>
</properties>
</profile>
<profile>
<id>公司公共</id>
<properties>
<bpm.autotest.moduleNumber>1</bpm.autotest.moduleNumber>
</properties>
</profile>
</profiles>
2.1,我這里配置了一個默認值,如果啥參數沒傳,就表示點檢所有領域,代碼里加個判斷

3,然后參數傳遞進來后,代碼需要修改,不能用之前的遍歷所有領域,而是根據領域編號來(這里需要提到一個點,單個領域的話先點擊哪個領域,那個領域的編號就是幾,所以需要按照順序先把所有領域按照遍歷順序點一遍,加載好index,不然就會亂)

4,再就是在BaseTest里加一個初始化動作,把領域跟對應的index存到集合中

5,然后在測試人員傳遞對應的領域名稱后,通過System.getProperty("moduleNumber")就可以拿到對應的index來定位領域了
輸入dos命令:mvn test -P 公司公共


浙公網安備 33010602011771號