InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What Are @factory And @dataprovider Annotation? |
|
Answer» @FACTORY: A factory will execute all the TEST methods present inside a test class using a separate instance of the respective class with different set of data. @DataProvider: A test method that uses DataProvider will be executed the specific methods multiple number of times based on the data PROVIDED by the DataProvider. The test method will be executed using the same instance of the test class to which the test method belongs. @Factory: A factory will execute all the test methods present inside a test class using a separate instance of the respective class with different set of data. @DataProvider: A test method that uses DataProvider will be executed the specific methods multiple number of times based on the data provided by the DataProvider. The test method will be executed using the same instance of the test class to which the test method belongs. |
|
| 2. |
What Does The Test Timeout Mean In Testng? |
|
Answer» The maximum number of milliseconds a test case should take.
In this example, the function testCase1 will be INVOKED ten times from three DIFFERENT threads. ADDITIONALLY, a time-out of ten SECONDS guarantees that none of the threads will block on this THREAD forever. The maximum number of milliseconds a test case should take. In this example, the function testCase1 will be invoked ten times from three different threads. Additionally, a time-out of ten seconds guarantees that none of the threads will block on this thread forever. |
|
| 3. |
What Is The Use Of @test(threadpoolsize=x)? |
|
Answer» The threadPoolSize attribute TELLS to form a thread pool to run the test method through multiple threads. Note: This attribute is IGNORED if invocationCount is not specified
In this example, the method testCase1 will be invoked from three different threads. The threadPoolSize attribute tells to form a thread pool to run the test method through multiple threads. Note: This attribute is ignored if invocationCount is not specified In this example, the method testCase1 will be invoked from three different threads. |
|
| 4. |
What Is The Use Of @test(invocationcount=x)? |
|
Answer» The invocationcount attribute tells how many TIMES TESTNG should run a test method
In this EXAMPLE, the method testCase1 will be INVOKED ten times. The invocationcount attribute tells how many times TestNG should run a test method In this example, the method testCase1 will be invoked ten times. |
|
| 5. |
How To Run Testng Using Command Prompt? |
|
Answer» RUN the TestNG USING command prompt Open command prompt and USE the below code
Run the TestNG using command prompt Open command prompt and use the below code |
|
| 6. |
List Out Various Ways In Which Testng Can Be Invoked? |
|
Answer» TestNG can be invoked in the FOLLOWING ways: TestNG can be invoked in the following ways: |
|
| 7. |
What Is The Time Unit We Specify In Test Suites And Test Cases? |
|
Answer» We specify the time unit in TEST suites and test CASES is in MILLISECONDS. We specify the time unit in test suites and test cases is in milliseconds. |
|
| 8. |
How To Write Regular Expression In Testng.xml File To Search @test Methods Containing “smoke” Keyword.? |
|
Answer» Regular EXPRESSION to find @TEST methods CONTAINING keyword “smoke” is as mentioned below. Regular expression to find @Test methods containing keyword “smoke” is as mentioned below. |
|
| 9. |
What Is The Use Of @listener Annotation In Testng? |
|
Answer» TestNG LISTENERS are USED to configure reports and logging. One of the most widely used listeners in testNG is ITestListener interface. It has methods like onTestStart, onTestSuccess, onTestFailure, onTestSkipped etc. We should implement this interface creating a listener class of our own. NEXT we should add the listeners annotation (@Listeners) in the Class which was created. TestNG listeners are used to configure reports and logging. One of the most widely used listeners in testNG is ITestListener interface. It has methods like onTestStart, onTestSuccess, onTestFailure, onTestSkipped etc. We should implement this interface creating a listener class of our own. Next we should add the listeners annotation (@Listeners) in the Class which was created. |
|
| 10. |
What Are The Different Ways To Produce Reports For Testng Results? |
|
Answer» TestNG offers two ways to produce a report: Listeners implement the INTERFACE org.testng.ITestListener and are NOTIFIED in real time of when a test starts, PASSES, fails, etc… Reporters implement the interface org.testng.IReporter and are notified when all the suites have been run by TestNG. The IReporter instance receives a list of OBJECTS that describe the ENTIRE test run. TestNG offers two ways to produce a report: Listeners implement the interface org.testng.ITestListener and are notified in real time of when a test starts, passes, fails, etc… Reporters implement the interface org.testng.IReporter and are notified when all the suites have been run by TestNG. The IReporter instance receives a list of objects that describe the entire test run. |
|
| 11. |
How Testng Allows To State Dependencies? |
Answer»
|
|
| 12. |
How To Ignore A Test Case In Testng? |
|
Answer» To IGNORE the test CASE we USE the parameter ENABLED = false to the @Test annotation.
To ignore the test case we use the parameter enabled = false to the @Test annotation. |
|
| 13. |
How To Skip A @test Method From Execution In Testng? |
|
Answer» By using throw new SkipException() Once SkipException() THROWN, remaining part of that test METHOD will not be executed and CONTROL will goes directly to NEXT test method execution.
By using throw new SkipException() Once SkipException() thrown, remaining part of that test method will not be executed and control will goes directly to next test method execution. |
|
| 14. |
How To Disable A Test Case In Testng? |
|
Answer» To disable the test case we USE the PARAMETER ENABLED = FALSE to the @Test annotation. @Test(enabled = false) To disable the test case we use the parameter enabled = false to the @Test annotation. @Test(enabled = false) |
|
| 15. |
How To Exclude A Particular Test Group From A Test Case Execution? |
|
Answer» By ADDING the exclude tag in the testng.xml By adding the exclude tag in the testng.xml |
|
| 16. |
How To Exclude A Particular Test Method From A Test Case Execution? |
|
Answer» By adding the EXCLUDE TAG in the testng.xml
By adding the exclude tag in the testng.xml |
|
| 17. |
How To Run Test Cases In Parallel Using Testng? |
|
Answer» we can use “parallel” attribute in testng.xml to accomplish parallel test execution in TestNG The parallel attribute of suite tag can accept four values: tests: All the test CASES inside <test> tag of testng.xml file will run parallel classes: All the test cases inside a java class will run parallel METHODS: All the methods with @Test annotation will EXECUTE parallel instances: Test cases in same instance will execute parallel but two methods of two DIFFERENT instances will run in different thread. <suite name="softwaretestingmaterial" parallel="methods"> we can use “parallel” attribute in testng.xml to accomplish parallel test execution in TestNG The parallel attribute of suite tag can accept four values: tests: All the test cases inside <test> tag of testng.xml file will run parallel classes: All the test cases inside a java class will run parallel methods: All the methods with @Test annotation will execute parallel instances: Test cases in same instance will execute parallel but two methods of two different instances will run in different thread. <suite name="softwaretestingmaterial" parallel="methods"> |
|
| 18. |
How To Create Group Of Groups In Testng? |
|
Answer» Groups can also INCLUDE other groups. These groups are called MetaGroups. For example, you might want to define a GROUP all that includes smokeTest and functionalTest. LET’s modify our testng.xml FILE as FOLLOWS:
Groups can also include other groups. These groups are called MetaGroups. For example, you might want to define a group all that includes smokeTest and functionalTest. Let’s modify our testng.xml file as follows: |
|
| 19. |
How To Run A Group Of Test Cases Using Testng? |
|
Answer» TESTNG allows you to perform sophisticated groupings of test methods. Not only can you DECLARE that methods belong to GROUPS, but you can also specify groups that contain other groups. Then TestNG can be invoked and asked to INCLUDE a certain set of groups (or regular expressions) while excluding another set. This gives you maximum flexibility in how you partition your tests and doesn’t require you to recompile anything if you want to run two different sets of tests back to back. Groups are specified in your testng.xml file and can be found either under the <test> or <suite> tag. Groups specified in the <suite> tag APPLY to all the <test> tags underneath.
TestNG allows you to perform sophisticated groupings of test methods. Not only can you declare that methods belong to groups, but you can also specify groups that contain other groups. Then TestNG can be invoked and asked to include a certain set of groups (or regular expressions) while excluding another set. This gives you maximum flexibility in how you partition your tests and doesn’t require you to recompile anything if you want to run two different sets of tests back to back. Groups are specified in your testng.xml file and can be found either under the <test> or <suite> tag. Groups specified in the <suite> tag apply to all the <test> tags underneath. |
|
| 20. |
How Can We Create Data Driven Framework Using Testng? |
|
Answer» By using @DataProvider annotation, we can CREATE a Data Driven Framework.
By using @DataProvider annotation, we can create a Data Driven Framework. |
|
| 21. |
What Is Parameterized Testing In Testng? |
|
Answer» Parameterized tests ALLOW developers to run the same test over and over again using DIFFERENT VALUES. There are two WAYS to set these parameters:
Parameterized tests allow developers to run the same test over and over again using different values. There are two ways to set these parameters: |
|
| 22. |
How To Set Test Case Priority In Testng? |
|
Answer» We use priority attribute to the @Test ANNOTATIONS. In case priority is not set then the test SCRIPTS execute in alphabetical order.
Output:
We use priority attribute to the @Test annotations. In case priority is not set then the test scripts execute in alphabetical order. Output: |
|
| 23. |
What Is Exception Test In Testng? |
|
Answer» TestNG gives an option for tracing the Exception handling of CODE. You can VERIFY whether a code throws the expected exception or not. The expected exception to VALIDATE while running the test case is MENTIONED using the expectedExceptions attribute value along with @Test annotation. TestNG gives an option for tracing the Exception handling of code. You can verify whether a code throws the expected exception or not. The expected exception to validate while running the test case is mentioned using the expectedExceptions attribute value along with @Test annotation. |
|
| 24. |
What Is Hard Assert In Testng? |
|
Answer» Hard ASSERT throws an AssertException IMMEDIATELY when an assert statement FAILS and test suite CONTINUES with NEXT @Test. Hard Assert throws an AssertException immediately when an assert statement fails and test suite continues with next @Test. |
|
| 25. |
What Is Soft Assert In Testng? |
|
Answer» Soft Assert COLLECTS ERRORS during @Test. Soft Assert does not throw an exception when an assert fails and would continue with the next STEP after the assert statement. If there is any exception and you WANT to throw it then you need to use assertAll() method as a last statement in the @Test and test suite again continue with next @Test as it is. Soft Assert collects errors during @Test. Soft Assert does not throw an exception when an assert fails and would continue with the next step after the assert statement. If there is any exception and you want to throw it then you need to use assertAll() method as a last statement in the @Test and test suite again continue with next @Test as it is. |
|
| 26. |
What Is Testng Assert And List Out Common Testng Assertions? |
|
Answer» TestNG Asserts HELP us to verify the condition of the test in the middle of the test run. BASED on the TestNG ASSERTIONS, we will consider a successful test only if it is completed the test run without throwing any exception. Some of the common assertions supported by TestNG are:
TestNG Asserts help us to verify the condition of the test in the middle of the test run. Based on the TestNG Assertions, we will consider a successful test only if it is completed the test run without throwing any exception. Some of the common assertions supported by TestNG are: |
|
| 27. |
How To Pass Parameter Through Testng.xml File To A Test Case? |
|
Answer» We COULD define the parameters in the testng.xml file and then reference those parameters in the source files. Create a JAVA test class, say, ParameterizedTest.java and add a test method say parameterizedTest() to the test class. This method takes a STRING as input parameter. Add the annotation @Parameters(“browser”) to this method.
The parameter would be passed a value from testng.xml, which we will see in the next step. We could set the parameter using the below syntax in the testng.xml file. <parameter name="browser" value="firefox"/> Here, name attribute represents the parameter name and value represents the value of that parameter. We could define the parameters in the testng.xml file and then reference those parameters in the source files. Create a java test class, say, ParameterizedTest.java and add a test method say parameterizedTest() to the test class. This method takes a string as input parameter. Add the annotation @Parameters(“browser”) to this method. The parameter would be passed a value from testng.xml, which we will see in the next step. We could set the parameter using the below syntax in the testng.xml file. <parameter name="browser" value="firefox"/> Here, name attribute represents the parameter name and value represents the value of that parameter. |
|
| 28. |
What Is The Importance Of Testng.xml File? |
|
Answer» In a Selenium TestNG PROJECT, we USE testng.xml FILE to configure the complete test suite in a SINGLE file. Some of the features are as follows:
In a Selenium TestNG project, we use testng.xml file to configure the complete test suite in a single file. Some of the features are as follows: |
|
| 29. |
How To Create And Run Testng.xml? |
|
Answer» In TestNG framework, we NEED to create testng.xml file to create and handle multiple TEST classes. We do configure our test RUN, set test dependency, include or exclude any test, method, CLASS or PACKAGE and set priority etc in the xml file. In TestNG framework, we need to create testng.xml file to create and handle multiple test classes. We do configure our test run, set test dependency, include or exclude any test, method, class or package and set priority etc in the xml file. |
|
| 30. |
What Are The Annotations Available In Testng? |
Answer»
|
|
| 31. |
What Are The Advantages Of Testng? |
Answer»
|
|
| 32. |
What Is Testng? |
|
Answer» TestNG is a testing framework designed to SIMPLIFY a broad range of testing needs, from UNIT testing to INTEGRATION testing. TestNG is a testing framework designed to simplify a broad range of testing needs, from unit testing to integration testing. |
|