Professional Documents
Culture Documents
Top 50+ TestNG Interview Questions and Answers For 2021 - Scientech Easy
Top 50+ TestNG Interview Questions and Answers For 2021 - Scientech Easy
Top 50+ TestNG Interview Questions and Answers For 2021 - Scientech Easy
We'll tryAdnotclosedtoshowby
w here N G stands for “next generation” Stop seeing this ad Selenium W ebD river +
is the next step tow ards w riting test Why this ad?
Selenium W ebD river Com m ands +
cases.
Selenium Loc rs +
It w as developed by C edric B eust to
Selenium XP Tutorials +
overcom e the de ciency in JU nit by
introducing som e m ore functionalities isD isplayed,isEn ed,isSelected
and features. M ethods +
The list of top 50+ TestN G interview questions and answ ers are for freshers
A ction Interface and A ctions Class +
and experienced.
Selenium JavascriptExecutor +
Topic-wise TestNG Interview Questions with
Answers for Fresher IFram e in Selenium +
TestNG Tutorials +
A he PO IA PI Tutorial +
PO M in Selenium +
It can be integrated w ith Selenium or any other autom ation toolto provide m
ultiple features like assertions,reporting,paralleltest execution,etc.
TestN G have the follow ing advantages over JU nit.They are as follow s:
1.TestN G generates H TM L test report in a readable form at.
2.Test m ethods can be grouped and prioritized m ore easily that is not
possible in the case of JU nit.
3.A nnotations of TestN G are easy to understand for creating test cases.
There are follow ing reasons for integrating TestN G w ith Selenium .
1.Since Selenium W ebD river does not generate test report,by integrating
TestN g w ith Selenium ,w e can easily generate test reports/results in a proper
readable form at to know about how m any test cases are passed,failed,and
skipped.
5.W hat are the basic steps required in w riting TestN G test?
There are three basic steps required in w riting TestN G test that is as
follow s:
1.W rite dow n the business logic of the test and annotate it by TestN G
annotations.
2.C reate testing.xm l le and add the inform ation about your test
3.Ru n TestN G .
A nnotations in TestN G are a set of code that controls how m ethod below
them have to be executed i.e,the order of execution of m ethods below them
w illbe decided by annotations that w e give.
a.Precondition annotations
b.Test annotation
M ethods annotated w ith @ Test are called test m ethods w hich serve as a unit
test.
c.Postcondition annotations
The postcondition annotations are those annotations that are executed after the
execution of allthe test m ethods.The postcondition annotation can be @ A
fterSuite,@ A fterC lass,@ A fterTest,@ A fterM ethod.
@ B eforeSuite
@ B eforeTest
@ B eforeC lass
@ B eforeM etho
@Test
@ A fterM ethod
@ A fterC lass
@ A fterTest
@ A fterSuite
5.W hat is the difference betw een @B eforeClass and @B eforeM ethod?
1.The m ethod w ith @ B eforeC lass w illbe executed only once before any of
the tests in the current class are run w hereas,a m ethod annotated w ith
@ B eforeM ethod w illbe executed before each m ethod annotated w ith @ Test.
2.@ B eforeC lass annotation can be used to set up the con guration and
initialization w hich is com m on to alltest m ethods in the current class.For
exam ple,w e can set up driver con guration w hich w illbe com m on for all
tests in the class.
@ B eforeM ethod can be used to set that data w hich is repeating before each
@ Test annotated m ethod.
@ D ataProvider annotation return an object double array (O bject [ ][ ]) as data to the test m
ethod.
Priority is an attribute that tells TestN G w hich orders have to follow to run
test m ethod.It is used to set the order of test cases as ours need.
Re fer to A nsw er 4.
For exam ple,if w e have 100 test cases of U niversity and 10 test cases of C
ollege,and if you w ant to run allthe test cases of U niversity together in a
single suite,this can be possible only through the grouping of test cases.
We can group m ultiple test m ethods by using groups param eter in the
@Test annotation.The syntax for grouping m ultiple test m ethods in a single group is as follow
s:
Syntax:
void atom () {
…………
}
void electorn() {
…………….
}
@ Test(enabled = false)
PartialG roups:W hen you de ne groups at the class leveland then add groups
at the m ethod level,it is called partialgroups.
M etaG roups:W hen groups include other groups,these groups are called m
etagroups.
ethod.The test m ethod annotated w ith @ Test annotation tells TestN G that this m ethod is a
@Test annotation supports lots of attributes that w e can use w ith this annotation.Som e of
ethods,enabled,priority,tim eO ut,etc.
Syntax:
W e can skip or disable a particular test case using enabled attribute.It can be
achieved by setting enabled attribute of the Test annotation to false. Syntax:
@ Test(enabled = false)
We can pass the param eter value to test m ethods at runtim e through the
testng.xm l le.For this,w e can use @ Param eter annotation:
Syntax:
2.H ow m any w ays by w hich w e can pass param eter values to test
m ethods?
There are m ainly tw o w ays through w hich w e can directly pass param eter
values to test m ethods.
1.Through testng.xm l le.
2.Through D ataProviders
3.W hich annotation is used to pass param eter values to test m ethod from the
testng.xm l le?
ataProviderC lass.class)
2.It allow s users to w rite data-driven test w here w e can run m ultiple tim es
the sam e test m ethod w ith different sets of test data.
A n assertion is basically blocks of code that are placed in the test cases to
check or verify w hether the test has failed or passed.A test w illbe considered
as successfulO N LY if test is com pleted w ithout throw ing any exception.i.e,If
the conditions are not true (do not satisfy),it w illstop the further execution of the
test and m arks it as failing.
Soft assertion is a type of assertion that continues w ith test execution even if
the assertion condition is not m et.That m eans soft assertions do not throw an
exception w hen the assert statem ent (assertion condition) fails.
Top 30+ Selenium Fram ew ork Interview Q uestions and A nsw ers
H ope that this tutorialhas covered TestN G interview questions w ith the best
possible answ ers.In the future,if need,questions w illbe updated regularly
related to TestN G .A llTestN G interview questions are frequently asked for
freshers as w ellas 2 to 3 years of experience. Thanks for reading!!!
Interview ,TestN G
TestN G Interview Qu estions
Leave a Comment