示例#1
0
        public void MenuElementPresenceTest(string menuName)
        {
            try
            {
                // Only navigate to page if necessary.
                if (!String.Equals(WebDriver.Url, Args.AppURL))
                {
                    WebDriver.Navigate().GoToUrl(Args.AppURL);
                }

                SeleniumTestUtils.WaitForPageToLoad(WebDriver, Args.PageTimeout);

                string menuXPath = "//*[@class='cgh-link-tag' and descendant-or-self::text()[normalize-space(.)='" +
                                   menuName + "']]";

                var         wait = new WebDriverWait(WebDriver, Args.ElementTimeout);
                IWebElement menu = wait.Until(
                    SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath(menuXPath)));

                Actions actions = new Actions(WebDriver);
                actions.MoveToElement(menu).Perform();

                SeleniumTestUtils.HighlightElement(WebDriver, menu);

                if (Args.DelayMillis > 0)
                {
                    Thread.Sleep(Args.DelayMillis);
                }
            }
            catch (Exception e)
            {
                Assert.Fail($"Could not find toolbar menu '{menuName}'; reason: '{e.Message}'");
            }
        }
示例#2
0
        /// <summary>
        /// Get the zip code field value.
        /// </summary>
        /// <returns>
        /// A zip code.
        /// </returns>
        public string GetZipCode()
        {
            SeleniumTestUtils.WaitForPresenceOfElement(driver, elementTimeout, By.XPath("//input[@name='zip']"));
            SeleniumTestUtils.HighlightElement(driver, zipCodeInput);

            return(zipCodeInput.GetAttribute("value").Trim());
        }
示例#3
0
        public void HyperlinkPresenceTest(string pageSegment, string title, string text, int position)
        {
            try
            {
                string pageUrl = Args.AppURL;

                if (!pageSegment.Equals("home"))
                {
                    pageUrl = Tests.Common.TestUtils.AppendUrl(Args.AppURL, pageSegment);
                }

                // Only navigate to new page if necessary.
                if (!String.Equals(WebDriver.Url, pageUrl))
                {
                    WebDriver.Navigate().GoToUrl(pageUrl);
                }

                SeleniumTestUtils.WaitForPageToLoad(WebDriver, Args.PageTimeout);

                SeleniumVerificationUtils.VerifyHyperlinkElementExistence(WebDriver, Args.ElementTimeout, title, text, position);

                if (Args.DelayMillis > 0)
                {
                    Thread.Sleep(Args.DelayMillis);
                }
            }
            catch (Exception e)
            {
                Assert.Fail($"Could not find hyperlink element page='{pageSegment}', " +
                            $"title='{title}', text='{text}', position='{position}'; reason: '{e.Message}'");
            }
        }
示例#4
0
        /// <summary>
        /// Get the page header text.
        /// </summary>
        /// <returns>
        /// The page header text with leading and trailing whitespace removed.
        /// </returns>
        public string GetHeaderText()
        {
            SeleniumTestUtils.WaitForPresenceOfElement(driver, elementTimeout, By.XPath("//h1"));
            SeleniumTestUtils.HighlightElement(driver, h1);

            return(h1.Text.Trim());
        }
        /// <summary>
        /// Get toolbar sub menu test data from an external JSON file.
        /// </summary>
        public static IEnumerable <object[]> SubMenuElementTestData()
        {
            IDictionary <string, string[]> inputData;
            IList <object[]> outputData = new List <object[]>();

            string jsonFilePath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                                "cfg", SeleniumTestUtils.GetConfigDir(), "ToolbarMenus.json"));

            if (!File.Exists(jsonFilePath))
            {
                throw new FileNotFoundException($"Could not find file '{jsonFilePath}'.");
            }

            inputData = JsonConvert.DeserializeObject <Dictionary <string, string[]> >(File.ReadAllText(jsonFilePath));

            foreach (string keyName in inputData.Keys)
            {
                foreach (string value in inputData[keyName])
                {
                    outputData.Add(new object[] { keyName, value });
                }
            }

            return(outputData);
        }
        /// <summary>
        /// Get hyperlink element test data from an external JSON file.
        /// </summary>
        public static IEnumerable <object[]> HyperlinkElementTestData()
        {
            IDictionary <string, PageElements> inputData;
            IList <object[]> outputData = new List <object[]>();

            string jsonFilePath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                                "cfg", SeleniumTestUtils.GetConfigDir(), "HyperlinkElements.json"));

            if (!File.Exists(jsonFilePath))
            {
                throw new FileNotFoundException($"Could not find file '{jsonFilePath}'.");
            }

            inputData = JsonConvert.DeserializeObject <Dictionary <string, PageElements> >(
                File.ReadAllText(jsonFilePath));

            foreach (string pageSegment in inputData.Keys)
            {
                foreach (HyperlinkElement element in inputData[pageSegment].Hyperlinks)
                {
                    outputData.Add(new object[] { pageSegment, element.Title, element.Text, element.Position });
                }
            }

            return(outputData);
        }
示例#7
0
        /// <summary>
        /// Select a car model.
        /// </summary>
        /// <param name="model">
        /// The name of the model to select.
        /// </param>
        public void Select_Model(string model)
        {
            var selector = new SelectElement(modelSelector);

            SeleniumTestUtils.HighlightElement(driver, modelSelector);

            selector.SelectByValue(model);
        }
示例#8
0
        /// <summary>
        /// Get the selected car model.
        /// </summary>
        /// <returns>
        /// The name of a car model.
        /// </returns>
        public string GetSelectedModel()
        {
            SeleniumTestUtils.WaitForPresenceOfElement(driver, elementTimeout, By.XPath("//select[@name='model']"));
            SeleniumTestUtils.HighlightElement(driver, modelSelector);

            var selector = new SelectElement(modelSelector);

            return(selector.SelectedOption.Text.Trim());
        }
示例#9
0
        /// <summary>
        /// Type a zip code into the zip code input field.
        /// </summary>
        /// <param name="zip">
        /// The zip code to type.
        /// </param>
        public void Type_ZipCode(string zip)
        {
            SeleniumTestUtils.HighlightElement(driver, zipCodeInput);

            zipCodeInput.Click();

            // clear any previous input
            zipCodeInput.SendKeys(Keys.Control + "a");
            zipCodeInput.SendKeys(Keys.Delete);

            zipCodeInput.SendKeys(zip);
        }
示例#10
0
        /// <summary>
        /// Select a car make.
        /// </summary>
        /// <param name="make">
        /// The name of the make to select.
        /// </param>
        public void Select_Make(string make)
        {
            var selector = new SelectElement(makeSelector);

            SeleniumTestUtils.HighlightElement(driver, makeSelector);

            // work round for selection issues when selecting same make
            selector.SelectByIndex(1);
            selector.SelectByIndex(selector.Options.Count - 1);

            selector.SelectByValue(make);
        }
示例#11
0
        /// <summary>
        /// Get car model test data from external JSON files.
        /// </summary>
        public static IEnumerable <object[]> GetCarModelTestData()
        {
            IDictionary <string, CarData> carData;
            IDictionary <string, ZipCode> zipCodes;
            IList <object[]> outputData = new List <object[]>();

            string jsonFilePath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                                "cfg", SeleniumTestUtils.GetConfigDir(), "CarModels.json"));

            if (!File.Exists(jsonFilePath))
            {
                throw new FileNotFoundException($"Could not find file '{jsonFilePath}'.");
            }

            carData = JsonConvert.DeserializeObject <Dictionary <string, CarData> >(
                File.ReadAllText(jsonFilePath));

            jsonFilePath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                         "cfg", SeleniumTestUtils.GetConfigDir(), "ZipCodes.json"));

            if (!File.Exists(jsonFilePath))
            {
                throw new FileNotFoundException($"Could not find file '{jsonFilePath}'.");
            }

            zipCodes = JsonConvert.DeserializeObject <Dictionary <string, ZipCode> >(
                File.ReadAllText(jsonFilePath));

            foreach (string zipCode in zipCodes.Keys)
            {
                foreach (string make in carData.Keys)
                {
                    foreach (CarModel model in carData[make].Models)
                    {
                        outputData.Add(new object[] { make, model.Name, zipCode });
                    }
                }
            }

            return(outputData);
        }
示例#12
0
        /// <summary>
        /// Click the 'Show Me' button for the specified make and model.
        /// </summary>
        /// <param name="make">
        /// A car make name.
        /// </param>
        /// <param name="model">
        /// A car model name.
        /// </param>
        /// <returns>
        /// Reference to a search results page object.
        /// </returns>
        public Page ClickShowMeButton(string make, string model)
        {
            /*
             * Replace characters to match the application url for the search page.
             */
            make  = make.Replace(' ', '-');
            make  = make.Replace('/', '-');
            model = model.Replace(' ', '-');
            model = model.Replace('/', '-');

            /*
             * Wait for the 'Show Me' button text to contain the number of matched vehicles using a regular expression;
             * matching zero vehicles will cause a timeout exception.
             */
            SeleniumTestUtils.WaitForElementTextToMatch(driver, elementTimeout, By.XPath("//span[@class='totalRecordsText']"), "^[1-9][0-9]+$");

            SeleniumTestUtils.Click(driver, elementTimeout, showMeButton);

            SeleniumTestUtils.WaitForUrlToMatch(driver, pageTimeout, $".*{make}.*{model}.*");
            return(PageFactory.Instance.GetPage(driver, driver.Url, PageFactory.SEARCH_RESULTS_PAGE, pageTimeout, elementTimeout));
        }
示例#13
0
 /// <summary>
 /// Click the page next button.
 /// </summary>
 /// <returns>
 /// A reference to the next page object.
 /// </returns>
 public Page Click_Next_Button()
 {
     SeleniumTestUtils.Click(driver, elementTimeout, nextButton);
     SeleniumTestUtils.WaitForUrl(driver, pageTimeout, TestUtils.AppendUrl(GetBaseUrl(), PageFactory.CARS_FOR_SALE2));
     return((CarsForSale2Page)PageFactory.Instance.GetPage(driver, GetBaseUrl(), PageFactory.CARS_FOR_SALE2, pageTimeout, elementTimeout));
 }
示例#14
0
 /// <summary>
 /// Click on the 'Used Cars for Sale' menu item.
 /// </summary>
 /// <returns>
 /// A reference to the initial 'Cars For Sale' page object.
 /// </returns>
 public CarsForSale1Page ClickUsedCarsForSaleMenu()
 {
     SeleniumTestUtils.Click(driver, elementTimeout, usedCarsForSaleMenu);
     SeleniumTestUtils.WaitForUrl(driver, pageTimeout, TestUtils.AppendUrl(GetBaseUrl(), PageFactory.CARS_FOR_SALE1));
     return((CarsForSale1Page)PageFactory.Instance.GetPage(driver, GetBaseUrl(), PageFactory.CARS_FOR_SALE1, pageTimeout, elementTimeout));
 }
示例#15
0
 /// <summary>
 /// Navigate to the page.
 /// </summary>
 public void Navigate()
 {
     driver.Navigate().GoToUrl(uri.AbsoluteUri);
     SeleniumTestUtils.WaitForUrl(driver, pageTimeout, uri.AbsoluteUri);
 }