Execute TestNg Project using batch file
Here, we have one sample class called SampleTest.java in JAVA Project which would open Google in chrome browser and verify the page title and then closes the browser at the end.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
| import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; public class SampleTest { WebDriver driver; @BeforeMethod public void setup() { // Initialize driver object System.setProperty( "webdriver.chrome.driver" , System.getProperty( "user.dir" ) + "/lib/chromedriver.exe" ); driver = new ChromeDriver(); // Launch Application on browser driver.get(baseUrl); } @Test public void test01() { String expectedPageTitle = "Google" ; String actualPageTitle = "" ; // Fetch page title and store it in a variable actualPageTitle = driver.getTitle(); // Print title System.out.println(actualPageTitle); if (actualPageTitle.equals(expectedPageTitle)) { System.out.println( "Test case passed" ); } else { System.out.println( "Test case Failed" ); } } @AfterMethod public void tearDonw() { // close browser driver.close(); } } |
Create TestNg file in Project
We will invoke below TestNg.xml file using batch file (.bat)
1
2
3
4
5
6
7
8
9
10
11
| <suite name= "Selenium Tests" verbose= "3" parallel= "tests" thread-count= "1" > <test name= "Test1" > <classes> < class name= "SampleTest" /> </classes> </test> </suite> |
Create LIB folder in project and put all the external Jars into it
As we new below 2 external Jars for this sample Project :
a)Selenium standalone Jar
b)TestNg Jar
The Sample Project would look like :
Create batch(.bat) file
1
2
3
4
5
| set projectPath=C:\Users\workspace\TestProject cd\ cd %projectPath% set classpath=%projectPath%\bin;%projectPath%\lib\*; java org.testng.TestNG testng.xml |
Save above commands in .bat file and now you can simply execute the project by just double click on batch file.
If you really like the information provided above, please don’t forget to like us on Facebook, you can also leave the comment.
Комментариев нет:
Отправить комментарий