コード例 #1
0
        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();
                }
            });
        }
コード例 #2
0
        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();
        }