0
0
Selenium Javatesting~20 mins

Test suites (testng.xml) in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
TestNG Suite Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
TestNG Suite Execution Order
Given the following testng.xml configuration, what is the order of test method execution?
Selenium Java
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite1">
  <test name="Test1">
    <classes>
      <class name="tests.SampleTest" />
    </classes>
  </test>
  <test name="Test2" preserve-order="false">
    <classes>
      <class name="tests.AnotherTest" />
    </classes>
  </test>
</suite>
ATests run in parallel regardless of order
BAll methods in AnotherTest run first in any order, then all methods in SampleTest run in defined order
CMethods from both classes run interleaved based on alphabetical order
DAll methods in SampleTest run first in defined order, then all methods in AnotherTest run in any order
Attempts:
2 left
💡 Hint
Look at the preserve-order attribute and default behavior of TestNG suites.
assertion
intermediate
2:00remaining
Assertion on TestNG Suite Parallel Execution
Which assertion correctly verifies that tests defined in testng.xml run in parallel mode?
Selenium Java
<suite name="ParallelSuite" parallel="tests" thread-count="3">
  <test name="TestA">
    <classes>
      <class name="tests.TestA" />
    </classes>
  </test>
  <test name="TestB">
    <classes>
      <class name="tests.TestB" />
    </classes>
  </test>
</suite>
AAssert.assertEquals(suite.getParallel(), "tests");
BAssert.assertFalse(suite.isParallel());
CAssert.assertEquals(suite.getThreadCount(), 1);
DAssert.assertTrue(suite.isParallel());
Attempts:
2 left
💡 Hint
Check the attribute that controls parallel execution in TestNG suite.
🔧 Debug
advanced
2:00remaining
Debugging Missing Test Execution in testng.xml
A tester notices that one test class is not running when executing the suite defined below. What is the most likely cause?
Selenium Java
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="SuiteDebug">
  <test name="TestGroup">
    <groups>
      <run>
        <include name="smoke" />
      </run>
    </groups>
    <classes>
      <class name="tests.LoginTest" />
      <class name="tests.PaymentTest" />
    </classes>
  </test>
</suite>
AThe <include> tag should be <exclude> to run smoke tests
BThe <groups> tag is misplaced inside <test> instead of <suite>
CPaymentTest methods are not annotated with @Test(groups = "smoke")
DThe suite name is missing the parallel attribute
Attempts:
2 left
💡 Hint
Check how TestNG runs tests filtered by groups.
framework
advanced
2:00remaining
Configuring TestNG Suite for Multiple Browsers
Which testng.xml snippet correctly configures two tests to run in parallel on Chrome and Firefox browsers using parameters?
A
&lt;suite name="BrowserSuite"&gt;
  &lt;test name="BrowserTest"&gt;
    &lt;parameter name="browser" value="chrome,firefox" /&gt;
    &lt;classes&gt;
      &lt;class name="tests.BrowserTest" /&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
&lt;/suite&gt;
B
&lt;suite name="BrowserSuite" parallel="tests" thread-count="2"&gt;
  &lt;test name="ChromeTest"&gt;
    &lt;parameter name="browser" value="chrome" /&gt;
    &lt;classes&gt;
      &lt;class name="tests.BrowserTest" /&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
  &lt;test name="FirefoxTest"&gt;
    &lt;parameter name="browser" value="firefox" /&gt;
    &lt;classes&gt;
      &lt;class name="tests.BrowserTest" /&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
&lt;/suite&gt;
C
&lt;suite name="BrowserSuite" parallel="classes" thread-count="2"&gt;
  &lt;test name="BrowserTest"&gt;
    &lt;classes&gt;
      &lt;class name="tests.ChromeTest" /&gt;
      &lt;class name="tests.FirefoxTest" /&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
&lt;/suite&gt;
D
&lt;suite name="BrowserSuite" parallel="methods" thread-count="2"&gt;
  &lt;test name="BrowserTest"&gt;
    &lt;parameter name="browser" value="chrome" /&gt;
    &lt;parameter name="browser" value="firefox" /&gt;
    &lt;classes&gt;
      &lt;class name="tests.BrowserTest" /&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
&lt;/suite&gt;
Attempts:
2 left
💡 Hint
Parallel tests with different parameters require separate tags.
🧠 Conceptual
expert
2:00remaining
Impact of preserve-order and parallel Attributes in testng.xml
Consider a TestNG suite with parallel="tests" and preserve-order="false" on a <test> tag. Which statement best describes the execution behavior?
ATests run in parallel, and methods inside each test run in any order ignoring their declaration order
BTests run sequentially, but methods inside each test run in parallel ignoring order
CTests run in parallel, but methods inside each test run sequentially preserving order
DTests and methods both run sequentially preserving order
Attempts:
2 left
💡 Hint
Understand how preserve-order affects method execution inside tests when parallel is enabled.