//Skipped since the page is not available.
        //[TestCaseSource(nameof(TestMethodDriver))]
        //[Parallelizable]
        public void CustomTooltipsTest(DriverOptions driverOptions)
        {
            IWebDriver driver = SeleniumUtils.CreateWebDriver(driverOptions);

            driver.Url = "https://d1q3vzvnjy4w20.cloudfront.net/";

            Eyes eyes = new Eyes();

            TestUtils.SetupLogging(eyes);
            eyes.Batch          = TestDataProvider.BatchInfo;
            eyes.HideScrollbars = false;
            eyes.Open(driver, nameof(TestCustomTooltips), nameof(CustomTooltipsTest), new System.Drawing.Size(800, 600));

            driver.FindElement(By.Id("coxkit-tooltip")).Click();
            Actions action = new Actions(driver);

            action.MoveToElement(driver.FindElement(By.Id("warningHover"))).Perform();

            By            tooltipSelector = By.CssSelector("div[content ^= 'I want to tell you']");
            WebDriverWait wait            = new WebDriverWait(driver, TimeSpan.FromSeconds(30));

            wait.Until(ExpectedConditions.ElementIsVisible(tooltipSelector));

            try
            {
                eyes.Check(Target.Region(tooltipSelector).WithName(nameof(CustomTooltipsTest)));
                eyes.Close();
            }
            finally
            {
                eyes.Abort();
                driver.Quit();
            }
        }
Exemplo n.º 2
0
        private void Init_(string testName)
        {
            // Initialize the eyes SDK and set your private API key.
            Eyes eyes = InitEyes_();

            string testNameWithArguments = testName;

            foreach (object argValue in TestContext.CurrentContext.Test.Arguments)
            {
                testNameWithArguments += "_" + argValue;
            }

            if (eyes.runner_ is VisualGridRunner)
            {
                testName += "_VG";
                testNameWithArguments += "_VG";
            }
            else if (stitchMode_ == StitchModes.Scroll)
            {
                testName += "_Scroll";
                testNameWithArguments += "_Scroll";
            }

            TestUtils.SetupLogging(eyes, testNameWithArguments);
            eyes.Logger.Log("initializing test: {0}", TestContext.CurrentContext.Test.FullName);
            SpecificTestContextRequirements testContextReqs = new SpecificTestContextRequirements(eyes, testName);

            testDataByTestId_.Add(TestContext.CurrentContext.Test.ID, testContextReqs);

            if ((eyes.runner_ is VisualGridRunner && RUNS_ON_CI) || USE_MOCK_VG)
            {
                eyes.Logger.Log("using VG mock eyes connector");
                string testNameAsFilename = TestUtils.SanitizeForFilename(TestContext.CurrentContext.Test.FullName);
                testContextReqs.TestNameAsFilename = testNameAsFilename;
                Assembly thisAssembly             = Assembly.GetCallingAssembly();
                Stream   expectedOutputJsonStream = thisAssembly.GetManifestResourceStream("Test.Eyes.Selenium.DotNet.Resources.VGTests." + testNameAsFilename + ".json");
                if (expectedOutputJsonStream != null)
                {
                    using (StreamReader reader = new StreamReader(expectedOutputJsonStream))
                    {
                        testContextReqs.ExpectedVGOutput = reader.ReadToEnd();
                    }
                    eyes.visualGridEyes_.EyesConnectorFactory = new Mock.MockEyesConnectorFactory();
                }
            }
            else
            {
                eyes.Logger.Log("using regular VG eyes connector");
            }

            string seleniumServerUrl = SetupSeleniumServer(testName);
            bool   isWellFormedUri   = Uri.IsWellFormedUriString(seleniumServerUrl, UriKind.Absolute);

            RemoteWebDriver webDriver = SeleniumUtils.RetryCreateWebDriver(() =>
            {
                RemoteWebDriver driver = null;
                if (isWellFormedUri)
                {
                    try
                    {
                        eyes.Logger.Log("Trying to create RemoteWebDriver on {0}", seleniumServerUrl);
                        driver = new RemoteWebDriver(new Uri(seleniumServerUrl), options_.ToCapabilities(), TimeSpan.FromMinutes(4));
                    }
                    catch (Exception e)
                    {
                        eyes.Logger.Log("Failed creating RemoteWebDriver on {0}. Creating local WebDriver.", seleniumServerUrl);
                        eyes.Logger.Log("Exception: " + e);
                    }
                }

                if (driver != null)
                {
                    return(driver);
                }

                if (TestUtils.RUNS_ON_CI)
                {
                    if (options_.BrowserName.Equals(BrowserNames.Chrome, StringComparison.OrdinalIgnoreCase) ||
                        options_.BrowserName.Equals(BrowserNames.Firefox, StringComparison.OrdinalIgnoreCase))
                    {
                        eyes.Logger.Log("webdriver is null, running on a CI and trying to initialize {0} browser.", options_.BrowserName);
                        driver = (RemoteWebDriver)SeleniumUtils.CreateWebDriver(options_);
                    }
                }
                else
                {
                    eyes.Logger.Log("webdriver is null, running locally and trying to initialize {0}.", options_.BrowserName);
                    driver = (RemoteWebDriver)SeleniumUtils.CreateWebDriver(options_);
                }

                return(driver);
            });

            eyes.AddProperty("Selenium Session ID", webDriver.SessionId.ToString());

            eyes.AddProperty("ForceFPS", eyes.ForceFullPageScreenshot ? "true" : "false");
            eyes.AddProperty("Agent ID", eyes.FullAgentId);

            //IWebDriver webDriver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capabilities_);

            eyes.Logger.Log("navigating to URL: " + testedPageUrl);

            IWebDriver driver;

            try
            {
                BeforeOpen(eyes);
                driver = eyes.Open(webDriver, testSuitName_, testName, testedPageSize);
            }
            catch
            {
                webDriver.Quit();
                throw;
            }

            //string userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            driver.Navigate().GoToUrl(testedPageUrl);
            eyes.Logger.Log($"{testName} ({options_.BrowserName}) : {TestDataProvider.BatchInfo.Name}");

            testDataByTestId_[TestContext.CurrentContext.Test.ID].WrappedDriver = driver;
            testDataByTestId_[TestContext.CurrentContext.Test.ID].WebDriver     = webDriver;
        }
Exemplo n.º 3
0
        private void Init_(string testName)
        {
            string testNameWithArguments = InitTestName_(ref testName);

            ILogHandler logHandler = TestUtils.InitLogHandler(testNameWithArguments);

            // Initialize the eyes SDK and set your private API key.
            Eyes eyes = InitEyes_(testName, logHandler);

            eyes.Logger.Log(TraceLevel.Notice, Stage.TestFramework, StageType.Start,
                            new { TestName = TestContext.CurrentContext.Test.FullName });

            string seleniumServerUrl = SetupSeleniumServer(testName);
            bool   isWellFormedUri   = Uri.IsWellFormedUriString(seleniumServerUrl, UriKind.Absolute);

            RemoteWebDriver webDriver = SeleniumUtils.RetryCreateWebDriver(() =>
            {
                RemoteWebDriver rwDriver = null;
                if (isWellFormedUri)
                {
                    try
                    {
                        eyes.Logger.Log(TraceLevel.Info, Stage.TestFramework, StageType.Start,
                                        new { message = $"Trying to create RemoteWebDriver on {seleniumServerUrl}" });
                        rwDriver = new RemoteWebDriver(new Uri(seleniumServerUrl), options_.ToCapabilities(), TimeSpan.FromMinutes(4));
                    }
                    catch (Exception e)
                    {
                        CommonUtils.LogExceptionStackTrace(eyes.Logger, Stage.TestFramework, StageType.Start, e,
                                                           testName, seleniumServerUrl);
                    }
                }

                if (rwDriver != null)
                {
                    return(rwDriver);
                }

                if (TestUtils.RUNS_ON_CI)
                {
                    if (options_.BrowserName.Equals(BrowserNames.Chrome, StringComparison.OrdinalIgnoreCase) ||
                        options_.BrowserName.Equals(BrowserNames.Firefox, StringComparison.OrdinalIgnoreCase))
                    {
                        rwDriver = (RemoteWebDriver)SeleniumUtils.CreateWebDriver(options_);
                    }
                }
                else
                {
                    rwDriver = (RemoteWebDriver)SeleniumUtils.CreateWebDriver(options_);
                }

                return(rwDriver);
            });

            eyes.AddProperty("Selenium Session ID", webDriver.SessionId.ToString());

            eyes.AddProperty("ForceFPS", eyes.ForceFullPageScreenshot ? "true" : "false");
            eyes.AddProperty("Agent ID", eyes.FullAgentId);

            //IWebDriver webDriver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capabilities_);

            IWebDriver driver;

            try
            {
                BeforeOpen(eyes);
                driver = eyes.Open(webDriver, testSuitName_, testName, testedPageSize);
            }
            catch
            {
                webDriver.Quit();
                throw;
            }

            //string userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            driver.Navigate().GoToUrl(testedPageUrl);
            eyes.Logger.Log($"{testName} ({options_.BrowserName}) : {TestDataProvider.BatchInfo.Name}");

            testDataByTestId_[TestContext.CurrentContext.Test.ID].WrappedDriver = driver;
            testDataByTestId_[TestContext.CurrentContext.Test.ID].WebDriver     = webDriver;
            testDataByTestId_[TestContext.CurrentContext.Test.ID].WebDriverProvider.SetDriver(driver);
        }