public void IEModalDialogsSupport() { Manager.LaunchNewBrowser(BrowserType.InternetExplorer, true); ActiveBrowser.NavigateTo(Path.Combine(TestContext.TestDeploymentDir, TESTPAGE2)); // Open the popup using mouse click so it doesn't hang execution. Find.ByAttributes <HtmlInputButton>("type=button").MouseClick(); // ** Special IE Code. Given that IE Dialog is an IE specific feature. if (ActiveBrowser.BrowserType == BrowserType.InternetExplorer) { InternetExplorerActions ieActions = (InternetExplorerActions)ActiveBrowser.Actions; // Connect the dialog ieActions.ConnectIEDialog("THIS IS A MODAL DIALOG", 300); Manager.WaitForNewBrowserConnect("dialog.html", true, 10000); Assert.IsTrue(ActiveBrowser.IsIEDialog); // The ActiveBrowser instance is now the dialog instance. Do what ever you want with the dialog ActiveBrowser.Find.ByTagIndex <HtmlContainerControl>("H1", 0).BaseElement.SetValue <string>("style.backgroundColor", "red"); // Once done, make sure to close the dialog. // Even if the dialog is closed due to a button click within the dialog, you still need this line // at this point to revert the ActiveBrowser instance to the main instance. We are searching for a // good approach to make this automatic. ActiveBrowser.Close(); } Assert.IsFalse(ActiveBrowser.IsIEDialog); // The ActiveBrowser is back to the main browser window. ActiveBrowser.NavigateTo("http://www.google.com"); }
public void HtmlSelectExamples() { /// You can find the HtmlSelect control via a number of methods. Use any of the following /// Find the control by assigned name HtmlSelect mySelect1 = Find.ByName <HtmlSelect>("ctl00$MainContent$drpMake"); /// Or find the control by it's assigned ID HtmlSelect mySelect2 = Find.ById <HtmlSelect>("ctl00_MainContent_drpMake"); /// Using a partial match to find the control even if the name changes slightly HtmlSelect mySelect3 = Find.ByAttributes <HtmlSelect>("id=~_drpMake"); /// Find all the controls matching a pattern which can then be iterated through IList <HtmlSelect> mySelectList = Find.AllByAttributes <HtmlSelect>("id=~_product"); /// Verify the select contains the expected options Assert.AreEqual(76, mySelect1.Options.Count); Assert.IsTrue(mySelect1.Options[0].Text.Equals("- Select -")); Assert.IsTrue(mySelect1.Options[1].Text.Equals("Alfa Romeo")); Assert.IsTrue(mySelect1.Options[2].Text.Equals("AM General")); Assert.IsTrue(mySelect1.Options[3].Text.Equals("AMC")); /// Iterate through the list of selects foreach (HtmlSelect aSelect in mySelectList) { if (aSelect.ID.Contains("color")) { /// Found the Color drop down /// Validate the options for it /// Iterate through all the options looking for something foreach (HtmlOption anOption in aSelect.Options) { Assert.IsTrue(anOption.Text.StartsWith("Color : ")); } } else if (aSelect.ID.Contains("size")) { /// Found the Size drop down /// Validate the options for it /// Iterate through all the options looking for something foreach (HtmlOption anOption in aSelect.Options) { Assert.IsTrue(anOption.Text.StartsWith("Size : ")); } } else if (aSelect.ID.Contains("option")) { /// Found the Option drop down /// Validate the options for it /// Iterate through all the options looking for something foreach (HtmlOption anOption in aSelect.Options) { Assert.IsTrue(anOption.Text.StartsWith("Option : ")); } } else { Assert.Fail("Unrecognized Select drop down found"); } } }
public void FindElementsByID() { Manager.LaunchNewBrowser(); ActiveBrowser.NavigateTo(Path.Combine(TestContext.TestDeploymentDir, TESTPAGE)); // Set the short-cuts to the main automation objects. Browser brwser = Manager.ActiveBrowser; Find rootFind = brwser.Find; // All the testregion are initialized here. TestRegion r1 = brwser.Regions["Region1"]; TestRegion r11 = brwser.Regions["Region11"]; TestRegion r111 = brwser.Regions["Region111"]; TestRegion r1111 = brwser.Regions["Region1111"]; TestRegion r112 = brwser.Regions["Region112"]; //*** Using identification by id. Element div0 = r1.Find.ById("div0"); //*** Using tag name occurrence index. Element div = r1.Find.ByTagIndex("div", 0); Element div1 = r112.Find.ByTagIndex("div", 0); // Some verification to illustrate how the same element that was found // using TestRegion Find objects above, can be also found // using the main Browser Find object. Assert.IsTrue(div.Equals(rootFind.ByTagIndex("div", 0))); Assert.IsTrue(div0.Equals(rootFind.ByTagIndex("div", 1))); //*** Using attribute identification. Assert.IsTrue(div1.Equals(rootFind.ByAttributes("id=div1"))); Assert.IsNull(rootFind.ByAttributes("id=bla")); Assert.IsNotNull(rootFind.ByAttributes("href=http://www.kayak.com")); //*** Using partial attribute identification. Assert.IsTrue(rootFind.ByAttributes("bla=~__").Equals(rootFind.ById("div7"))); Assert.IsNull(rootFind.ByAttributes("id=~div7", "bla=~wow")); Assert.IsNotNull(rootFind.ByAttributes("onclick=~clicked();", "id=~button2")); //*** Using 'All' elements identification. // Note here that the first 'div' does not have any id that contains 'div' hence the '- 1'. Assert.AreEqual(rootFind.AllByTagName("div").Count - 1, rootFind.AllByXPath("/descendant::node()[starts-with(@id,'div')]").Count); Assert.AreEqual(5, rootFind.AllByAttributes("href=http://www.kayak.com").Count); Assert.AreEqual(2, rootFind.AllByAttributes("id=~button").Count); Assert.AreEqual(10, r1.Find.AllByTagName("div").Count); Assert.AreEqual(0, r1111.Find.AllByTagName("div").Count); Assert.AreEqual(2, r111.Find.AllByTagName("a").Count); Assert.AreEqual(9, r11.Find.AllByAttributes("id=~div").Count); //*** Using NodeIndexPath identification. Assert.IsTrue(r1.Find.ByNodeIndexPath("0/1/1").IdAttributeValue.Equals("input1")); Assert.IsTrue(rootFind.ByNodeIndexPath("1/0/0").TagName.Equals("div", StringComparison.OrdinalIgnoreCase)); //*** Using name Assert.IsNull(r1.Find.ByName("bla")); }
public void FindByTagAttributes() { // Find this table: // <table summary="This table lists program available at the university // based on the discipline and type of degree." // border="1" rules="all"> // OPTION I // // ~ : signifies a partial value. // ByAttributes takes a params list, so you can include N number of name=value pairs to check. Element table = Find.ByAttributes("summary=~This table lists", "border=1", "rules=all"); Assert.IsTrue(table.ElementType == ElementType.Table); }
public void Slider_DataBinding() { string minimumValue = TestContext.DataRow["MinimumValue"].ToString(); string maximumValue = TestContext.DataRow["MaximumValue"].ToString(); string selectionStart = TestContext.DataRow["SelectionStart"].ToString(); string selectionEnd = TestContext.DataRow["SelectionEnd"].ToString(); string expectedSliderStart = TestContext.DataRow["ExpectedSliderStart"].ToString(); string expectedSliderEnd = TestContext.DataRow["ExpectedSliderEnd"].ToString(); string configuratorId = "ctl00_ConfiguratorPlaceholder_ConfigurationPanel1"; Manager.LaunchNewBrowser(); Manager.ActiveBrowser.Window.Maximize(); ActiveBrowser.NavigateTo("http://demos.telerik.com/aspnet-ajax/slider/examples/clientsideapi/defaultcs.aspx"); HtmlDiv configurator = Find.ByAttributes <HtmlDiv>("class=panel configurator"); //Find.ByAttributes<HtmlDiv>("class=demo-containers").ScrollToVisible(); Manager.ActiveBrowser.ScrollBy(0, 150); Find.ById <HtmlInputText>(configuratorId + "_SmallChangeNtb").MouseClick(); Find.ById <HtmlInputText>(configuratorId + "_SmallChangeNtb").Value = "1"; Find.ById <HtmlInputText>(configuratorId + "_MinValueNtb").MouseClick(); Find.ById <HtmlInputText>(configuratorId + "_MinValueNtb").Value = minimumValue; Find.ById <HtmlInputText>(configuratorId + "_MaxValueNtb").MouseClick(); Find.ById <HtmlInputText>(configuratorId + "_MaxValueNtb").Value = maximumValue; Find.ById <HtmlInputText>(configuratorId + "_SelectionStartNtb").MouseClick(); Find.ById <HtmlInputText>(configuratorId + "_SelectionStartNtb").Value = selectionStart; Find.ById <HtmlInputText>(configuratorId + "_SelectionEndNtb").MouseClick(); Find.ById <HtmlInputText>(configuratorId + "_SelectionEndNtb").Value = selectionEnd; Find.ById <HtmlInputText>(configuratorId + "_SelectionStartNtb").MouseClick(); RadSlider slider = Find.ById <RadSlider>("RadSliderWrapper_ctl00_ContentPlaceholder1_RadSlider1"); Assert.AreEqual(expectedSliderStart, slider.SelectionStart.ToString()); Assert.AreEqual(expectedSliderEnd, slider.SelectionEnd.ToString()); }
public void SearchForXaml() { // Start browser and navigate to Telerik Academy home page Manager.LaunchNewBrowser(); ActiveBrowser.NavigateTo("http://telerikacademy.com/"); // Enter "XAML" and click Search button Find.ById <HtmlInputText>("SearchTerm").Text = "XAML"; Find.ById <HtmlInputSubmit>("SearchButton").Click(); // Locate title var title = Find .ByAttributes <HtmlContainerControl>("class=SearchResultsListTitle"); // Locate cources list var courcesList = Find .AllByAttributes <HtmlDiv>("class=SearchResultsCategory") .Where(category => category.InnerText.Contains("Курсове")) .FirstOrDefault() .Find.ByExpression <HtmlUnorderedList>(new HtmlFindExpression("tagname=ul")); // Locate tracks list var tracksList = Find .AllByAttributes <HtmlDiv>("class=SearchResultsCategory") .Where(category => category.InnerText.Contains("Тракове")) .FirstOrDefault() .Find.ByExpression <HtmlUnorderedList>(new HtmlFindExpression("tagname=ul")); // Verify results title Assert.AreEqual("Вашето търсене за \"XAML\" върна следните резултати" , title.TextContent); // Verify results Assert.AreEqual(3, courcesList.Items.Count(), "Count of cources is wrong"); Assert.AreEqual(2, tracksList.Items.Count(), "Count of tracks is wrong"); }
public void VerifySortingOnInitializeWithTable() { Manager.LaunchNewBrowser(); // From http://www.telerik.com/support/demos click "Launch Kendo UI demos" ActiveBrowser.NavigateTo("http://www.telerik.com/support/demos"); ActiveBrowser.WaitUntilReady(); Find.ByXPath <HtmlAnchor>("//*[@href='http://demos.telerik.com/kendo-ui']").Click(); ActiveBrowser.WaitUntilReady(); // Verify you are on http://demos.telerik.com/kendo-ui/ Assert.AreEqual(ActiveBrowser.Url, "http://demos.telerik.com/kendo-ui/", "KendoUI Link points to the wrong page"); // Navigate to Grid -> Initialization from table demo Find.ByXPath <HtmlAnchor>("//*[@href='/kendo-ui/grid/index']").Click(); ActiveBrowser.WaitUntilReady(); Find.ByXPath <HtmlAnchor>("//*[@href='/kendo-ui/grid/from-table']").Click(); ActiveBrowser.WaitUntilReady(); // Verify Grid is loaded and has X columns and Y rows HtmlTable grid = new HtmlTable(); bool hasGridBeenLoaded; try { grid = Find.ById <HtmlTable>("grid"); hasGridBeenLoaded = true; } catch { hasGridBeenLoaded = false; } Assert.IsTrue(hasGridBeenLoaded); var gridRowsCount = grid.Find.AllByTagName <HtmlTableRow>("tr").Count(); int gridColumsCount = Find.AllByXPath("//th").Count(); Assert.AreEqual(21, gridRowsCount); Assert.AreEqual(5, gridColumsCount); // Test sorting (grid is sorded via column headers). You define what and how to test. Find.ByAttributes <HtmlControl>("data-field=year").Find.AllByTagName <HtmlAnchor>("a").FirstOrDefault().Click(); List <string> expectedSortedValues = new List <string>(); List <string> actualSortedValues = new List <string>(); ActiveBrowser.RefreshDomTree(); var gridRows = Find.AllByXPath <HtmlTableRow>("//tbody/tr"); foreach (var gridRow in gridRows) { string yearCellValue = gridRow.Find.AllByTagName <HtmlTableCell>("td")[2].InnerText; expectedSortedValues.Add(yearCellValue); actualSortedValues.Add(yearCellValue); } expectedSortedValues.Sort(); for (int i = 0; i < expectedSortedValues.Count(); i++) { Assert.AreEqual(expectedSortedValues[i], actualSortedValues[i]); } }
public void CommonHtmlControlMethodsProperties() { // All controls have a Click/MouseClick. The .Click invokes a click from the DOM, // the MouseClick(), moves the mouse to the controls and clicks it. // // CLICKING // Find.ById <HtmlInputButton>("button1").Click(); ActiveBrowser.Refresh(); Find.ById <HtmlInputButton>("button1").MouseClick(); // You can capture any element on the page using the .Capture() Find.ById <HtmlInputImage>("image1").Capture("myfile"); // Will be stored to the Log.LogLocation // // CHECKING // // Check a checkbox and invoke the onclick event. HtmlInputCheckBox ck = Find.ById <HtmlInputCheckBox>("checkbox1"); if (ActiveBrowser.BrowserType == BrowserType.Safari) { // Unfortunately the way Safari behaves is different then the other browsers. ck.Check(true, false); } else { ck.Check(true, true); } // Query the checked state Assert.IsTrue(ck.Checked); // You can also simply set the value without invoking the clicked event. ck.Checked = false; Assert.IsFalse(ck.Checked); // Get whether a checkbox is enabled or disabled. HtmlInputCheckBox cks = Find.ById <HtmlInputCheckBox>("checkbox1"); bool disabled = cks.GetValue <bool>("disabled"); // Disable it cks.SetValue <string>("disabled", "true"); Assert.IsTrue(cks.GetValue <bool>("disabled")); // Is it visible Assert.IsTrue(cks.IsVisible()); // When the contents of a div element are larger than the declared // width or height of element it automatically adds scroll bars. // When that happens we can scroll the contents of the div element. // The value represents the offset in pixels to scroll the contents. HtmlDiv infoDiv = Find.ById <HtmlDiv>("AutoInfo"); infoDiv.ScrollTop = 50; infoDiv.ScrollLeft = 75; // // SELECTING // HtmlSelect select = Find.ById <HtmlSelect>("color_product"); Assert.IsTrue(select.SelectedOption.Value.Equals("Blue")); Assert.IsTrue(select.SelectedOption.Text.Equals("Color : Blue")); select.SelectByIndex(1); Assert.IsTrue(select.SelectedOption.Text.Equals("Color : Green")); // // SET TEXT // Find.ById <HtmlTextArea>("textarea1").Text = "NEW TEXT"; // Access common methods HtmlAnchor link = Find.ByAttributes <HtmlAnchor>("href=~google"); Assert.IsTrue(link.Attributes.Count == 3); Assert.IsTrue(link.BaseElement.TextContent.Trim().Equals("Link")); // Invoke any events on the control link.InvokeEvent(ScriptEventType.OnFocus); }
public void AspNetInProcTesting() { // Will initialize a new AspNetApplication object. Manager.LaunchNewBrowser(); // Request the page we want. ActiveBrowser.NavigateTo(TESTPAGE); // We can access raw http request properties when the // browser is AspNetHost. if (ActiveBrowser.BrowserType == BrowserType.AspNetHost) { // we wrap this part with an if..else statement so that // this test can still run on other browsers without // having to perform any recompilation. AspNetHostBrowser hostBrowser = (AspNetHostBrowser)ActiveBrowser; // get the last status code for the last response. // You can also access the full Request/Response objects using // hostBrowser.AspNetAppInstance.LastResponse // or // hostBrowser.AspNetAppInstance.LastRequest Assert.IsTrue(hostBrowser.Status == 200); } else { // Do some other type of verification... } Element label = ActiveBrowser.Find.ById("label1"); // Click a button Actions.Click(Find.ById("button1")); label.Refresh(); Assert.IsTrue(label.InnerText.Contains("Button1 Clicked")); // Click a linkbutton Actions.Click(Find.ById("linkbutton1")); label.Refresh(); Assert.IsTrue(label.InnerText.Contains("LinkButton1 Clicked")); // Set Text Actions.SetText(Find.ById("textbox1"), "Hello!"); label.Refresh(); Assert.IsTrue(label.InnerText.Contains("Hello!")); //Select From DropDown Actions.SelectDropDown(Find.ById("dropdownlist1"), "Item2"); label.Refresh(); Assert.IsTrue(label.InnerText.Contains("Item2")); // Select a link on the calendar. string dateToSelect = DateTimeFormatInfo.CurrentInfo.GetMonthName(DateTime.Today.Month) + " " + string.Format("{0:00}", DateTime.Today.Day); Actions.Click(Find.ByAttributes("title=~" + dateToSelect)); label.Refresh(); Assert.IsTrue(label.InnerText.Contains(DateTime.Today.ToShortDateString())); // Select a node in a treeview Actions.Click(Find.ById("treeView1t1")); label.Refresh(); Assert.IsTrue(label.InnerText.Contains("Node2")); }