Esempio n. 1
0
 public int queryShoppingCart() throws IOException {
   int goodNum = 0;
   QueryShoppingCart qs = new QueryShoppingCart(driver);
   qs.getElement("shoppingcart").click();
   String result = qs.getElement("isempty").getText();
   if (result.equals("尝试买些东西再回来看看,肯定会有些不一样!")) {
     Log.logInfo("购物车没有商品,请去首页添加些商品吧!");
   } else {
     Log.logInfo("购物车有商品: " + qs.getElement("goodsnum").getText());
     String num = qs.getElement("goodsnum").getText();
     goodNum = Integer.parseInt(num.substring(0, num.length() - 1));
   }
   Log.logInfo("查询购物车成功");
   return goodNum;
 }
Esempio n. 2
0
  @SuppressWarnings("deprecation")
  @Test(dataProvider = "providerMethod")
  public void addShoppingCart(Map<String, String> param) throws IOException {

    AddShoppingCart sp = new AddShoppingCart(driver);
    sp.getElement("inputbox").sendKeys(param.get("keyword"));
    Log.logInfo("搜索关键字: " + param.get("keyword"));
    sp.getElement("button").click();
    sp.getElement("button").click();
    Boolean result = sp.getElement("isgoodsexist").isDisplayed();
    System.out.println("result= " + result);
    String s = null;
    if (result) {
      // ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();",
      // sp.getElement("isgoodsexist"));
      // sp.getElement("isgoodsexist").click();
      try {
        Boolean empty = sp.getElement("goodsnum").isDisplayed();
        String num = sp.getElement("goodsnum").getText();
        Log.logInfo("添加购物车前数量= " + num);
        s = num;
      } catch (Exception e) {
        Log.logInfo("购物车为空");
        s = "0";
      } finally {
        sp.getElement("goodsclick").click();
        switchWindow(param.get("goodsname"));
        sp.getElement("addshoppingcard").click();
        String num1 = sp.getElement("goodsnum").getText();
        num1 = sp.getElement("goodsnum").getText();
        Log.logInfo("添加购物车后数量= " + num1);
        Assert.assertEquals(1, Integer.parseInt(num1) - Integer.parseInt(s));
      }
    } else {
      Log.logError("你要加入购物车的商品不存在,请尝试加入其他商品");
    }
  }
Esempio n. 3
0
 public void executeForBlock(String index) throws DefinedException {
   String forName = logicTitle.get(index);
   Log.commentStep(forName);
   List<String> list = re.parameterName(forName);
   String variableName;
   int begin;
   int end;
   try {
     variableName = list.get(0);
     begin = Integer.valueOf(list.get(1));
     if (param.containsKey(list.get(1))) begin = Integer.valueOf(param.get(list.get(1)));
     end = Integer.valueOf(list.get(2));
     if (param.containsKey(list.get(2))) end = Integer.valueOf(param.get(list.get(2)));
   } catch (Exception e) {
     throw new DefinedException(forName + " for title error, miss parameter!");
   }
   for (int i = begin; i <= end; i++) {
     param.put(variableName, String.valueOf(i));
     this.executeLogicBlock(index);
   }
 }
Esempio n. 4
0
 private boolean ifCondition(String str) throws DefinedException {
   List<String> conList = re.getIfCondition(str);
   List<Boolean> temp = new ArrayList<Boolean>();
   List<String> conditions = new ArrayList<String>();
   for (String con : conList) {
     String condition = this.ifParameter(con);
     conditions.add(condition);
     List<String> pName = re.parameterName(condition);
     String determine = re.getDetermine(condition);
     boolean b;
     try {
       b = pName.get(0).equals(pName.get(1));
     } catch (Exception e) {
       throw new DefinedException("if title error, miss condition parameter!");
     }
     if (determine.equals(Keyword.getKeyword("equals"))) temp.add(b);
     if (determine.equals(Keyword.getKeyword("notEquals"))) temp.add(!b);
   }
   str = re.replaceIfCondition(str, conditions);
   Log.commentStep(str);
   if (temp.size() == 0)
     throw new DefinedException(str + " if title error, miss condition parameter!");
   return this.logicConnector(str, temp);
 }