Selenium Java Part5
Selenium Java Part5
2) Can you arrange the below testng.xml tags from parent to child?
<test>
<suite>
<class>
<methods>
<classes>
<suite><test><classes><class><methods>
TestNG.xml file is an XML file which contains all the Test configuration
and this XML file can be used to run and organize our test.
Asserts helps us to verify the conditions of the test and decide whether
test has failed or passed. Some of the common assertions are:
– assertEqual(String actual,String expected)
– assertTrue(condition)
– assertFalse(condition)
5) What is Soft Assert in TestNG?
@Test(enabled = false)
public void test() {
System.out.println("This test is disabled");
}
@Test(enabled = false)
public void test() {
System.out.println("This test is ignored");
}
12) What are the different ways to produce reports for TestNG results?
14) What is the time unit we specify in test suites and test cases?
– Command Line
– Maven
– IDE
The invocationcount attribute tells how many times TestNG should run a
test method. In this example, the method testCase will be invoked ten
times:
@Test(invocationCount = 10)
public void testCase(){
System.out.println("Invocation method");
}
@Test(invocationCount = 3, threadPoolSize = 3)
public void testThreadPools() {
System.out.printf("Thread Id : %s%n", Thread.currentThread().getId());
}
While running test methods there can be cases where certain test
methods get struck or may take longer time than to complete the
execution than the expected. We need to handle these type of cases by
specifying Timeout and proceed to execute further test cases / methods
@Test(timeOut=5000)
public void executeTimeOut() throws InterruptedException{
Thread.sleep(3000);
}
JUnit is an open source Unit Testing Framework for JAVA. It is useful for
Java Developers to write and run repeatable tests.
– @Test
– @ParameterizedTest
– @RepeatedTest
– @TestFactory
– @TestTemplate
– @Disabled
– @Tag
– @AfterAll
– @BeforeAll
– @BeforeEach
– @AfterEach
– @TestInstance
@Test (priority=1)
public void openBrowser() {
driver = new FirefoxDriver();
}
@Test (priority=2)
public void launchGoogle() {
driver.get("http://www.google.co.in");
}