Selenium Testing Framework Selenium Grid & Parallel Testing 2 — Questions and Answers
Question 1: What is the benefit of using Docker containers for Selenium Grid nodes?
- Faster JavaScript execution
- Easy scalability and consistent browser environments (Correct answer)
- Reduced memory usage per test
- Native OS integration
Correct answer: Easy scalability and consistent browser environments
Docker containers allow Grid nodes to be spun up and torn down quickly with a consistent, isolated browser environment every time.
Question 2: Which TestNG annotation is used to enable parallel test execution across methods in a suite?
- @ParallelTest
- @Suite(parallel=true)
- parallel='methods' in testng.xml (Correct answer)
- @Concurrent
Correct answer: parallel='methods' in testng.xml
In testng.xml, setting parallel='methods' on the <suite> tag causes TestNG to run test methods in parallel threads.
Question 3: What is a 'node' in Selenium Grid?
- A test script file
- A machine that executes browser sessions on behalf of the Hub (Correct answer)
- A remote API endpoint
- A virtual user
Correct answer: A machine that executes browser sessions on behalf of the Hub
A Grid node is a machine (or container) that has browsers installed and receives commands from the Hub to run actual browser sessions.
Question 4: Which port does Selenium Grid 4 use as its default HTTP port?
- 4445
- 5555
- 4444 (Correct answer)
- 8080
Correct answer: 4444
Selenium Grid 4 defaults to port 4444 for both the Hub and the standalone server.
Question 5: When running tests in parallel with Selenium Grid, why should each thread use its own WebDriver instance?
- To reduce network traffic
- To prevent test interference since WebDriver is not thread-safe (Correct answer)
- To improve CPU usage
- To avoid browser cache issues
Correct answer: To prevent test interference since WebDriver is not thread-safe
WebDriver is not thread-safe, so sharing one instance across threads causes race conditions and unpredictable test failures.
Question 6: What does the `maxSession` configuration property control on a Selenium Grid node?
- Total test runtime
- Maximum number of concurrent browser sessions the node will accept (Correct answer)
- Session timeout in milliseconds
- Maximum file download size
Correct answer: Maximum number of concurrent browser sessions the node will accept
The `maxSession` property limits how many browser instances run simultaneously on a single Grid node.
What is the benefit of using Docker containers for Selenium Grid nodes?