public static void Main(string[] args) { // Init the LeanFT SDK SDK.Init(new SdkConfiguration()); // Open a Chrome browser IBrowser testBrowser = BrowserFactory.Launch(BrowserType.Chrome); // Initialize the eyes SDK and set your private API key. var eyes = new Eyes(); eyes.ServerUrl = "https://localhost.applitools.com"; try { // Start the test and set the browser's viewport size to 800x600 eyes.Open(testBrowser, "Hello World!", "My first LeanFT C# test", new Size(800, 600)); // Navigate the browser to the "hello world!" web-site. testBrowser.Navigate("https://www.applitools.com/helloworld"); // Visual checkpoint #1 eyes.CheckWindow("Hello!"); // Click the "Click me!" button IWebElement button = testBrowser.FindChildren <IWebElement>(new WebElementDescription { TagName = "button" })[0]; button.Click(); // Visual checkpoint #2 eyes.CheckWindow("Click!"); // End the test eyes.Close(); } catch (Exception ex) { Console.WriteLine(ex); } finally { // Close the browser. testBrowser.Close(); // If the test was aborted before eyes.Close was called, ends the test as aborted. eyes.AbortIfNotClosed(); // Close the LeanFT SDK SDK.Cleanup(); } }
public void ThenIShouldSeeFollowingResults(Table expectedProducts) { //Find all the product name elements using Programmatic Descriptions var products = browser.FindChildren <IWebElement>( new XPathDescription("//h2[@class='product-name']/a")); //Get the product name displayed on the page by reading InnerText property var productNames = products.Select(p => p.InnerText).ToList(); //Get the expected product name list from Table List <string> expectedProductNames = new List <string>(); foreach (TableRow row in expectedProducts.Rows) { expectedProductNames.Add(row["Products"]); } //Check the size Assert.AreEqual(expectedProductNames.Count, productNames.Count); //Check the expected and actual list CollectionAssert.AreEqual(expectedProductNames, productNames); }
public void TestSimpleSearch() { try { //Expected list of product names should be displayed upon search for given keyword string[] expectedProductNames = { "Madison Earbuds", "Madison Overear Headphones" }; //Enter search keyword app.MadisonIslandPage.QEditField.SetValue("phones"); //Click on Search button app.MadisonIslandPage.SearchButton.Click(); //Wait for Browser title to change browser.WaitUntil(b => b.Title.Equals("Search results for: 'phones'")); //Find all the product name elements using Programmatic Descriptions var products = browser.FindChildren <IWebElement>( new XPathDescription("//h2[@class='product-name']/a")); //Check the count of items Assert.AreEqual(expectedProductNames.Length, products.Length); //Get the product name displayed on the page by reading InnerText property var productNames = products.Select(p => p.InnerText).ToArray(); //Check the product names CollectionAssert.AreEqual(expectedProductNames, productNames); } catch (AssertFailedException ex) { //Add failure information in LeanFT Report Reporter.ReportEvent("Simple Search", "Failed during validation", Status.Failed, ex); throw; } }