Ejemplo n.º 1
0
        public void GetElementsAsListTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            Assert.IsTrue(elementActions.GetElementsAsList(By.XPath("//ul/li")).Count > 0, "Element list wasn't created.");
        }
Ejemplo n.º 2
0
        public void IsDisplayedIWebElementTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            Assert.IsTrue(elementActions.IsDisplayed(Driver.FindElement(By.XPath("//a[text()='A/B Testing']"))), "The A/B link wasn't displayed.");
        }
Ejemplo n.º 3
0
 public LoginPage()
 {
     _wait           = new Waits();
     _fileLocations  = new FileLocations();
     _elementActions = new ElementActions();
     PageFactory.InitElements(BeforeHooks.driver, this);
 }
Ejemplo n.º 4
0
        public void IsEnabledByTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            Assert.IsTrue(elementActions.IsEnabled(By.XPath("//a[text()='A/B Testing']")), "The A/B link wasn't enabled.");
        }
Ejemplo n.º 5
0
        public void GetTextByTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            Assert.AreEqual("Welcome to the-internet", elementActions.GetText(By.XPath("//h1")), "The text didn't match.");
        }
Ejemplo n.º 6
0
        public void ClickIWebElementTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            elementActions.Click(Driver.FindElement(By.XPath("//a[text()='A/B Testing']")));
            Assert.IsTrue(Driver.Url.Contains("/abtest"), "URL didn't contain '/abtest'.");
        }
Ejemplo n.º 7
0
        public void GetSelectedOptionIWebElementTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://automate-apps.com/select-multiple-options-from-a-drop-down-list/";
            elementActions.SelectDropdownValueByText(By.XPath("//select[@name='cars']"), "Honda");
            Assert.AreEqual("Honda", elementActions.GetSelectedOption(Driver.FindElement(By.XPath("//select[@name='cars']"))).Text, "The selected options didn't match.");
        }
Ejemplo n.º 8
0
        public void NestedChildFrameTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "https://demoqa.com/nestedframes";
            var element = elementActions.FindElement(By.XPath("//p"));

            Assert.AreEqual("Child Iframe", element.Text, "The element text didn't match.");
        }
Ejemplo n.º 9
0
        public void NoFrameTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "https://demoqa.com/nestedframes";
            var element = elementActions.FindElement(By.XPath("//div[@class='main-header']"));

            Assert.AreEqual("Nested Frames", element.Text, "The element text didn't match.");
        }
Ejemplo n.º 10
0
        public void BadElementTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "https://demoqa.com/nestedframes";
            var element = elementActions.FindElement(By.XPath("//div[@class='false-header']"));

            Assert.IsNull(element, "The element object wasn't null.");
        }
Ejemplo n.º 11
0
        public void SelectDropdownValueByIndexIWebElementTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            elementActions.Click(Driver.FindElement(By.XPath("//a[text()='Dropdown']")));
            elementActions.SelectDropdownValueByIndex(Driver.FindElement(By.Id("dropdown")), 1);
            Assert.AreEqual("Option 1", elementActions.GetSelectedOption(Driver.FindElement(By.Id("dropdown"))).Text, "The selected dropdown values didn't match.");
        }
Ejemplo n.º 12
0
        public void IsSelectedIWebElementTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            elementActions.Click(By.XPath("//a[text()='Checkboxes']"));
            elementActions.Click(By.XPath("//form[@id='checkboxes']/input[1]"));
            Assert.IsTrue(elementActions.IsSelected(Driver.FindElement(By.XPath("//form[@id='checkboxes']/input[1]"))), "The checkbox wasn't selected.");
        }
Ejemplo n.º 13
0
        public void TypeIWebElementTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            elementActions.Click(Driver.FindElement(By.XPath("//a[text()='Forgot Password']")));
            elementActions.Type(Driver.FindElement(By.XPath("//input[@id='email']")), "james");
            Assert.AreEqual("james", Driver.FindElement(By.Id("email")).GetAttribute("value"), "The textbox values didn't match.");
        }
Ejemplo n.º 14
0
        public void IsMultiSelectTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://automate-apps.com/select-multiple-options-from-a-drop-down-list/";
            elementActions.SelectDropdownValueByText(By.XPath("//select[@name='cars']"), "Honda");
            elementActions.SelectDropdownValueByText(By.XPath("//select[@name='cars']"), "BMW");
            Assert.IsTrue(elementActions.GetAllSelectedOptions(Driver.FindElement(By.XPath("//select[@name='cars']"))).Count == 2, "The total selected dropdown options wasn't 2.");
        }
Ejemplo n.º 15
0
        public void TypeByTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            elementActions.Click(Driver.FindElement(By.XPath("//a[text()='Forgot Password']")));
            new WebDriverWait(Driver, TimeSpan.FromSeconds(30)).Until(ExpectedConditions.ElementIsVisible(By.XPath("//input[@id='email']")));
            elementActions.Type(By.XPath("//input[@id='email']"), "james");
            Assert.AreEqual("james", Driver.FindElement(By.Id("email")).GetAttribute("value"), "The textbox values didn't match.");
        }
Ejemplo n.º 16
0
        public void HoverByTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            elementActions.Click(By.XPath("//a[text()='Hovers']"));
            Assert.IsFalse(elementActions.IsDisplayed(By.XPath("//h5[text()='name: user1']")), "The specified text isn't displayed.");
            elementActions.Hover(By.XPath("//div[@class='figure'][1]"));
            Assert.IsTrue(elementActions.IsDisplayed(By.XPath("//h5[text()='name: user1']")), "The specified text isn't displayed.");
        }
Ejemplo n.º 17
0
        public void DragAndDropIWebElementTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            elementActions.Click(By.XPath("//a[text()='Drag and Drop']"));
            Assert.AreEqual("A", Driver.FindElement(By.XPath("//div[@id='columns']/div[1]/header")).Text);
            elementActions.DragAndDrop(Driver.FindElement(By.Id("column-a")), Driver.FindElement(By.Id("column-b")));
            Assert.AreEqual("B", Driver.FindElement(By.XPath("//div[@id='columns']/div[1]/header")).Text, "The boxes didn't drag and drop.");
        }
Ejemplo n.º 18
0
        public static ElementResult ExecuteAction(this ElementResult elementRef, ElementObject ele)
        {
            if (ele == null)
            {
                ele = new ElementObject();
            }
            var ea = new ElementActions(elementRef.TE);

            return(ea.ExecuteAction(ele, elementRef));
        }
Ejemplo n.º 19
0
        public void IsAlertDisplayedTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            elementActions.Click(By.XPath("//a[text()='JavaScript Alerts']"));
            elementActions.Click(By.XPath("//button[text()='Click for JS Alert']"));
            elementActions.WaitForAlertToBeVisible(30);
            Assert.IsTrue(elementActions.IsAlertDisplayed(), "Alert wasn't displayed.");
        }
Ejemplo n.º 20
0
        public void DeselectDropdownValueByValueIndexTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://automate-apps.com/select-multiple-options-from-a-drop-down-list/";
            elementActions.SelectDropdownValueByText(By.XPath("//select[@name='cars']"), "BMW");
            Assert.AreEqual("BMW", elementActions.GetSelectedOption(By.XPath("//select[@name='cars']")).Text, "The selected dropdown values didn't match.");
            elementActions.DeselectDropdownValueByIndex(Driver.FindElement(By.XPath("//select[@name='cars']")), 2);
            Assert.IsNull(elementActions.GetSelectedOption(By.XPath("//select[@name='cars']")), "The selected dropdown option wasn't null.");
        }
Ejemplo n.º 21
0
        public void IframeIWebelementTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            elementActions.Click(By.XPath("//a[text()='Frames']"));
            elementActions.Click(By.XPath("//li/a[text()='iFrame']"));
            Assert.IsFalse(elementActions.IsDisplayed(By.Id("tinymce")), "The specified text isn't displayed.");
            elementActions.SwitchToFrame(Driver.FindElement(By.Id("mce_0_ifr")));
            Assert.IsTrue(elementActions.IsDisplayed(By.Id("tinymce")), "The specified text isn't displayed.");
        }
Ejemplo n.º 22
0
        public void SwitchToNewestWindowTest()
        {
            var browserActions = new BrowserActions(Driver);
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            elementActions.Click(By.XPath("//a[text()='Multiple Windows']"));
            elementActions.Click(By.XPath("//a[text()='Click Here']"));
            browserActions.SwitchToNewestWindow();
            Assert.AreEqual("New Window", browserActions.GetPageTitle(), "The newest window page title didn't match.");
        }
Ejemplo n.º 23
0
        public void DismissAlertTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            elementActions.Click(By.XPath("//a[text()='JavaScript Alerts']"));
            elementActions.Click(By.XPath("//button[text()='Click for JS Confirm']"));
            Assert.IsTrue(elementActions.IsAlertDisplayed(), "Alert wasn't displayed.");
            elementActions.DismissAlert();
            Assert.IsFalse(elementActions.IsAlertDisplayed(), "Alert was still displayed.");
        }
Ejemplo n.º 24
0
        public void GetAlertTextTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            elementActions.Click(By.XPath("//a[text()='JavaScript Alerts']"));
            elementActions.Click(By.XPath("//button[text()='Click for JS Alert']"));
            var text = elementActions.GetAlertText();

            Assert.AreEqual("I am a JS Alert", text, "The alert text didn't match.");
        }
Ejemplo n.º 25
0
        public void CustomDownloadFileLocationTest()
        {
            var elementActions = new ElementActions(Driver);

            Driver.Url = "http://the-internet.herokuapp.com/";
            elementActions.Click(By.XPath("//a[text()='File Download']"));
            var items        = elementActions.GetElementsAsList(By.XPath("//div[@class='example']/a"));
            var downloadFile = items[1].Text;
            var downloadPath = string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["DownloadLocation"].ToString()) ? $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\downloads\\" : System.Configuration.ConfigurationManager.AppSettings["DownloadLocation"];

            FileHelper.DeleteFile(downloadPath, downloadFile);
            elementActions.Click(items[1]);
            FileHelper.WaitForFileDownload(downloadFile, downloadPath);
            Assert.IsTrue(File.Exists($"{downloadPath}\\{downloadFile}"), "The file wasn't downloaded successfully.");
        }
Ejemplo n.º 26
0
        public static List <ElementResult> ExecuteActions(this ElementResult elementRef, ElementObject ele)
        {
            if (!elementRef.Success)
            {
                return(new List <ElementResult>()
                {
                    new ElementResult(elementRef.TE)
                });
            }

            if (ele == null)
            {
                ele = new ElementObject();
            }
            var ea = new ElementActions(elementRef.TE);

            return(ea.ExecuteActions(ele, elementRef));
        }
Ejemplo n.º 27
0
 public BasePage(IWebDriver driver)
 {
     ElementActions = new ElementActions(driver);
     BrowserActions = new BrowserActions(driver);
 }
Ejemplo n.º 28
0
 public Page(IWebDriver driver)
 {
     Driver  = driver;
     Actions = new ElementActions(Driver);
 }
Ejemplo n.º 29
0
 public void LoginSuccessfully(string userName, string passWord)
 {
     ElementActions.AlertDataEnter(_driver, userName);
     ElementActions.AlertDataEnter(_driver, passWord);
     ElementActions.AlertAccept(_driver);
 }
Ejemplo n.º 30
0
 public void LoginUnSuccessfully()
 {
     ElementActions.AlertDismiss(_driver);
 }