/** * Generic constructor */ public PageObject(IWebDriver driver) { _driver = driver; _windowHandler = new WindowHandler(_driver); if (_logActions) { _logger = SeleniumLogger.GetLogger(_actionLog); } }
/** SeleniumLogger GetLogger(string descriptiveLogName) * * @param - descriptive name of log. * ie. TestDetails, DatabaseCalls, etc. * * Shows up in _logDir/DATE_descriptiveLogName.txt * * This method uses a modified Singleton Design Pattern. * In the Singleton Design Pattern, the constructor is set to private, * and there is a static GetObject method and a private static instance * of that object. For instance, in the normal Singleton Pattern, I * would create a private static _logger, and the GetLogger() method * would call the constructor if _logger is null before sending back * _logger, or just simply return _logger if it has already been * constructed. * * In this modified version of the Singleton Design Pattern, we have a * private static List<Logger>, and when GetLogger() is called, it * checks that list to see if it's already created, before returning it, * creating it if necessary. */ public static SeleniumLogger GetLogger(string descriptiveLogName) { SeleniumLogger loggerInst; if (!LoggerDict.ContainsKey(descriptiveLogName)) { loggerInst = new SeleniumLogger(descriptiveLogName); LoggerDict.Add(descriptiveLogName, loggerInst); } return LoggerDict[descriptiveLogName]; }