2017-02-11 97 views
0

我有一個使用TestNG框架在Selenium中編寫的腳本。這個腳本通過一個xml文件執行。由於我們沒有主要的方法,我怎樣才能將這個腳本導出到可運行的JAR文件?將Eclipse的Selenium TestNG腳本導出到可運行的jar中

+0

你用什麼IDE? –

+2

[如何爲Testng創建可執行jar文件和runnnig點應該是Xml文件](http://stackoverflow.com/questions/16393223/how-to-create-a-executable-jar-file testng-and-the-runnnig-point-should-t-t) – djangofan

回答

0

我將這個問題標記爲一個複製(而這段代碼片段來自於複製問題),但基本上可以編寫一個公共靜態void main方法來掃描測試或加載現有的testng.xml文件。然後,你只需要使用諸如Maven Shade插件之類的東西來打包它。

public static void main(String[] args) { 
TestListenerAdapter tla = new TestListenerAdapter(); 
TestNG testng = new TestNG(); 
testng.setTestClasses(new Class[] { test_start.class }); 
testng.addListener(tla); 
testng.run(); 
} 

我用WebDriverManager項目來管理我的驅動程序庫。我會讓.jar加載這些外部的。

+0

我也試過,但是在控制檯中卻沒有其他的東西。 – Akshay

+0

只需閱讀TestNG文檔。網絡上還有其他類似的例子。 – djangofan

+0

謝謝大家。我有這個解決方案。 – Akshay

相關問題