Example #1
0
        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);
        }
        private List <List <string> > GetReportData(List <string> testInputs, string outputDirectory)
        {
            var header = new List <string> {
                "Name", "WikiLink", "Wiki_Directors", "Wiki_Screenshot", "ImdbLink", "Imdb_Directors", "Wiki_Screenshot", "Result"
            };
            var reportData = new List <List <string> >();

            reportData.Add(header);

            testInputs.ForEach(input => {
                var info = AutomationUtility.Deserialize <MovieInfo>($"{outputDirectory}\\{AutomationUtility.ExcludeSymbols(input)}.xml");
                if (info != null)
                {
                    reportData.Add(info.ToArray().ToList());
                }
            });

            return(reportData);
        }
        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();
        }