0
0
Selenium Javatesting~20 mins

Parallel execution configuration in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Parallel Execution Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of TestNG Parallel Execution Configuration
Given the following TestNG XML configuration for parallel execution, what will be the output order of test methods if each test prints its method name when run?
Selenium Java
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="methods" thread-count="2">
  <test name="Test1">
    <classes>
      <class name="tests.SampleTest"/>
    </classes>
  </test>
</suite>

// SampleTest.java
package tests;
import org.testng.annotations.Test;
public class SampleTest {
  @Test
  public void testA() {
    System.out.println("testA");
  }
  @Test
  public void testB() {
    System.out.println("testB");
  }
  @Test
  public void testC() {
    System.out.println("testC");
  }
}
AtestA\ntestB\ntestC (order may vary but all run concurrently with max 2 threads)
BtestA\ntestB\ntestC (always sequential in this order)
CtestA\ntestC\ntestB (always this fixed order)
DOnly testA runs because thread-count limits to 1
Attempts:
2 left
💡 Hint
Parallel execution with thread-count=2 means up to 2 tests run at the same time, order is not guaranteed.
assertion
intermediate
2:00remaining
Correct Assertion for Parallel Test Execution Completion
In a Selenium TestNG parallel test suite, which assertion correctly verifies that all tests have completed execution before proceeding?
Selenium Java
import org.testng.Assert;
import org.testng.annotations.Test;

@Test
public void verifyAllTestsCompleted() {
  boolean allTestsDone = TestExecutionListener.allTestsFinished();
  // Which assertion below is correct to confirm all tests finished?
}
AAssert.assertFalse(allTestsDone, "Not all tests completed");
BAssert.assertNull(allTestsDone, "Not all tests completed");
CAssert.assertTrue(allTestsDone, "Not all tests completed");
DAssert.assertEquals(allTestsDone, false, "Not all tests completed");
Attempts:
2 left
💡 Hint
You want to confirm the boolean flag is true indicating completion.
🔧 Debug
advanced
2:00remaining
Debugging Thread Safety Issue in Parallel Selenium Tests
You have configured parallel execution in TestNG with thread-count=3. Your Selenium tests share a WebDriver instance stored in a static variable. What problem will most likely occur?
ATests will throw a compilation error due to static WebDriver.
BTests will run faster without any issues because WebDriver is shared.
CTests will run sequentially ignoring parallel configuration.
DTests will fail intermittently due to WebDriver instance conflicts across threads.
Attempts:
2 left
💡 Hint
Consider thread safety when sharing objects in parallel tests.
framework
advanced
2:00remaining
Best Practice for Parallel Execution in Selenium with TestNG
Which TestNG suite XML configuration snippet correctly enables parallel execution at the class level with 4 threads?
A
&lt;suite name="Suite" parallel="classes" thread-count="4"&gt;
  &lt;test name="Test"&gt;
    &lt;classes&gt;
      &lt;class name="tests.TestClass1"/&gt;
      &lt;class name="tests.TestClass2"/&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
&lt;/suite&gt;
B
&lt;suite name="Suite" parallel="tests" thread-count="4"&gt;
  &lt;test name="Test1"&gt;
    &lt;classes&gt;
      &lt;class name="tests.TestClass1"/&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
  &lt;test name="Test2"&gt;
    &lt;classes&gt;
      &lt;class name="tests.TestClass2"/&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
&lt;/suite&gt;
C
&lt;suite name="Suite" parallel="methods" thread-count="4"&gt;
  &lt;test name="Test"&gt;
    &lt;classes&gt;
      &lt;class name="tests.TestClass1"/&gt;
      &lt;class name="tests.TestClass2"/&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
&lt;/suite&gt;
D
&lt;suite name="Suite" parallel="instances" thread-count="4"&gt;
  &lt;test name="Test"&gt;
    &lt;classes&gt;
      &lt;class name="tests.TestClass1"/&gt;
      &lt;class name="tests.TestClass2"/&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
&lt;/suite&gt;
Attempts:
2 left
💡 Hint
Parallel at class level means parallel="classes" in suite tag.
🧠 Conceptual
expert
2:00remaining
Impact of Parallel Execution on Test Data Management
In a Selenium TestNG suite running tests in parallel, what is the best approach to manage test data to avoid flaky tests?
AShare a single global data object across all tests to reduce memory usage.
BUse thread-local storage or separate data instances per test thread to isolate test data.
CLoad test data once before suite and reuse it without synchronization.
DUse static variables to store test data accessible by all threads.
Attempts:
2 left
💡 Hint
Think about data isolation in parallel environments.