Esempio n. 1
0
 @Test(
     dataProvider = "DP_valid_login",
     dataProviderClass = DataProviderObjects.DP_LoginScenario.class,
     groups = {"SmokeTest"})
 public void avalid_login(String TC_ID, String Order, String Uname, String Pwd, String expected)
     throws Exception {
   SoftAssert assert1 = new SoftAssert();
   Initialize_browser();
   POM_LoginScenario pom_valid = new POM_LoginScenario(driver);
   pom_valid.execute_common_methods_log(Uname, Pwd);
   if (!driver
       .getTitle()
       .equalsIgnoreCase(
           "Buy Books Online | Online Bookstore India | Online Book Shopping | Free Shipping Across India")) {
     log.error(
         "The user has failed to login, the page the user currently is " + driver.getTitle());
     Assert.fail();
     tear_down();
   }
   String actual = pom_valid.get_valid_log_msg();
   assert1.assertEquals(
       actual, expected, "The actual found is" + actual + " The expected is " + expected);
   if (actual.equalsIgnoreCase(expected)) {
     log.info("The validation has passed");
   } else {
     log.error("THe validation has failed");
   }
   pom_valid.click_signout();
   tear_down();
   assert1.assertAll();
 }
 // -------------------------------------------------------
 //	Click Method.
 public void click(By by) {
   try {
     getWebElement(by).click();
   } catch (Throwable t) {
     logger.error("cannot click by " + by, t);
   }
 }
 // close all existing opened browser
 public void closeAllBr() {
   try {
     driver.close();
     driver.quit();
   } catch (Throwable t) {
     logger.error("cannot close browser", t);
   }
 }
 // This method can be used to navigate to specific url
 public void navigateTo(String url) {
   try {
     logger.info("navigating to url--" + url);
     driver.navigate().to(url);
   } catch (Throwable e) {
     logger.error("cannot navigate to url " + url, e);
   }
 }
 public void clearAndSendKeys(By by, String toType) {
   try {
     getWebElement(by).clear();
     getWebElement(by).sendKeys(toType);
   } catch (Throwable t) {
     logger.error("cannot type to " + by, t);
   }
 }
 public String getTextValue(By by) {
   try {
     // String strTextValue= getWebElement(by).getText();
     strTextValue = getWebElement(by).getText();
   } catch (Throwable t) {
     logger.error("cannot type to " + by, t);
   }
   return strTextValue;
 }
  // selects by String value
  public void selectByValue(By by, String value) {
    try {

      new Select(getWebElement(by)).selectByValue(value);

    } catch (Throwable t) {
      logger.error("cannot select webelement by " + by, t);
    }
  }
 // *****************************************************
 // basic method-type, click, double click, drag and drop
 // GetWebElement
 public WebElement getWebElement(By by) {
   try {
     logger.info("finding webelement by " + by);
     return driver.findElement(by);
   } catch (Throwable t) {
     logger.error("could not find webElement by " + by, t);
   }
   return null;
 }
  public Properties readPropertiesFile(String path) {
    try {
      logger.info("loading properties file " + path);
      Properties prop = new Properties();
      FileInputStream fis = new FileInputStream(path);

      prop.load(fis);
      return prop;

    } catch (Throwable t) {
      logger.error("File could not be loaded" + path, t);
    }
    return null;
  }
  /** @param br purpose: set desiredCapanbilities */
  public DesiredCapabilities setDesiredCapabilites(String browserCapability) {
    capabilities = new DesiredCapabilities();

    switch (browserCapability) {
      case "firefox":
        capabilities.setBrowserName("firefox");
        capabilities.setPlatform(Platform.ANY);
        break;

      default:
        try {
          throw new Throwable("no capalities matched");
        } catch (Throwable e) {
          // TODO Auto-generated catch block
          logger.error("no capabilites found", e);
        }
    }
    return capabilities;
  }
 /** Creates summary of the run */
 public void generateReport(List<XmlSuite> xml, List<ISuite> suites, String outdir) {
   try {
     m_out = createWriter(outdir);
   } catch (IOException e) {
     L.error("output file", e);
     return;
   }
   ConfigReader cr = ConfigReader.getInstance();
   builder.setEncoding(cr.getSrouceCodeEncoding());
   builder.addSourceTree(new File(cr.getSourceCodeDir()));
   startHtml(m_out);
   generateSuiteSummaryReport(suites);
   testIds.clear();
   generateMethodSummaryReport(suites);
   testIds.clear();
   generateMethodDetailReport(suites);
   testIds.clear();
   endHtml(m_out);
   m_out.flush();
   m_out.close();
 }