













































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This exam tests automation skills using Selenium WebDriver, TestNG/JUnit, locators, framework design, page object model (POM), automation scripts, debugging, and CI/CD integration. Learners solve hands-on automation scenarios covering dynamic elements, cross-browser testing, waits, and synchronization issues.
Typology: Exams
1 / 85
This page cannot be seen from the preview
Don't miss anything!














































































Question 1. Which Java keyword is used to create an instance of a class? A) new B) create C) instance D) construct Answer: A Explanation: The new keyword allocates memory and calls the constructor to create an object. Question 2. In Selenium WebDriver, which method retrieves the current page title? A) getUrl() B) getTitle() C) getPageSource() D) getCurrentUrl() Answer: B Explanation: getTitle() returns the title of the loaded page. Question 3. Which of the following is NOT a primitive data type in Java? A) int B) boolean C) String D) double Answer: C Explanation: String is a reference type, not a primitive. Question 4. What does the Selenium Grid Hub do?
A) Executes tests on a single machine B) Manages multiple nodes for parallel execution C) Generates test reports D) Provides a GUI for test creation Answer: B Explanation: The Hub receives test requests and distributes them to registered nodes. Question 5. Which TestNG annotation runs before every test method in a class? A) @BeforeSuite B) @BeforeClass C) @BeforeMethod D) @BeforeTest Answer: C Explanation: @BeforeMethod is invoked before each @Test method. Question 6. In Java, which access modifier provides the highest level of encapsulation? A) public B) protected C) private D) default Answer: C Explanation: private restricts access to the declaring class only. Question 7. Which Selenium locator strategy is generally the fastest? A) XPath
C) <dependencies> lists all external libraries required by the project. Question 11. Which Java collection allows duplicate elements and maintains insertion order? A) HashSet B) TreeSet C) ArrayList D) LinkedHashMap Answer: C Explanation: ArrayList permits duplicates and preserves the order of insertion. Question 12. What does the Selenium Select class handle? A) Alerts B) Drop‑down menus C) Frames D) Windows Answer: B Explanation: Select provides methods to interact with <select> HTML elements. Question 13. Which TestNG annotation is used to supply data to a test method? A) @Parameters B) @DataProvider C) @Factory
D) @BeforeDataProvider Answer: B Explanation: @DataProvider defines a method that returns test data arrays. Question 14. In Java, which keyword is used to inherit a class? A) implements B) extends C) inherits D) derives Answer: B Explanation: extends establishes an inheritance relationship between classes. Question 15. Which Selenium wait is designed to poll the DOM at regular intervals until a condition is met? A) Implicit Wait B) Thread.sleep() C) Fluent Wait D) Page Load Timeout Answer: C Explanation: FluentWait allows custom polling intervals and ignoring specific exceptions. Question 16. What does the @FindBy annotation do in PageFactory? A) Declares a test method B) Locates a WebElement using a given strategy C) Generates test reports
D) git init newbranch Answer: A Explanation: git checkout - b <branch> creates and switches to a new branch. Question 20. Which of the following statements about Selenium IDE is true? A) It supports Java as a scripting language. B) It records tests in a browser and generates scripts. C) It can run tests on a Selenium Grid. D) It provides a full‑featured API for complex interactions. Answer: B Explanation: Selenium IDE records user actions and produces test scripts, primarily for quick prototyping. Question 21. Which Java loop guarantees at least one execution? A) for B) while C) do‑while D) enhanced for Answer: C Explanation: do‑while executes the body before evaluating the condition. Question 22. In Selenium, which method is used to close only the current browser window? A) driver.quit() B) driver.close() C) driver.shutdown()
D) driver.exit() Answer: B Explanation: close() shuts the active window; quit() ends the entire session. Question 23. Which TestNG assertion stops test execution immediately upon failure? A) SoftAssert.assertTrue() B) Assert.assertEquals() C) Verify.assertFalse() D) Check.assertNotNull() Answer: B Explanation: Assert methods throw an exception on failure, halting the test. Question 24. Which of the following is a headless browser option for Selenium? A) ChromeDriver with GUI B) FirefoxDriver with UI C) HtmlUnitDriver D) SafariDriver Answer: C Explanation: HtmlUnitDriver runs without a graphical interface. Question 25. In Java, which interface must a class implement to be used as a lambda expression target? A) Serializable B) Runnable C) FunctionalInterface
Answer: B Explanation: Cast the driver to TakesScreenshot and call getScreenshotAs(OutputType.FILE). Question 29. Which of the following best describes the difference between assert and verify in testing? A) assert continues execution after failure; verify stops execution. B) assert stops execution on failure; verify logs failure and continues. C) Both behave identically. D) assert is used only for UI checks; verify for API checks. Answer: B Explanation: Assertions halt the test, whereas verifications record the failure but let the test proceed. Question 30. Which Java feature allows multiple methods with the same name but different parameters? A) Overriding B) Overloading C) Polymorphism D) Encapsulation Answer: B Explanation: Method overloading provides compile‑time polymorphism. Question 31. In Selenium, which command returns the value of a given attribute of a WebElement? A) getText() B) getAttribute() C) getProperty()
D) getValue() Answer: B Explanation: getAttribute("attributeName") fetches the attribute’s value. Question 32. Which TestNG annotation is executed once after all tests in a suite have run? A) @AfterSuite B) @AfterTest C) @AfterClass D) @AfterGroups Answer: A Explanation: @AfterSuite runs after the entire suite completes. Question 33. Which Selenium WebDriver method is used to switch focus to a newly opened window? A) driver.switchTo().window(handle) B) driver.switchTo().frame(handle) C) driver.switchTo().alert() D) driver.switchTo().defaultContent() Answer: A Explanation: switchTo().window(String handle) changes context to the specified window. Question 34. Which Java collection interface guarantees that elements are unique and sorted? A) List B) Set C) Map
Answer: A Explanation: Declaring a class as final stops inheritance. Question 38. Which of the following is a valid way to perform a drag‑and‑drop action using Selenium? A) element.dragAndDrop(target) B) Actions.dragAndDrop(source, target).perform() C) driver.drag(source, target) D) element.moveTo(target) Answer: B Explanation: The Actions class provides dragAndDrop(source, target).perform(). Question 39. Which Maven plugin is commonly used to run TestNG tests? A) maven-compiler-plugin B) maven-surefire-plugin C) maven-jar-plugin D) maven-deploy-plugin Answer: B Explanation: maven-surefire-plugin executes unit and integration tests, supporting TestNG. Question 40. In Selenium, which locator strategy can use CSS attribute selectors? A) By.id() B) By.name() C) By.cssSelector() D) By.linkText()
Answer: C Explanation: By.cssSelector() accepts any valid CSS selector, including attribute selectors. Question 41. Which Java exception is thrown when an array index is out of bounds? A) NullPointerException B) IllegalArgumentException C) ArrayIndexOutOfBoundsException D) IndexOutOfBoundsException Answer: C Explanation: ArrayIndexOutOfBoundsException signals illegal array index access. Question 42. Which command in Selenium WebDriver waits for a page to load completely? A) driver.manage().timeouts().pageLoadTimeout() B) driver.manage().timeouts().implicitlyWait() C) driver.waitForPageLoad() D) driver.wait().untilPageLoaded() Answer: A Explanation: pageLoadTimeout sets the maximum time to wait for a page load. Question 43. In TestNG, what does the dependsOnMethods attribute specify? A) Parallel execution order B) Priority of test execution C) That a test should run only after specified methods succeed D) The data provider to use Answer: C
Question 47. Which Java keyword is used to handle resources automatically in a try block? A) catch B) finally C) try-with-resources D) synchronized Answer: C Explanation: The try-with-resources statement automatically closes resources that implement AutoCloseable. Question 48. In Selenium, which method scrolls the page to bring an element into view using JavaScript? A) driver.scrollTo(element) B) ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", element) C) driver.executeScript("scrollIntoView()", element) D) element.scrollIntoView() Answer: B Explanation: JavascriptExecutor runs the scrollIntoView script on the element. Question 49. Which Git command merges a remote branch into the current branch? A) git pull origin feature-branch B) git fetch origin feature-branch C) git merge origin/feature-branch D) git rebase origin/feature-branch Answer: C
Explanation: git merge origin/feature-branch merges the fetched remote branch. Question 50. Which Selenium WebDriver method is used to clear the text from an input field? A) clearText() B) delete() C) clear() D) reset() Answer: C Explanation: WebElement.clear() removes any existing text. Question 51. Which Java collection is best suited for fast lookup by key? A) ArrayList B) LinkedList C) HashMap D) TreeSet Answer: C Explanation: HashMap provides O(1) average time complexity for key‑based retrieval. Question 52. In TestNG, which attribute groups test methods for selective execution? A) priority B) groups C) dependsOnMethods D) enabled Answer: B Explanation: The groups attribute assigns a test to one or more named groups.
Question 56. In Selenium, which method retrieves the handle of the current browser window? A) driver.getWindowHandles() B) driver.getWindowHandle() C) driver.getCurrentWindow() D) driver.getActiveWindow() Answer: B Explanation: getWindowHandle() returns the unique identifier of the active window. Question 57. Which TestNG feature allows execution of the same test method with multiple data sets? A) @Parameters B) @DataProvider C) @Factory D) @Test(priority) Answer: B Explanation: @DataProvider supplies multiple argument sets to a single test method. Question 58. Which Java exception must be either caught or declared in the method signature? A) RuntimeException B) NullPointerException C) IOException D) IllegalArgumentException Answer: C Explanation: IOException is a checked exception, requiring handling or declaration.
Question 59. Which Selenium command is used to retrieve the number of open windows/tabs? A) driver.getWindowCount() B) driver.getWindowHandles().size() C) driver.getOpenWindows() D) driver.getTabsCount() Answer: B Explanation: getWindowHandles() returns a Set; its size indicates the number of windows. Question 60. In Maven, which file defines the project’s dependencies and build configuration? A) settings.xml B) pom.xml C) build.xml D) project.properties Answer: B Explanation: pom.xml (Project Object Model) contains dependencies, plugins, and other settings. Question 61. Which Selenium method can be used to capture the text of a selected option in a dropdown? A) getSelectedOption() B) getFirstSelectedOption().getText() C) getOptionText() D) getValue() Answer: B Explanation: Select.getFirstSelectedOption().getText() returns the visible text of the chosen option.