Esempio n. 1
0
  @AfterSuite
  public static void endScript() throws Exception {

    // Once the test is completed update the end time in HTML report
    TestReports.updateEndTime(TestUtil.now("dd.MMMMM.yyyy hh.mm.ss aaa"));
    driver.quit();
  }
Esempio n. 2
0
  @BeforeSuite
  public void startTesting() throws Exception {

    // Code to Generate random numbers

    nSelPort = randomGenerator.nextInt(40000);
    strDate = getCurrentTimeStamp();
    System.out.println("date time stamp :" + strDate);

    // Start testing method will start generating the Test Reports from the beginning
    TestReports.startTesting(
        "C://Automation//apache-tomcat-7.0.27//webapps//ROOT//htmlpages//index" + strDate + ".html",
        TestUtil.now("dd.MMMMM.yyyy hh.mm.ss aaa"),
        "Payback",
        "1.0");

    // Loading Config File
    CONFIG = new Properties();
    FileInputStream fs =
        new FileInputStream(System.getProperty("user.dir") + "\\src\\config\\config.properties");
    CONFIG.load(fs);

    // LOAD Objects properties File
    Objects = new Properties();
    fs = new FileInputStream(System.getProperty("user.dir") + "\\src\\config\\Objects.properties");
    Objects.load(fs);

    // Load datatable
    Core = new Xlfile_Reader(System.getProperty("user.dir") + "\\src\\config\\Core.xlsx");
    testData = new Xlfile_Reader(System.getProperty("user.dir") + "\\src\\config\\TestData.xlsx");

    System.setProperty(
        "webdriver.chrome.driver", "E://selenium//chromedriver_win32//chromedriver.exe");
    dr = new ChromeDriver();
    driver = new EventFiringWebDriver(dr);
    driver.get(Url);

    // wait for 30 seconds and then fail
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.manage().window().maximize();
  }
Esempio n. 3
0
  @Test
  public void testApp() {

    String startTime = null;

    TestReports.startSuite("Suite 1");

    for (int tcid = 2; tcid <= Core.getRowCount("Suite1"); tcid++) {
      currentTest = Core.getCellData("Suite1", "TCID", tcid);

      // initilize start time of test
      if (Core.getCellData("Suite1", "Runmode", tcid).equals("Y")) {

        // executed the keywords

        // loop again - rows in test data
        int totalSets = testData.getRowCount(currentTest + "1");
        ; // holds total rows in test data sheet. IF sheet does not exist then 2 by default
        if (totalSets <= 1) {
          totalSets = 2; // run atleast once
        }

        for (testRepeat = 2; testRepeat <= totalSets; testRepeat++) {
          startTime = TestUtil.now("dd.MMMMM.yyyy hh.mm.ss aaa");

          APPLICATION_LOGS.debug("Executing the test " + currentTest);

          // implemented keywords file
          try {
            for (int tsid = 2; tsid <= Core.getRowCount(currentTest); tsid++) {

              // Get values from xls file

              keyword = Core.getCellData(currentTest, "Keyword", tsid);
              object = Core.getCellData(currentTest, "Object", tsid);
              currentTSID = Core.getCellData(currentTest, "TSID", tsid);
              stepDescription = Core.getCellData(currentTest, "Description", tsid);
              proceedOnFail = Core.getCellData(currentTest, "ProceedOnFail", tsid);
              data_column_name = Core.getCellData(currentTest, "Data_Column_Name", tsid);
              Method method = Keywords.class.getMethod(keyword);
              result = (String) method.invoke(method);
              APPLICATION_LOGS.debug("***Result of execution -- " + result);

              // take screenshot - every keyword
              String fileName =
                  "Suite1_TC" + (tcid - 1) + "_TS" + tsid + "_" + keyword + testRepeat + ".jpg";

              if (result.startsWith("Pass")) {
                testStatus = result;

                // Uncomment this one to capture screenshots in case of Pass, For every test step a
                // screenshot will be captured
                // TestUtil.captureScreenshot(CONFIG.getProperty("screenshotPath")+TestUtil.imageName+".jpeg");

                TestReports.addKeyword(
                    stepDescription,
                    keyword,
                    result,
                    "http://"
                        + TestUtil.Handeler()
                        + ":8080//screenshots//"
                        + TestUtil.imageNameIP
                        + ".jpeg");

              } else if (result.startsWith("Fail")) {
                testStatus = result;
                // take screenshot - only on error
                TestUtil.captureScreenshot(
                    CONFIG.getProperty("screenshotPath") + TestUtil.imageName + ".jpeg");

                // changed to make the screenshot path generic
                TestReports.addKeyword(
                    stepDescription,
                    keyword,
                    result,
                    "http://"
                        + TestUtil.Handeler()
                        + ":8080//screenshots//"
                        + TestUtil.imageNameIP
                        + ".jpeg");

                if (proceedOnFail.equalsIgnoreCase("N")) {

                  break;
                }
                break;
              }
            }

          } catch (Throwable t) {
            APPLICATION_LOGS.debug("Error came");
          }

          // report pass or fail in HTML Report

          if (testStatus == null) {
            testStatus = "Pass";
          }
          APPLICATION_LOGS.debug("######################" + currentTest + " --- " + testStatus);
          TestReports.addTestCase(
              currentTest, startTime, TestUtil.now("dd.MMMMM.yyyy hh.mm.ss aaa"), testStatus);

          if (result.startsWith("Fail")) {

            break;
          }
        }
      } else {
        APPLICATION_LOGS.debug("Skipping the test " + currentTest);
        testStatus = "Skip";

        // report skipped
        APPLICATION_LOGS.debug("#######################" + currentTest + " --- " + testStatus);
        TestReports.addTestCase(
            currentTest,
            TestUtil.now("dd.MMMMM.yyyy hh.mm.ss aaa"),
            TestUtil.now("dd.MMMMM.yyyy hh.mm.ss aaa"),
            testStatus);
      }

      testStatus = null;

      if (result != null && result.startsWith("Fail")) {
        break;
      }
    }
    TestReports.endSuite();
  }