private void CompareProperties_(SpecificTestContextRequirements testData, Metadata.ImageMatchSettings ims, int index) { Dictionary <string, object> expectedProps = GetExpectationsAtIndex(index, testData).ExpectedProperties; Type imsType = typeof(Metadata.ImageMatchSettings); foreach (KeyValuePair <string, object> kvp in expectedProps) { string propertyNamePath = kvp.Key; string[] properties = propertyNamePath.Split('.'); Type currentType = imsType; object currentObject = ims; foreach (string propName in properties) { PropertyInfo pi = currentType.GetProperty(propName); currentObject = pi.GetValue(currentObject, null); if (currentObject == null) { break; } currentType = currentObject.GetType(); } Assert.AreEqual(kvp.Value, currentObject); } }
private Eyes InitEyes_(string testName, ILogHandler logHandler, bool?forceFullPageScreenshot = null) { EyesRunner runner = null; string testNameAsFilename = TestUtils.SanitizeForFilename(TestContext.CurrentContext.Test.FullName); string expectedVGOutput = null; WebDriverProvider webDriverProvider = new WebDriverProvider(); if (useVisualGrid_) { if (RUNS_ON_CI || USE_MOCK_VG) { //eyes.Logger.Log("using VG mock eyes connector"); 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)) { expectedVGOutput = reader.ReadToEnd(); } runner = new VisualGridRunner(10, null, new MockServerConnectorFactory(webDriverProvider), logHandler); } } } runner = runner ?? (useVisualGrid_ ? (EyesRunner) new VisualGridRunner(10, logHandler) : new ClassicRunner(logHandler)); Eyes eyes = new Eyes(runner); TestUtils.SetupDebugScreenshotProvider(eyes, testName); SpecificTestContextRequirements testContextReqs = new SpecificTestContextRequirements(eyes, testName); testDataByTestId_.Add(TestContext.CurrentContext.Test.ID, testContextReqs); testContextReqs.TestNameAsFilename = testNameAsFilename; testContextReqs.ExpectedVGOutput = expectedVGOutput; testContextReqs.WebDriverProvider = webDriverProvider; string serverUrl = Environment.GetEnvironmentVariable("APPLITOOLS_SERVER_URL"); if (!string.IsNullOrEmpty(serverUrl)) { eyes.ServerUrl = serverUrl; } if (forceFullPageScreenshot != null) { eyes.ForceFullPageScreenshot = forceFullPageScreenshot.Value; } eyes.HideScrollbars = true; eyes.StitchMode = stitchMode_; eyes.SaveNewTests = false; eyes.Batch = TestDataProvider.BatchInfo; return(eyes); }
private Expectations GetExpectationsAtIndex(int index) { SpecificTestContextRequirements testData = testDataByTestId_[TestContext.CurrentContext.Test.ID]; if (!testData.Expectations.TryGetValue(index, out Expectations expectations)) { expectations = new Expectations(); testData.Expectations[index] = expectations; } return(expectations); }
private void CompareRegions_(SpecificTestContextRequirements testData, Metadata.ImageMatchSettings ims, int index) { if (!CompareExpectedRegion) { return; } Expectations expectations = GetExpectationsAtIndex(index, testData); CompareAccessibilityRegionsList_(ims.Accessibility, expectations.ExpectedAccessibilityRegions, "Accessibility"); CompareFloatingRegionsList_(ims.Floating, expectations.ExpectedFloatingRegions, "Floating"); TestUtils.CompareSimpleRegionsList_(ims.Ignore, expectations.ExpectedIgnoreRegions, "Ignore"); TestUtils.CompareSimpleRegionsList_(ims.Layout, expectations.ExpectedLayoutRegions, "Layout"); TestUtils.CompareSimpleRegionsList_(ims.Content, expectations.ExpectedContentRegions, "Content"); TestUtils.CompareSimpleRegionsList_(ims.Strict, expectations.ExpectedStrictRegions, "Strict"); }
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; }