@Test(
      dataProvider = "DP_invalid_login",
      dataProviderClass = DataProviderObjects.DP_LoginScenario.class)
  public void invalid_login(String TC_ID, String Order, String Uname, String Pwd, String expected)
      throws Exception {
    SoftAssert assert1 = new SoftAssert();
    log.info("Starting invalid_login scenario" + TC_ID + " " + Order);
    Initialize_browser();

    log.info("Browser Initialized" + TC_ID + " " + Order);

    POM_LoginScenario pom_invalid = new POM_LoginScenario(driver);
    pom_invalid.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  loggedin, the page the user currently is " + driver.getTitle());
      Assert.fail();
      tear_down();
    }
    String actual = pom_invalid.get_invalid_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");
    }
    tear_down();
    assert1.assertAll();
    log.info("Completed invalid_login scenario" + TC_ID + " " + Order);
  }
  @Test(
      groups = "integration",
      dependsOnMethods = {"createCreditCardTest"})
  public void testListCreditCard() throws PayPalRESTException {
    logger.info("**** List CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCardHistory creditCards = CreditCard.list(TokenHolder.accessToken);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    logger.info("Retrieved list of credit cards = " + creditCards.getItems());
    Assert.assertTrue(creditCards.getTotalItems() > 0);
  }
  @Test(
      groups = "integration",
      dependsOnMethods = {"createCreditCardTest"})
  public void testGetCreditCard() throws PayPalRESTException {
    logger.info("**** Get CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCard retrievedCreditCard = CreditCard.get(TokenHolder.accessToken, createdCreditCardId);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    Assert.assertEquals(
        true, this.creditCard.getId().equalsIgnoreCase(retrievedCreditCard.getId()));
    logger.info("Retrieved Credit Card status = " + retrievedCreditCard.getState());
  }
  @Test(
      groups = "integration",
      dependsOnMethods = {"testGetCreditCard"})
  public void getCreditCardForNull() {
    logger.info("**** Get CreditCard Null ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    try {
      CreditCard.get(TokenHolder.accessToken, null);
    } catch (IllegalArgumentException e) {
      Assert.assertTrue(e != null, "Illegal Argument Exception not thrown for null arguments");
    } catch (PayPalRESTException e) {
      Assert.fail();
    }
  }
  @Test(
      groups = "integration",
      dependsOnMethods = {"testUpdateCreditCard"})
  public void deleteCreditCard() throws PayPalRESTException {
    logger.info("**** Delete CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCard retrievedCreditCard = CreditCard.get(TokenHolder.accessToken, createdCreditCardId);
    retrievedCreditCard.delete(TokenHolder.accessToken);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    try {
      CreditCard.get(TokenHolder.accessToken, createdCreditCardId);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 // 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);
   }
 }
 // *****************************************************
 // 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 WebDriver getWebDriver(String br) {
   // make sure capabilities is not null
   logger.info("Starting WebDriver");
   // Set the desired capabilities
   capabilities = setDesiredCapabilites(br);
   // To run test Cases on Firefox Browser.
   if (br.equalsIgnoreCase("firefox")) {
     dr = new FirefoxDriver(capabilities);
     return dr;
   }
   return null;
 }
  @Test(groups = "unit")
  public void testCvv2() {
    logger.info("**** Test CreditCard CVV2 ****");
    CreditCard creditCard = createDummyCreditCard();

    // empty CVV2
    creditCard.setCvv2(null);
    Assert.assertEquals(-1, creditCard.getCvv2());

    // valid CVV2
    creditCard.setCvv2(123);
    Assert.assertEquals(123, creditCard.getCvv2());
  }
  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;
  }
  @Test(
      groups = "integration",
      dependsOnMethods = {"testGetCreditCard"})
  public void testUpdateCreditCard() throws PayPalRESTException {
    logger.info("**** Update CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    // set up patch request
    Patch patch = new Patch();
    patch.setOp("replace");
    patch.setPath("/expire_year");
    patch.setValue(new Integer(2020));
    List<Patch> patchRequest = new ArrayList<Patch>();
    patchRequest.add(patch);

    // send patch request
    CreditCard creditCard = new CreditCard();
    creditCard.setId(createdCreditCardId);
    CreditCard retrievedCreditCard = creditCard.update(TokenHolder.accessToken, patchRequest);

    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    Assert.assertEquals(2020, retrievedCreditCard.getExpireYear());
  }
  // will be called in before method
  public void initBeforeMethod() {
    // initialize - all before methods
    logger.info("Starting init method");
    locator = readPropertiesFile(pathLocator);
    // Launch webDriver

    dr = getWebDriver(br);
    driver = new EventFiringWebDriver(dr);
    // maximize
    driver.manage().window().maximize();
    originalWindowHandle = driver.getWindowHandle();
    // implicit wait, pageloadtimeout

    driver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(PAGELOAD_TIMEOUT, TimeUnit.SECONDS);
    // navigate
    navigateTo(url);
    createObject();
  }
示例#13
0
 protected void dump() {
   LOG.info("===== Test class\n" + m_testClass.getName());
   for (ITestNGMethod m : m_beforeClassMethods) {
     LOG.info("  @BeforeClass " + m);
   }
   for (ITestNGMethod m : m_beforeTestMethods) {
     LOG.info("  @BeforeMethod " + m);
   }
   for (ITestNGMethod m : m_testMethods) {
     LOG.info("    @Test " + m);
   }
   for (ITestNGMethod m : m_afterTestMethods) {
     LOG.info("  @AfterMethod " + m);
   }
   for (ITestNGMethod m : m_afterClassMethods) {
     LOG.info("  @AfterClass " + m);
   }
   LOG.info("======");
 }
  @Test(groups = "integration")
  public void createCreditCardTest() throws PayPalRESTException {
    logger.info("**** Create CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCard creditCard = new CreditCard();
    creditCard.setExpireMonth(EXPMONTH);
    creditCard.setExpireYear(EXPYEAR);
    creditCard.setNumber(NUMBER);
    creditCard.setType(TYPE);
    this.creditCard = creditCard.create(TokenHolder.accessToken);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    logger.info("Credit Card created with ID = " + this.creditCard.getId());
    Assert.assertEquals(true, "ok".equalsIgnoreCase(this.creditCard.getState()));
    logger.info("Created Credit Card status = " + this.creditCard.getState());
    createdCreditCardId = this.creditCard.getId();
  }
示例#15
0
  @Test
  /**
   * substitute cloud , global and local variables where each is simply a variable easy test to pass
   */
  public void processAllVarsTest() {
    String[] cloudValues = new String[] {"cbar", "cfoo", "cbaz"};
    String[] globalValues = new String[] {"gbat", "gfee", "gbiz"};
    String[] localValues = new String[] {"lbaz", "lfuu", "lbuz"};

    // -cloud variables are just the variable name set to upper case
    Map<String, String> cloudVars = new HashMap<String, String>(3);
    for (String val : cloudValues) {
      cloudVars.put(val, val.toUpperCase());
    }
    logger.info("cloud values have been set too: " + cloudVars);

    Map<String, String> globalVars = new HashMap<String, String>(3);
    for (String val : globalValues) {
      globalVars.put(val, val.toUpperCase());
    }
    logger.info("globalVars values have been set too: " + globalVars);

    Map<String, String> localVars = new HashMap<String, String>(3);
    for (String val : localValues) {
      localVars.put(val, val.toUpperCase());
    }
    logger.info("local values have been set too: " + localVars);

    CmsCI ci = new CmsCI();
    ci.setCiId(4444);
    ci.setCiName("processAllVarsTest");
    Map<String, CmsCIAttribute> attributes =
        new LinkedHashMap<String, CmsCIAttribute>(cloudValues.length * 3);
    /// set up the ci with attributes which each need replacing...
    int i = 0;
    for (String cloudVariable : cloudValues) { // 3 cloud vars
      CmsCIAttribute attrC = new CmsCIAttribute();
      attrC.setDjValue("$OO_CLOUD{" + cloudVariable + "}");
      attrC.setAttributeName("pav1");
      attributes.put("cloud_" + (++i), attrC);
    }
    for (String globalVariable : globalValues) { // 3 globals
      CmsCIAttribute attrH = new CmsCIAttribute();
      attrH.setDjValue("$OO_GLOBAL{" + globalVariable + "}");
      attrH.setAttributeName("pav2");

      attributes.put("global_" + (++i), attrH);
    }
    for (String localVariable : localValues) { // 3 locals
      CmsCIAttribute attrI = new CmsCIAttribute();
      attrI.setDjValue("$OO_LOCAL{" + localVariable + "}");
      attrI.setAttributeName("pav3");

      attributes.put("local_" + (++i), attrI);
    }
    ci.setAttributes(attributes);
    logger.info("CI Attributes have been set into the ci, attrs: " + attributes);
    Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes();
    for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) {
      System.out.println("*- b4   |" + e.getKey() + "->" + e.getValue().getDjValue());
    }

    CmsUtil util = new CmsUtil();
    dumpMaps(cloudVars, globalVars, localVars);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, cloudVars, globalVars, localVars);
    dumpCmsCIAttributes(ci);

    for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) {
      String djKey = a.getKey();
      String djAfter = a.getValue().getDjValue();
      System.out.println("after>" + djKey + "->" + djAfter);
      if (djKey.startsWith("cloud_")) {
        String expected =
            attributesBefore
                .get(djKey)
                .getDjValue()
                .replace("OO_CLOUD{", "")
                .replace("}", "")
                .toUpperCase();
        assertEquals(djAfter, expected, "did not measure up for key " + djKey);
      } else {
        if (djKey.startsWith("global_")) {
          String expected =
              attributesBefore
                  .get(djKey)
                  .getDjValue()
                  .replace("OO_GLOBAL{", "")
                  .replace("}", "")
                  .toUpperCase();
          assertEquals(djAfter, expected, "did not measure up for key " + djKey);
        } else {
          if (djKey.startsWith("local_")) {
            String expected =
                attributesBefore
                    .get(djKey)
                    .getDjValue()
                    .replace("OO_LOCAL{", "")
                    .replace("}", "")
                    .toUpperCase();
            assertEquals(djAfter, expected, "did not measure up for key " + djKey);
          }
        }
      }
    }
  }
示例#16
0
  @Test
  /** test that a global value can refer to a cloud variable */
  public void processGlobalValueWithCloudValueResolution() {
    String[] cloudValues = new String[] {"czat", "czitCCC"};
    String[] globalValues = new String[] {"czit"}; // map to czitCCC in cloud

    // -cloud variables are just the variable name set to upper case
    Map<String, String> cloudVars = new HashMap<String, String>(3);
    for (String val : cloudValues) {
      cloudVars.put(val, val.toUpperCase());
    }
    logger.info("cloud values have been set too: " + cloudVars);

    Map<String, String> globalVars = new HashMap<String, String>(3);
    for (String val : globalValues) {
      globalVars.put(
          val, "$OO_CLOUD{" + val + "CCC}" // is a reference to a cloud variable
          );
    }
    logger.info("globalVars values have been set too: " + globalVars);

    CmsCI ci = new CmsCI();
    ci.setCiId(9876);
    ci.setCiName("processGlobalValueWithCloudValueResolution");
    Map<String, CmsCIAttribute> attributes =
        new LinkedHashMap<String, CmsCIAttribute>(cloudValues.length * 3);
    /// set up the ci with attributes which each need replacing...
    int i = 0;
    for (String cloudVariable : cloudValues) { // 3 cloud vars
      CmsCIAttribute attrC = new CmsCIAttribute();
      attrC.setDjValue("$OO_CLOUD{" + cloudVariable + "}");
      attributes.put("cloud_" + (++i), attrC);
    }
    for (String globalVariable : globalValues) { // 3 globals
      CmsCIAttribute attrG = new CmsCIAttribute();
      attrG.setDjValue("$OO_GLOBAL{" + globalVariable + "}");
      attrG.setAttributeName("djdj");
      attributes.put("global_" + (++i), attrG);
    }

    ci.setAttributes(attributes);
    logger.info("CI Attributes have been set into the ci, attrs: " + attributes);
    Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes();
    for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) {
      System.out.println("*- b4   |" + e.getKey() + "->" + e.getValue().getDjValue());
    }

    CmsUtil util = new CmsUtil();
    dumpMaps(cloudVars, globalVars, null);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, cloudVars, globalVars, new HashMap<String, String>());
    dumpCmsCIAttributes(ci);

    for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) {
      String djKey = a.getKey();
      String djAfter = a.getValue().getDjValue();
      System.out.println("after>" + djKey + "->" + djAfter);
      if (djKey.startsWith("cloud_")) {
        String expected =
            attributesBefore
                .get(djKey)
                .getDjValue()
                .replace("OO_CLOUD{", "")
                .replace("}", "")
                .toUpperCase();
        assertEquals(djAfter, expected, "did not measure up for key " + djKey);
      } else {
        if (djKey.startsWith("global_")) {
          String expected =
              attributesBefore
                  .get(djKey)
                  .getDjValue()
                  .replace("OO_GLOBAL{", "")
                  .replace("}", "")
                  .toUpperCase();
          assertEquals(djAfter, expected, "did not measure up for key " + djKey);
        }
      }
    }
  }