Пример #1
0
  public void analyzeLinks() {
    int linksCount = selenium.getXpathCount("//a").intValue();

    ArrayList<String> linksWithText = new ArrayList<String>();
    ArrayList<String> linksWithNoText = new ArrayList<String>();

    for (int i = 1; i <= linksCount; i++) {

      if (!selenium.getText("xpath=(//a)[" + i + "]").equals("")) {
        linksWithText.add(selenium.getText("xpath=(//a)[" + i + "]"));
      } else {
        linksWithNoText.add(selenium.getAttribute("xpath=(//a)[" + i + "]@href"));
      }
    }

    java.util.Iterator<String> iterator = linksWithText.iterator();

    int i = 0;
    while (iterator.hasNext()) {
      i = i + 1;
      logger.info("Link " + i + " " + iterator.next().toString());
    }

    iterator = linksWithNoText.iterator();

    i = 0;
    while (iterator.hasNext()) {
      i = i + 1;
      logger.info("Link " + i + " with no Text so logging href " + iterator.next().toString());
    }
  }
Пример #2
0
  /** This method stops LoggingSelenium session and sets its instance to null. */
  public void stopSeleniumInstance() {
    // Comment these lines just for UrgentWowyTest
    /*logger.info("Taking screen shot before closing selenium instance");
    if (lastTestMethodResult == true) captureScreenShot(selenium, currentScreenShotPath);*/

    try {

      logger.info("Clicking on 'Sign Out' if not signed out");
      // if(selenium.isElementPresent("css=a:contains(Sign Out)")) {
      if (selenium.isTextPresent("Sign Out")) {
        selenium.click("css=a:contains(Sign Out)");
        selenium.waitForPageToLoad(TestConsts.PAGE_LOAD_TIMEOUT);
      }
    } catch (Exception e) {
      logger.info(e.getMessage());
    }

    logger.info("Setting sign  in count to 0");
    signInCount = 0;

    try {
      logger.info("Stopping selenium session");
      selenium.stop();
      logger.info("Setting selenium Instance as null");
      selenium = null;

      if (null != loggingWriter) {
        loggingWriter.close();
        loggingWriter = null;
      }
    } catch (Exception e) {
      // do nothing
    }
  }
Пример #3
0
 /**
  * Navigates user to Eat Smart Page.
  *
  * @return EatSmartPage
  */
 public EatSmartPage clickEatSmartLink() {
   selenium.goBack();
   selenium.waitForPageToLoad(TestConsts.PAGE_LOAD_TIMEOUT);
   selenium.click(Dashboard.EAT_SMART_MENU_LINK);
   selenium.waitForPageToLoad(TestConsts.PAGE_LOAD_TIMEOUT);
   return new EatSmartPage(selenium);
 }
 /**
  * This is constructor for this class. It validates that the user is on The Beachbody Challenge
  * Page.
  *
  * @param selenium
  */
 public TheBeachbodyChallengePage(LoggingSelenium selenium) {
   selenium.logComment("Executing constructor of Beachbody Challenge Page");
   this.selenium = selenium;
   assertTrue(
       "This is not The Beachbody Challenge Page of logged in user, current page "
           + selenium.getLocation(),
       selenium.getTitle().equals("Team Beachbody - The Beachbody Challenge"),
       selenium);
 }
Пример #5
0
  /**
   * This is constructor for this class. It validates that the user is on Meal Plans Page.
   *
   * @param selenium
   */
  public MealPlansPage(LoggingSelenium selenium) {
    selenium.logComment("Executing constructor of Meal Plans Page");
    this.selenium = selenium;

    assertTrue(
        "This is not Meal Plans Page of logged in user, current page " + selenium.getLocation(),
        selenium.getTitle().equals("Meal Plans"),
        selenium);
  }
 /**
  * This is constructor for this class. It validates that the user is on Shakeology And Supplements
  * Page.
  *
  * @param selenium
  */
 public ShakeologyAndSupplementsPage(LoggingSelenium selenium) {
   selenium.logComment("Executing constructor of Shakeology And Supplements Page");
   this.selenium = selenium;
   assertTrue(
       "This is not Shakeology And Supplements Page of logged in user, current page "
           + selenium.getLocation(),
       selenium.getTitle().equals("Team Beachbody - Eat Smart: Supplements"),
       selenium);
 }
Пример #7
0
  /**
   * This method takes screen shot of web page. After taking screen shot, it saves that to file with
   * test method name and time stamp. This also writes a comment (having link to screenshot) to
   * selenium logging file created through LoggingSelenium.
   */
  public void captureScreenShot(LoggingSelenium selenium, String screenshotsResultsPath) {

    try {

      final String SCREENSHOT_PATH = "screenshots";
      /*
      String screenshotsResultsPath = new File(RESULTS_BASE_PATH
      		+ File.separator + SCREENSHOT_PATH).getAbsolutePath();


      if (!new File(screenshotsResultsPath).exists()) {
      	new File(screenshotsResultsPath).mkdirs();
      }*/

      String imageName = "Image" + timeStampForFileName() + ".png";

      String finalImage = screenshotsResultsPath + File.separator + imageName;

      String browser = ConfigFileReader.getConfigItemValue("browser");
      if (browser.equals("*chrome") || browser.equals("*firefox") || browser.equals("*iehta")) {
        // call captureEntirePageScreenshotToString method and it will
        // return Base64 encoded string referring to screen shot
        String base64Screenshot = selenium.captureEntirePageScreenshotToString("");

        // Decode that Base64 encoded string to get actual screen shot.
        // Finally this screen shot will be written to file object.
        byte[] decodedScreenshot = Base64.decode(base64Screenshot);

        // create instance of FileOutputStream by passing it filename
        FileOutputStream fos = new FileOutputStream(new File(finalImage));

        // Write decoded screenshot to fileoutputstream object
        fos.write(decodedScreenshot);
        fos.close();
      } else {
        selenium.captureScreenshot(finalImage);
      }

      String failedSS =
          "<a href=\"file://" + finalImage + "\">Screenshot for previous action " + "</a>";
      logger.debug(finalImage);
      // selenium.logComment(failedSS);
      selenium.logComment(
          "<a href=\""
              + SCREENSHOT_PATH
              + "/"
              + imageName
              + "\"><img src=\""
              + SCREENSHOT_PATH
              + "/"
              + imageName
              + "\" alt=\"Page Screen Shot\" width=\"150\" height=\"300\" border=\"5\"/></a>");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #8
0
  protected void startSession() throws Exception {
    /*startSeleniumSession("localhost", 4444, "*chrome",
    	"http://www.abc.com", LoggingResultsFormatter);
    selenium = session();*/

    selenium.setTimeout(TIMEOUT);
    selenium.open("/");
    selenium.windowFocus();
    selenium.windowMaximize();
  }
Пример #9
0
  public void analyzeHiddenElements() {
    int hiddenElementsCount = selenium.getXpathCount("//*[contains(@type, 'hidden')]").intValue();
    ArrayList<String> hiddenElements = new ArrayList<String>();

    String id = "not defined",
        name = "not defined",
        value = "not defined",
        className = "not defined";
    for (int i = 1; i <= hiddenElementsCount; i++) {
      try {
        id = selenium.getAttribute("xpath=(//*[contains(@type, 'hidden')])[" + i + "]@id");
      } catch (Exception e) {
      }
      try {
        name = selenium.getAttribute("xpath=(//*[contains(@type, 'hidden')])[" + i + "]@name");
      } catch (Exception e) {
      }
      try {
        value = selenium.getAttribute("xpath=(//*[contains(@type, 'hidden')])[" + i + "]@value");
      } catch (Exception e) {
      }
      try {
        className =
            selenium.getAttribute("xpath=(//*[contains(@type, 'hidden')])[" + i + "]@class");
      } catch (Exception e) {
      }

      hiddenElements.add(
          "Hidden Element: "
              + i
              + "|| id: "
              + id
              + "|| name: "
              + name
              + "|| value: "
              + value
              + "|| class: "
              + className);
    }

    java.util.Iterator<String> iterator = hiddenElements.iterator();

    while (iterator.hasNext()) {
      logger.info(iterator.next().toString());
    }
  }
Пример #10
0
  public void getEnvInfo() {
    // To Get the name of the browser
    System.out.println("Name of the browser used" + selenium.getEval("navigator.appName;"));

    // To Get the code name of the browser using Selenium
    System.out.println("Code name of the browser" + selenium.getEval("navigator.appCodeName;"));

    // To Get the browser version using Selenium
    System.out.println(
        "browser version of the selenium" + selenium.getEval("navigator.appVersion;"));

    // To Get the Operating System Details using Selenium
    System.out.println(" " + selenium.getEval("navigator.userAgent;"));

    // To Get whether the cookies are enabled in the browser
    System.out.println("Cookies are enabled: " + selenium.getEval("navigator.cookieEnabled;"));

    // To Get the Language Details of the Browser
    System.out.println(
        "Language used by the browser:" + selenium.getEval("navigator.userLanguauge;"));

    // To Get Default language of the Operating System
    System.out.println(
        "Default Language used by the Operating System: "
            + selenium.getEval("navigator.systemLanguage;"));
  }
Пример #11
0
 /**
  * This method evaluates a boolean expression and based on success/failure, stores failure message
  * in an instance of StringBuilder class.
  *
  * @param success Condition to Check, should return true/false
  * @param message Failure Message to log in case conditions evaluates to false
  * @param messages Messages container to store Failure messages
  */
 public void assertSoft(
     boolean success, String message, StringBuilder messages, LoggingSelenium selenium) {
   if (!success) {
     messages.append("<br>" + message + "<br>");
     // Comment this line for UrgentWowyTest if there is a need
     // captureScreenShot(selenium, currentScreenShotPath);
     selenium.logAssertion("Assertion Error", message, "");
   }
 }
Пример #12
0
 public boolean waitForTextNotPresent(String locator, String textToCheck) {
   for (int second = 0; ; second++) {
     if (second >= TestConsts.TIMEOUT) return false;
     try {
       if (!textToCheck.equals(selenium.getText(locator))) return true;
     } catch (Exception e) {
     }
     sleep(1000);
   }
 }
Пример #13
0
 public boolean waitForSelectedValue(String locator, String pattern) {
   for (int second = 0; ; second++) {
     if (second >= TestConsts.TIMEOUT) return false;
     try {
       if (pattern.equals(selenium.getSelectedValue(locator))) return true;
     } catch (Exception e) {
     }
     sleep(1000);
   }
 }
Пример #14
0
 /**
  * @param locator
  * @param value
  * @return
  */
 public boolean waitForConfirmationPresent() {
   for (int second = 0; ; second++) {
     if (second >= TestConsts.TIMEOUT) return false;
     try {
       if (selenium.isConfirmationPresent()) return true;
     } catch (Exception e) {
     }
     sleep(1000);
   }
 }
Пример #15
0
 /**
  * @param locator
  * @param value
  * @return
  */
 public boolean waitForNotAtrribute(String locator, String value) {
   for (int second = 0; ; second++) {
     if (second >= TestConsts.TIMEOUT) return false;
     try {
       if (!value.equals(selenium.getAttribute(locator))) return true;
     } catch (Exception e) {
     }
     sleep(1000);
   }
 }
Пример #16
0
 public boolean isTextPresent(String textToCheck) {
   for (int second = 0; ; second++) {
     if (second >= TestConsts.TIMEOUT) return false;
     try {
       if (selenium.isTextPresent(textToCheck)) return true;
     } catch (Exception e) {
     }
     sleep(1000);
   }
 }
Пример #17
0
  public void dragAndDropToObject(String sourceElement, String destinationElement) {
    assertTrue(
        "Element " + sourceElement + " not found", waitForElementPresent(sourceElement), selenium);
    assertTrue(
        "Element " + destinationElement + " not found",
        waitForElementPresent(destinationElement),
        selenium);

    selenium.dragAndDropToObject(sourceElement, destinationElement);
  }
Пример #18
0
 public boolean waitForEditable(String locator) {
   for (int second = 0; ; second++) {
     if (second >= TestConsts.TIMEOUT) return false;
     try {
       if (selenium.isEditable(locator)) return true;
     } catch (Exception e) {
     }
     sleep(1000);
   }
 }
Пример #19
0
 public boolean waitForSelectOptions(String promptText) {
   for (int second = 0; ; second++) {
     if (second >= TestConsts.TIMEOUT) return false;
     try {
       if (promptText.equals(selenium.getPrompt())) return false;
     } catch (Exception e) {
     }
     sleep(1000);
   }
 }
 /** Clicks on Sign out link to sign out of the website. */
 public void clickSignOut() {
   selenium.click(Home.SIGNOUT_LINK);
   selenium.waitForPageToLoad(TestConsts.PAGE_LOAD_TIMEOUT);
   selenium.waitForElementPresent(Home.SIGN_IN_LINK);
 }
Пример #21
0
 /**
  * Method to override selenium uncheck method. This waits for given element to present for 60
  * seconds Once it gets that element, it unchecks that. Otherwise it fails the assertion.
  *
  * @param element Locator for element
  */
 public void uncheck(String element) {
   assertTrue("Element " + element + " not found", waitForElementPresent(element), selenium);
   selenium.uncheck(element);
 }
 /**
  * Clicks on Slimming Formula Learn More Link. Navigates user to Shopping Cart Page.
  *
  * @return
  */
 public ShoppingCartPage clickSlimmingFormulaLearnMoreLink() {
   selenium.click(SLIMMING_FORMULA_LEARN_MORE);
   selenium.waitForPageToLoad(TestConsts.PAGE_LOAD_TIMEOUT);
   return new ShoppingCartPage(selenium);
 }
 /**
  * Clicks on 'Learn More' link for 'P90X Peak Performance Protein Bars'. Navigates user to
  * Shopping Cart Page.
  *
  * @return ShoppingCartPage
  */
 public ShoppingCartPage clickP90XPeakPerformanceProteinBarsLearnMoreLink() {
   selenium.click(P90X_PEAK_PERFORMANCE_PROTEIN_BARS_LEARN_MORE);
   selenium.waitForPageToLoad(TestConsts.PAGE_LOAD_TIMEOUT);
   return new ShoppingCartPage(selenium);
 }
 /**
  * Returns the number of Learn More links displayed on the Supplements Page.
  *
  * @return int
  */
 public int getLearnMoreLinksCount() {
   return selenium.getXpathCount(LEARN_MORE_LINKS).intValue();
 }
 /**
  * Clicks on 'Learn More' link for Shakeology. Navigates user to Shakeology Page.
  *
  * @return ShakeologyPage
  */
 public ShakeologyPage clickShakeologyLearnMoreLink() {
   selenium.click(SHAKEOLOGY_LEARN_MORE);
   selenium.waitForPageToLoad(TestConsts.PAGE_LOAD_TIMEOUT);
   return new ShakeologyPage(selenium);
 }
 /**
  * Returns the number of Supplement choice boxes displayed on the Supplements Page.
  *
  * @return int
  */
 public int getContentBoxesCount() {
   return selenium.getXpathCount(SUPPLEMENT_CHOICE_BOXES).intValue();
 }
Пример #27
0
 /**
  * Method to override selenium focus method. This waits for given element to present for 60
  * seconds Once it gets that element, it focuses on that. Otherwise it fails the assertion.
  *
  * @param element Locator for element
  */
 public void focus(String element) {
   assertTrue("Element " + element + " not found", waitForElementPresent(element), selenium);
   selenium.focus(element);
 }
 /**
  * Returns the number of reviews displayed in bazaar voice of Shakeology.
  *
  * @return int
  */
 public int getReviewCount() {
   return selenium.getXpathCount(SupplementsTab.REVIEW_XPATH).intValue();
 }
 /**
  * Returns the number of stars displayed in bazaar voice of Shakeology.
  *
  * @return int
  */
 public int getStarsCount() {
   return selenium.getXpathCount(SupplementsTab.STAR_IMAGE_XPATH).intValue();
 }
 /**
  * Clicks on 'Contest FAQ' link in the left hand menu. Navigates user to Contest FAQ Page.
  *
  * @return ContestFAQPage
  */
 public ContestFAQPage goToContestFAQPage() {
   selenium.click(Contests.LEFT_MENU_CONTEST_FAQ_LINK);
   selenium.waitForPageToLoad(TestConsts.PAGE_LOAD_TIMEOUT);
   return new ContestFAQPage(selenium);
 }