I'm struggling with how to apply inheritance and composition with Java for scraping sample data.
App driver:
package dur.bounceme.net.SeleniumBase;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Logger;
import org.openqa.selenium.WebDriver;
public class App {
private static final Logger LOG = Logger.getLogger(App.class.getName());
public static void main(String[] args) throws IOException {
new App().initSelenium();
}
private void initSelenium() throws IOException {
LOG.fine("starting selenium initialization..");
Properties properties = new Properties();
properties.loadFromXML(App.class.getResourceAsStream("/selenium.xml"));
LOG.fine(properties.toString());
BookScraper bookScraper = new BookScraper(properties);
WebDriver webDriver = bookScraper.getWebDriver();
WelcomePage welcomePage = new WelcomePage(webDriver);
welcomePage.populateCatalogue();
bookScraper.close();
}
}
within WelcomePage
I'm looking to utilize OOP principles in relation to the Page Object Model
which Selenium
utilizes.
My focus is populating the catalogue. As the catologue is a division within the page it seems there should be a corresponding class. What would this class extend and implement?
Is it not customary to instantiate a single WebDriver
instance which is then passed around? I would think that Selenium Grid
would be employed for multiple instances, and wouldn't expect a single user to concurrently be on different pages. (A user, myself, might switch between open tabs or pages, but not, literally, concurrently. Like most humans I have only the one set of eyes and one set of fingers (for Braille).)
Or, perhaps each page and page component gets its own, new, WebDriver
!?
Admittedly, this PageFactory
looks intriguing, and I see that Page Fragment
is well established: