Пример #1
0
        public void clickButton(string sButtonName, string sType, string sObjectLocator)
        {
            try
            {
                waitForElementIsPresent(sButtonName, Constants.TIME_OUT, sObjectLocator);
                switch (sType)
                {
                case "id":
                    getDriver.FindElement(By.Id(sObjectLocator)).Click();
                    break;

                case "xpath":
                    getDriver.FindElement(By.XPath(sObjectLocator)).Click();
                    break;

                case "name":
                    getDriver.FindElement(By.Name(sObjectLocator)).Click();
                    break;

                case "classname":
                    getDriver.FindElement(By.ClassName(sObjectLocator)).Click();
                    break;

                case "tagname":
                    getDriver.FindElement(By.TagName(sObjectLocator)).Click();
                    break;
                }
                ExReports.reportPass("Button '" + sButtonName + "' is clicked");
            }
            catch (Exception e)
            {
                ExReports.reportFail("Button '" + sButtonName + "' is not clicked. " + e.Message);
                throw;
            }
        }
Пример #2
0
        public bool waitForElementIsPresent(string sName, string sType, string sObjectLocator, int iTimeOut)
        {
            try
            {
                WebDriverWait wait = new WebDriverWait(getDriver, TimeSpan.FromSeconds(iTimeOut));
                switch (sType)
                {
                case "id":
                    wait.Until(ExpectedConditions.ElementIsVisible((By.Id(sObjectLocator))));
                    ExReports.reportInfo("Element '" + sName + "' is found");
                    return(true);

                case "name":
                    wait.Until(ExpectedConditions.ElementIsVisible((By.Name(sObjectLocator))));
                    ExReports.reportPass("Element '" + sName + "' is found");
                    return(true);

                case "xpath":
                    wait.Until(ExpectedConditions.ElementIsVisible((By.XPath(sObjectLocator))));
                    ExReports.reportPass("Element '" + sName + "' is found");
                    return(true);

                case "link":
                    wait.Until(ExpectedConditions.ElementIsVisible(By.LinkText(sObjectLocator)));
                    ExReports.reportPass("Element '" + sName + "' is found");
                    return(true);
                }
                return(false);
            }
            catch (WebDriverTimeoutException)
            {
                ExReports.reportFail("Timeout is over - Element '" + sName + "' is not found");
                throw;
            }
        }
Пример #3
0
 public void isElementPresent()
 {
     try
     {
         Assert.IsTrue(Common.waitForElementIsPresent("First name field", "name", "firstname", Constants.TIME_OUT));
     }
     catch (AssertFailedException e)
     {
         ExReports.reportFail("Element is on the page" + e.Message);
         throw;
     }
 }
Пример #4
0
 public void fillUserName(string sUserName)
 {
     try
     {
         Common.fillField("User name", "id", "user_login", sUserName);
     }
     catch (Exception e)
     {
         ExReports.reportFail(e.Message);
         throw;
     }
 }
Пример #5
0
 public void checkFieldIsEmpty(string sName, string sObjectLocator)
 {
     try
     {
         waitForElementIsPresent(sName, Constants.TIME_OUT, sObjectLocator);
         Assert.IsTrue(String.IsNullOrEmpty(getDriver.FindElement(By.Id(sObjectLocator)).GetAttribute("value")));
         ExReports.reportPass("Field '" + sName + "' is empty");
     } catch (AssertFailedException)
     {
         ExReports.reportFail("Field '" + sName + "' is not empty");
         throw;
     }
 }
Пример #6
0
 /// <Wait methods>
 public void waitForElementIsPresent(string sName, int iTimeOut, string sObjectLocator)
 {
     try
     {
         WebDriverWait wait = new WebDriverWait(getDriver, TimeSpan.FromSeconds(iTimeOut));
         wait.Until(ExpectedConditions.ElementIsVisible((By.Id(sObjectLocator))));
         ExReports.reportInfo("Element '" + sName + "' is found");
     } catch (WebDriverTimeoutException)
     {
         ExReports.reportFail("Timeout is over - Element '" + sName + "' is not found");
         throw;
     }
 }
Пример #7
0
 public void clickLink(string sLink)
 {
     try
     {
         getDriver.FindElement(By.LinkText(sLink)).Click();
         ExReports.reportPass("Link is selected");
     }
     catch (Exception e)
     {
         ExReports.reportFail("Link is not clicked. " + e.Message);
         throw;
     }
 }
Пример #8
0
 public void pressBack()
 {
     try
     {
         driver.Navigate().Back();
         ExReports.reportPass("'Back' button is clicked");
     }
     catch (Exception e)
     {
         ExReports.reportFail(e.Message);
         throw;
     }
 }
Пример #9
0
 public void selectProfessionYearsAndTool()
 {
     try
     {
         Profession.Click();
         Experience.Click();
         Tool.Click();
     }
     catch (Exception e)
     {
         ExReports.reportFail(e.Message);
         throw;
     }
 }
Пример #10
0
 public void checkFieldValue(string sObjectLocator, string sValue)
 {
     try
     {
         waitForElementIsPresent(sValue, Constants.TIME_OUT, sObjectLocator);
         Assert.AreEqual(getDriver.FindElement(By.Id(sObjectLocator)).GetAttribute("value"), sValue);
         ExReports.reportPass("Check field - Value '" + sValue + "' is correct");
     }
     catch (AssertFailedException)
     {
         ExReports.reportFail("Check field - Value '" + sValue + "' is not correct");
         throw;
     }
 }
Пример #11
0
 public void addToCard()
 {
     try
     {
         Common.waitForElementIsPresent("Add to Card button", "classname", "wpsc_buy_button", Constants.TIME_OUT);
         BtnAddToCard.Click();
         ExReports.reportPass("Button 'Add to card' is clicked");
     }
     catch (Exception e)
     {
         ExReports.reportFail("Add to card" + e.Message);
         throw;
     }
 }
Пример #12
0
 public void checkElementIsDisplayed(string sName, string sObjectLocator)
 {
     try
     {
         waitForElementIsPresent(sName, Constants.TIME_OUT, sObjectLocator);
         Assert.IsTrue(getDriver.FindElement(By.Id(sObjectLocator)).Displayed);
         ExReports.reportPass("Element '" + sName + "' is displayed");
     }
     catch (AssertFailedException e)
     {
         ExReports.reportFail("Element '" + sName + "' is not displayed. " + e.Message);
         throw;
     }
 }
Пример #13
0
 public void openItem()
 {
     try
     {
         Common.waitForElementIsPresent("Item link", "xpath", "//*[text()='iPhone 5']", Constants.TIME_OUT);
         lnkItem.Click();
         ExReports.reportPass("'Item link' is selected");
     }
     catch (Exception e)
     {
         ExReports.reportFail("Open item" + e.Message);
         throw;
     }
 }
Пример #14
0
 public void checkTextIsPresent(string sText)
 {
     try
     {
         WebDriverWait wait = new WebDriverWait(getDriver, TimeSpan.FromSeconds(Constants.TIME_OUT));
         wait.Until(ExpectedConditions.ElementIsVisible((By.XPath(String.Format("//*[contains(text(), '" + sText + "')]")))));
         ExReports.reportPass("Text '" + sText + "' is found on page");
     }
     catch (WebDriverTimeoutException)
     {
         ExReports.reportFail("Text '" + sText + "' is not found on page");
         throw;
     }
 }
Пример #15
0
 public void inputCredentialsAndSubmit(string sUserName, string sPassword)
 {
     try
     {
         fillUserName(sUserName);
         fillPass(sPassword);
         clickSubmitButton();
     }
     catch (Exception e)
     {
         ExReports.reportFail(e.Message);
         throw;
     }
 }
Пример #16
0
 public void selectCommands()
 {
     try
     {
         SelectElement oSelect = new SelectElement(Commands);
         oSelect.SelectByText("Navigation Commands");
         oSelect.SelectByText("Wait Commands");
         ExReports.reportPass("Two commands are selected");
     }
     catch (Exception e)
     {
         ExReports.reportFail(e.Message);
         throw;
     }
 }
Пример #17
0
        public void createFile(string sFileName)
        {
            try
            {
                if (File.Exists(sFileName))
                {
                    File.Delete(sFileName);
                }

                File.Create(sFileName);
            }
            catch (Exception e)
            {
                ExReports.reportFail("File is not created. " + e.Message);
            }
        }
Пример #18
0
        public void submitItem()
        {
            try
            {
                Common.waitForElementIsPresent("First name field", "xpath", "//input[@id='wpsc_checkout_form_2']", Constants.TIME_OUT);
                BtnSubmit.Click();
                ExReports.reportPass("'Purchase' button is clicked");

                Common.checkTextIsPresent("Thank you, your purchase is pending");
            }
            catch (Exception e)
            {
                ExReports.reportFail("Submit Item error" + e.Message);
                throw;
            }
        }
Пример #19
0
        public void fillUserFields()
        {
            try
            {
                FirstName.SendKeys("Gleb");
                ExReports.reportPass("'First name' field is filled");

                LastName.SendKeys("Shustin");
                ExReports.reportPass("'Last name' field is filled");
            }
            catch (Exception e)
            {
                ExReports.reportFail(e.Message);
                throw;
            }
        }
Пример #20
0
 public void searchItem(string sItemName)
 {
     try
     {
         Common.waitForElementIsPresent("Search", "name", "s", Constants.TIME_OUT);
         SearchField.SendKeys(sItemName);
         ExReports.reportPass("'Search' field is filled");
         SearchField.SendKeys(Keys.Enter);
         ExReports.reportPass("'Enter' is pressed");
     }
     catch (Exception e)
     {
         ExReports.reportFail("Search item" + e.Message);
         throw;
     }
 }
Пример #21
0
        public void chooseProfilePicture()
        {
            try
            {
                Common.createFile(sUploadPath);

                BtnChooseFile.Click();
                SendKeys.SendWait(sUploadPath);
                SendKeys.SendWait(@"{Enter}");

                ExReports.reportPass("File '" + UPLOAD_FILE_NAME + "' is uploaded");
            } catch (Exception e)
            {
                ExReports.reportFail("File '" + UPLOAD_FILE_NAME + "' is not uploaded. " + e.Message);
                throw;
            }
        }
Пример #22
0
 public void checkMessage(string sType, string sObjectLocator, string sMessage)
 {
     try
     {
         switch (sType)
         {
         case "id":
             waitForElementIsPresent(sMessage, Constants.TIME_OUT, sObjectLocator);
             Assert.AreEqual(getDriver.FindElement(By.Id(sObjectLocator)).Text, sMessage);
             ExReports.reportInfo("Message '" + sMessage + "' is checked");
             break;
         }
     }
     catch (AssertFailedException e)
     {
         ExReports.reportFail("Message '" + sMessage + "' is not checked. " + e.Message);
         throw;
     }
 }
Пример #23
0
 public void selectLinks()
 {
     try
     {
         PartialLink.Click();
         ExReports.reportPass("Partial Link is clicked");
         Link.Click();
         ExReports.reportPass("Link is clicked");
         Common.checkTextIsPresent("Burj Khalifa");
         ExReports.reportPass("Table page is loaded");
         pressBack();
         Common.checkTextIsPresent("Practice Automation Form");
         ExReports.reportPass("Form page is loaded");
     }
     catch (Exception e)
     {
         ExReports.reportFail(e.Message);
         throw;
     }
 }
Пример #24
0
        public void fillField(string sFieldName, string sType, string sObjectLocator, string sData)
        {
            try
            {
                switch (sType)
                {
                case "id":
                    waitForElementIsPresent(sFieldName, Constants.TIME_OUT, sObjectLocator);
                    getDriver.FindElement(By.Id(sObjectLocator)).SendKeys(sData);
                    ExReports.reportPass("Field '" + sFieldName + "' is filled");
                    break;

                case "name":
                    getDriver.FindElement(By.Name(sObjectLocator)).SendKeys(sData);
                    break;
                }
            }
            catch (Exception e)
            {
                ExReports.reportFail("Field '" + sFieldName + "' is not filled. " + e.Message);
                throw;
            }
        }
Пример #25
0
        public void selectRadioBtn(string sName)
        {
            try
            {
                IList <IWebElement> oRadioButton = getDriver.FindElements(By.Name(sName));

                bool bValue = false;
                bValue = oRadioButton.ElementAt(0).Selected;
                if (bValue == true)
                {
                    oRadioButton.ElementAt(1).Click();
                }
                else
                {
                    oRadioButton.ElementAt(0).Click();
                }
            }
            catch (Exception e)
            {
                ExReports.reportFail("Radiobutton is not selected. " + e.Message);
                throw;
            }
        }
Пример #26
0
        public void checkOutItem()
        {
            try
            {
                Common.waitForElementIsPresent("Check out", "id", "header_cart", Constants.TIME_OUT);
                BtnCount.Click();
                ExReports.reportPass("'Check out' is clicked");

                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(Constants.TIME_OUT));
                wait.Until(ExpectedConditions.TextToBePresentInElement(Count, getCount));
                ExReports.reportPass("1 item is on the card");

                //Common.waitForElementIsPresent("Continue button", "classname", "step2", Constants.TIME_OUT);
                Common.waitForElementIsPresent("Continue button", "xpath", "//span[contains(.,'Continue')]", Constants.TIME_OUT);
                BtnContinue.Click();
                ExReports.reportPass("'Continue' button is clicked");
            }
            catch (Exception e)
            {
                ExReports.reportFail("Check out item" + e.Message);
                throw;
            }
        }
Пример #27
0
        public void clearField(string sFieldName, string sType, string sObjectLocator)
        {
            try
            {
                waitForElementIsPresent(sFieldName, Constants.TIME_OUT, sObjectLocator);
                switch (sType)
                {
                case "id":
                    getDriver.FindElement(By.Id(sObjectLocator)).Clear();
                    break;

                case "name":
                    getDriver.FindElement(By.Name(sObjectLocator)).Clear();
                    break;
                }
                ExReports.reportPass("Clear field - Field '" + sFieldName + "' is cleared");
            }
            catch (Exception e)
            {
                ExReports.reportFail("Field '" + sFieldName + "' is not cleared. " + e.Message);
                throw;
            }
        }