TestNG

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

How are groups specified in TestNG?

Groups are specified in our 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.

How to create a Group of Groups in TestNG?

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.

What is a Hard Assert in TestNG?***********

Hard Assert throws an AssertException immediately when an assert statement fails and test suite continues with next @Test Practical Example

What is SauceLab?

Sauce Labs is similar to BrowserStack in that it provides a cloud-based platform for cross-browser testing. It also supports a wide range of web browsers and operating systems, and allows for automated and manual testing. Additionally, it supports Appium and Selenium frameworks, which makes it useful for test automation. Sauce Labs also provides analytics and reporting tools to help you understand the results of your tests.

What are the annotations available in TestNG?

--pre-requisite annotation and post condition annotation. @BeforeSuite @AfterSuite @BeforeTest @AfterTest @BeforeGroups @AfterGroups @BeforeClass @AfterClass @BeforeMethod @AfterMethod @Test @DataProvider @Parameters

How to skip a @Test method from execution in TestNG?

-By using the "throw new SkipException()" exception. Once SkipException() is thrown, the remaining part of that test method will not be executed and control will go directly to the next test method execution.

What is the importance of testng.xml file?

-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. • testng.xml file allows to include or exclude the execution of test methods and test groups • It allows to pass parameters to the test cases • Allows to add group dependencies • Allows to add priorities to the test cases • Allows to configure parallel execution of test cases • Allows to parameterize the test cases

Why do we create and run testng.xml ?

-In the TestNG framework, we need to create a testng.xml file to handle multiple test classes. HOW? 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. It is also called a test runner. Or Heart of the testNG framework. HOW WE CREATE IN FRAMEWORKAlthough one is created automatically but you can also create it by - Right click on src/main/resources, then new, then file, name it testNG.xml When created just paste the info from somewhere. HOW WE RUN IN FRAMEWORKRight click on testNG.xml file, choose TestNG Suite.

What is a Parameterized test in TestNG?******

-Parameterized tests allow us to run the same test over and over again using different values. There are two ways to set these parameters: • using testng.xml (We Define parameter in testNG.xml file and and refer those parameter along with [inside the] @parameter annotation before the method to run the test cases) TestNG will automatically try to convert the value specified in testng.xml to the type of your parameter. Here are the types supported: ● String ● int/Integer ● boolean/Boolean ● byte/Byte ● char/Character ● double/Double ● float/Float ● long/Long ● short/Short Practical Example

What is a Soft Assert in TestNG? *******

-Soft Assert generally shows/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.

What is TestNG Assert and list out common TestNG Assertions method?*******

-TestNG Asserts help us to verify whether the test cases pass or not. -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 • assertEqual(String actual,String expected) • assertEqual(String actual,String expected, String message) • assertEquals(boolean actual,boolean expected) • assertTrue(condition) • assertTrue(condition, message) • assertFalse(condition) • assertFalse(condition, message)

How TestNG allows us to state dependencies in a method?

-TestNG allows two ways to declare the dependencies. 1) define dependsOnMethods attributes along with @Test annotations - And refer to which method it should depend on and run the test class 2) Using dependsOnGroups attributes in @Test annotations define groups attributes along with @Test annotations And refer to which group it belongs to. Then create dependencies tags inside the groups tag and put the group name and depends on what group in testNG.xml file

How to run a group of test cases using TestNG?

-TestNG allows us 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. (We Define groups in testNG.xml file and and refer those group along with @Test annotation before the method to run the test cases)

What is an exception test in TestNG?

-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/keyword value along with @Test annotation.

What is the use of @Test(invocationCount=x)?

-The invocationcount attribute tells how many times TestNG should run a test method @Test(invocationCount = 10) public void testCase1(){ In this example, the method testCase1 will be invoked ten times ** What about "thread count" in parallel execution? -- it is used in testNG.xml file

How to disable a test case in TestNG ? or How to Ignore a test case in TestNG?

-To disable the test case we use the attribute (enabled = false) along with @Test annotation.

How to pass parameters through testng.xml file to a test case?****

-We could define the parameters in the testng.xml file and then reference those parameters in the source files. (We Define parameter in testNG.xml file and and refer those parameter along with [inside the] @parameter annotation before the method to run the test cases) // TestNG Interview Questions public class MainTest { @Test @Parameters({"browserName"}) public void parameterizedTest(String browserName){ if(browser.equals("firefox")){ System.out.println("Open Firefox Driver"); }else if(browser.equals("chrome")){ System.out.println("Open Chrome Driver"); } } }

What is the time unit we specify in test suites and test cases?

-We specify the time unit in test suites and test cases is in milliseconds.

How to run test cases in parallel using TestNG?*******

-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

What are @Factory and @DataProvider annotations?

@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.

Why choose TestNG?

Advantages of TestNG over JUnit There are three major advantages of TestNG over JUnit: ● Annotations are easier to understand ● Test cases can be grouped more easily ● Parallel testing is possible Ans: Major difference in TestNG and JUnit test frameworks is their scope. I suggest to use TestNG as core unit test framework for Java project, because TestNG is more advanced in parameterize testing, dependency testing and suite testing (Grouping concept). TestNG is meant for high-level testing and complex integration test.

What is browerstack and saucelab?

BrowserStack and Sauce Labs are cloud-based cross-browser testing platforms. They allow developers and testers to run automated and manual tests on a wide range of web browsers and operating systems without the need to maintain a lab of physical devices or virtual machines.

What is BrowserStack?

BrowserStack is a cross-browser testing platform that allows developers to test their website or web application on a wide variety of web browsers and operating systems, including desktop and mobile browsers. It also provides a live, web-based interface that allows manual testing and debugging. It supports selenium and Appium frameworks, which enables you to run your tests on different programming languages such as Java, C#, Python, Ruby and JavaScript.

How to exclude a particular test group from a test case execution?

By adding the exclude tag in the testng.xml

How to exclude a particular test method from a test case execution?

By adding the exclude tag in the testng.xml

How can we create data driven framework using TestNG?

By using @DataProvider annotation, we can create a Data Driven Framework.

How to do cross browser testing?

Cross-browser testing is the process of checking how a website or web application functions on different web browsers and browser versions. Here are the general steps to perform cross-browser testing using TestNG: 1. Identify the web browsers and browser versions that you want to test your website or web application on. Install the necessary web drivers for each browser that you want to test on. For example, if you want to test on Chrome, you will need to install the ChromeDriver. 2.Set up your TestNG test suite to run multiple test instances, one for each browser and browser version that you want to test. 3.In your test code, use the appropriate web driver for the current test instance to launch the web browser and interact with your website or web application. 4.Run your TestNG test suite and analyze the results to check for any issues with your website or web application on the different browsers and browser versions that you have tested on. It's worth to mention that using some external tools such as Selenium Grid or services as BrowserStack or SauceLabs that allows you to execute the test on multiple environments can help you with this process.

How to write a regular expression In testng.xml file to search @Test methods containing "smoke" keyword.

Regular expression to find @Test methods containing keyword "smoke" is as mentioned below.

List out various ways in which TestNG can be invoked?

TestNG can be invoked in the following ways • Using Eclipse IDE • Using maven/ant build tool • From the command line • Using IntelliJ's IDEA

What is the difference between junit and testng?

TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use. TestNG is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc.. Additional Features: ● Annotations. ● Run your tests in arbitrarily big thread pools with various policies available (all methods in their own thread, one thread per test class, etc...). ● Test that your code is multithread safe. ● Flexible test configuration. Support for data-driven testing (with @DataProvider). ● Support for parameters. ● Powerful execution model (no more TestSuite). ● Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc...). ● Embeds BeanShell for further flexibility. ● Default JDK functions for runtime and logging (no dependencies). ● Dependent methods for application server testing. ● Facilitates user with effective means of Report Generation using ReportNG Annotations: JUnit: @BeforeClass and @AfterClass methods have to be declared as static. TestNG does not have this constraint. TestNG: It has provided four additional setup/teardown pairs for the suite, test and groups, i.e. @BeforeSuite, @AfterSuite, @BeforeTest, @AfterTest, @BeforeGroups and @AfterGroups, @BeforeMethod, @BeforeClass, @AfterClass and @AfterMethod. Parameterized test: This feature is implemented in both tools, however in quite different ways. TestNG has basically two ways for providing varying parameter values to a test method: by setting the testng.xml, and by defining a @DataProvider method. In JUnit, @RunWith and @Parameters are used together to facilitate parameterized tests, while the @Parameters method has to return List[] with all the actual values, which will be fed into a dedicated class constructor as an argument.

What is the use of @Listener annotation in TestNG?

TestNG listeners are used to configure reports and logging. One of the most widely used listeners in testNG is the 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.

What are the different ways to produce reports for TestNG results?

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...

Advantage of TestNG?

TestNG provides parallel execution of test methods by several browsers at the same time. · It allows to define dependency of one test method over other method · It allows to assign priority to test methods @Test(priority=1, groups = "Login") · It allows grouping of test methods into test groups · It has support for parameterizing test cases using @Parameters annotation · It allows data driven testing using @DataProvider annotation.

What is TestNG?

TestNG stands for Test Next Generation. It is a testing framework used by the developers to write their unit label test cases as well as their integration label test cases.

Can you arrange the below testng.xml tags from parent to child?

The correct order of the TestNG tags are as follows <suite>, <test>, <classes>, <class>, <methods>

What does the test timeout mean in TestNG?

The maximum number of milliseconds a test case should take. @Test(threadPoolSize = 3, invocationCount = 10, timeOut = 10000) public void testCase1(){ 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.

What is the use of @Test(threadPoolSize=x)?

The threadPoolSize attribute tells it to form a thread pool to run the test method through multiple threads. Note: This attribute is ignored if invocationCount is not specified @Test(threadPoolSize = 3, <code class="plain">invocationCount = </code><code class="value">10</code>) public void testCase1(){} In this example, the method testCase1 will be invoked from three different threads.

What is verbose in testNGsuite?

Verbose Attribute lets you obtain clear reports through IDE console. This attribute will be placed inside the <Suite> tag of testng.xml as shown below: <suite name="Suite" parallel="tests" verbose="2"> There are 10 levels of Verbose, starting from 1 to 10. verbose="1" — verbose="10" Verbose="10" gives more test details on console output whereas verbose="1" display less details.

How to set test case priority in TestNG?

We use priority attributes along with @Test annotations. In case priority is not set then the test scripts execute in alphabetical order.


Kaugnay na mga set ng pag-aaral

Mid 19th Century Conservative Monarchies

View Set

IBM | CompTIA ITF+ Certification Practice Exam

View Set

Laboratory and Field Experiments

View Set

4th Grade English Vocabulary Words

View Set