Challenge - 5 Problems
Base Page Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of BasePage method call
Given the following BasePage class snippet, what will be the output when
getPageTitle() is called if the current page title is "Home - MyApp"?Selenium Java
public class BasePage { protected WebDriver driver; public BasePage(WebDriver driver) { this.driver = driver; } public String getPageTitle() { return driver.getTitle(); } } // Assume driver.getTitle() returns "Home - MyApp"
Attempts:
2 left
💡 Hint
Think about what the getTitle() method of WebDriver returns.
✗ Incorrect
The getPageTitle() method returns the title of the current page by calling driver.getTitle(), which returns the exact page title string.
❓ assertion
intermediate2:00remaining
Correct assertion for page title verification
Which assertion correctly verifies that the page title is exactly "Dashboard - MyApp" in a test using the BasePage class?
Selenium Java
BasePage basePage = new BasePage(driver); String actualTitle = basePage.getPageTitle();
Attempts:
2 left
💡 Hint
Exact match is required for the title.
✗ Incorrect
assertEquals compares the expected and actual strings exactly, which is needed to verify the full page title.
❓ locator
advanced2:00remaining
Best locator strategy in BasePage for a common header element
In the BasePage class, which locator is the best practice to find a header element with id "main-header"?
Attempts:
2 left
💡 Hint
Id locators are fastest and most reliable if unique.
✗ Incorrect
Using By.id("main-header") is the fastest and most reliable locator if the id is unique on the page.
🔧 Debug
advanced2:00remaining
Identify the error in BasePage constructor
What error will occur when creating a BasePage object with this constructor code snippet?
Selenium Java
public class BasePage {
protected WebDriver driver;
public BasePage() {
this.driver = driver;
}
}Attempts:
2 left
💡 Hint
Look at how driver is assigned in the constructor.
✗ Incorrect
The constructor has no parameter, so 'driver' on right side is the field itself, so it remains null causing NullPointerException later.
❓ framework
expert3:00remaining
Best practice for extending BasePage in Page Object Model
In a Page Object Model using BasePage as a parent class, which approach correctly initializes the driver in a child page class named LoginPage?
Selenium Java
public class LoginPage extends BasePage { private By usernameField = By.id("username"); public LoginPage(WebDriver driver) { // What should go here? } }
Attempts:
2 left
💡 Hint
Use the parent constructor to initialize inherited fields.
✗ Incorrect
Calling super(driver) passes the driver to the BasePage constructor to initialize the protected driver field properly.