public MovieInfo Run(MovieInfo info, string outputDirectory, AutomationBrowserType browserType) { if (info != null && info.WikiLinks != null && info.WikiLinks.Any()) { foreach (var link in info.WikiLinks) { this.WPage.Navigate(link); try { info.Directors_Wiki = this.WPage.GetDirector(); info.WikiLink = link; info.WikiScreenShotPath = $"{AutomationUtility.ExcludeSymbols(info.Name)}_wiki.png"; this.WPage.GetScreenshot(Path.Combine(outputDirectory, info.WikiScreenShotPath)); } catch { } if (!string.IsNullOrEmpty(info.Directors_Wiki)) { break; } } ; info.ImdbLink = this.WPage.GetIMDbLink(browserType); this.IPage.Navigate(info.ImdbLink); info.Directors_Imdb = this.IPage.GetDirector(browserType); info.ImdbScreenShotPath = $"{AutomationUtility.ExcludeSymbols(info.Name)}_imdb.png"; this.IPage.GetScreenshot(Path.Combine(outputDirectory, info.ImdbScreenShotPath)); } return(info); }
public string GetDirector(AutomationBrowserType browserType) { string director = string.Empty; switch (browserType) { case AutomationBrowserType.MobileChromeBrowser: { director = this.MobDirector.Text.Replace(" ", ""); break; } default: { if (this.PCMultipleDirectors != null && this.PCMultipleDirectors.Any()) { director = string.Join(",", this.PCMultipleDirectors.ToList().Select(d => d.Text).ToList()); } else { director = this.PCSingleDirector.Text; } break; } } return(director); }
public void Automate(List <string> testInputs, AutomationBrowserType browserType, string outputDirectory, int degreeOfParallelism = 5) { Console.WriteLine($"UTC-{DateTime.UtcNow}: Automation started."); if (browserType == AutomationBrowserType.PCChromeBrowser) { List <Task> tasks = new List <Task>() { Task.Factory.StartNew(() => { RunTests(testInputs.Take(1).ToList(), AutomationBrowserType.MobileChromeBrowser, outputDirectory, 1); }), Task.Factory.StartNew(() => { RunTests(testInputs.Skip(1).ToList(), AutomationBrowserType.PCChromeBrowser, outputDirectory, degreeOfParallelism); }) }; Task.WaitAll(tasks.ToArray()); } else { RunTests(testInputs, AutomationBrowserType.PCHeadlessChromeBrowser, outputDirectory, degreeOfParallelism); } var reportData = GetReportData(testInputs, outputDirectory); var report = ReportGenerator.Generate(reportData, "Report Template\\TestAutothonReport.html"); AutomationUtility.SaveReport(report, $"{outputDirectory}\\Report.html"); Console.WriteLine($"UTC-{DateTime.UtcNow}: Automation completed."); }
public string GetIMDbLink(AutomationBrowserType browserType) { string link = string.Empty; switch (browserType) { case AutomationBrowserType.MobileChromeBrowser: link = this.IMDbLink.GetProperty("href"); break; default: link = this.IMDbLink.GetAttribute("href"); break; } return(link); }
static void Main(string[] args) { string _iFilePath, _bType, _nThreads, _nWLinks; //args[0] => Input filename if (!string.IsNullOrEmpty(args[0]) && args[0] != "null") { _iFilePath = args[0]; MovieNames = GetInputFromFile(_iFilePath); } //args[1] => Browser Type (gui, headless) if (!string.IsNullOrEmpty(args[1]) && args[1] != "null") { _bType = args[1]; browserType = GetBrowserType(_bType); } //args[2] => Max no of threads if (!string.IsNullOrEmpty(args[2]) && args[2] != "null") { _nThreads = args[2]; Int32.TryParse(_nThreads, out maxNoOfThreads); } //args[3] => Max no of wiki links if (!string.IsNullOrEmpty(args[3]) && args[3] != "null") { _nWLinks = args[3]; Int32.TryParse(_nWLinks, out noOfWikiLinks); } //args[4] => Output folder if (!string.IsNullOrEmpty(args[4]) && args[4] != "null") { outputDirectory = args[4]; } Console.WriteLine("Starting job"); Console.WriteLine(args); string reportDirectory = AutomationUtility.GetOutputDirectory(outputDirectory); AutomationHelper helper = new AutomationHelper(); helper.GetWikiLinks(MovieNames, browserType, reportDirectory, noOfWikiLinks); helper.Automate(MovieNames, browserType, reportDirectory, maxNoOfThreads); Console.WriteLine("Completed job"); }
private void RunTests(List <string> testInputs, AutomationBrowserType browserType, string outputDirectory, int degreeOfParallelism = 5) { ParallelOptions option = new ParallelOptions() { MaxDegreeOfParallelism = browserType != AutomationBrowserType.MobileChromeBrowser ? degreeOfParallelism : 1 }; Parallel.ForEach(testInputs, option, (input) => { var info = AutomationUtility.Deserialize <MovieInfo>($"{outputDirectory}\\{AutomationUtility.ExcludeSymbols(input)}.xml"); if (info != null) { var automationDriver = new AutomationDriver(); automationDriver.StartBrowser(browserType, 3); AutomationFacade facade = new AutomationFacade(automationDriver.Browser, 120); try { info = facade.Run(info, outputDirectory, browserType); if (string.IsNullOrEmpty(info.Directors_Wiki)) { info.Directors_Wiki = "Cannot find Wikipedia result"; } if (string.IsNullOrEmpty(info.Directors_Imdb)) { info.Directors_Imdb = "Cannot find IMDb result"; } Console.WriteLine($"The test {info.Passed} for {info.Name}"); } catch (Exception ex) { Console.WriteLine(ex.Message); info = new MovieInfo(); info.Name = input; info.Directors_Imdb = "Cannot find IMDb result"; info.Directors_Wiki = "Cannot find Wikipedia result"; } AutomationUtility.Serialize <MovieInfo>(info, $"{outputDirectory}\\{AutomationUtility.ExcludeSymbols(info.Name)}.xml"); automationDriver.StopBrowser(); } }); }
public void GetWikiLinks(List <string> testInputs, AutomationBrowserType browserType, string outputDirectory, int noOfResults = 2) { Console.WriteLine($"UTC-{DateTime.UtcNow}: Retrieving Wiki Links."); var googleDriver = new AutomationDriver(); googleDriver.StartBrowser(browserType, 3); AutomationFacade facade = new AutomationFacade(googleDriver.Browser); if (testInputs != null && testInputs.Any()) { facade.NavigateToGoogle(); testInputs.ForEach(input => { var info = facade.GetWikiLinks(input, noOfResults); AutomationUtility.Serialize <MovieInfo>(info, $"{outputDirectory}\\{AutomationUtility.ExcludeSymbols(info.Name)}.xml"); }); } googleDriver.StopBrowser(); }
public void StartBrowser(AutomationBrowserType browserType = AutomationBrowserType.PCChromeBrowser, int defaultTimeOut = 1) { switch (browserType) { case AutomationBrowserType.PCChromeBrowser: this.Browser = GetPCChromeDriver(); break; case AutomationBrowserType.PCHeadlessChromeBrowser: this.Browser = GetPCHeadlessChromeDriver(); break; case AutomationBrowserType.MobileChromeBrowser: this.Browser = GetMobileChromeDriver(); break; default: break; } BrowserWait = new WebDriverWait(this.Browser, TimeSpan.FromMinutes(defaultTimeOut)); }