zoukankan      html  css  js  c++  java
  • Java+Selenium 如何处理Try/Catch

    场景:为了检查数据是否存在,如果存在就把数据删除,不存在则新增保存。因为我们需要做下数据初始化准备工作。

    一、:Feature 示例:

     1 Scenario: E-251:维护薪资帐套明细
     2    When I click on menu 薪酬管理>薪资相关设定>薪资套帐管理 from HCM page
     3    When I try to delete 南昌分公司 Pay account set if exist
     4    Then add PayTerms 
     5    |薪资帐套   | 中文描述      |英文描述    |
     6    | 9         | 南昌分公司     |NanChang |
     7    When I click on menu 薪酬管理>数据准备>薪资套帐管理 from HCM page
     8    Then verify PayTerms 南昌分公司 
     9    When I click on menu 薪酬管理>薪资相关设定>帐套明细设定 from HCM page
    10    Then select Pay Account detail setting for 南昌分公司 
    11      |   开始时间          |     结束时间        |
    12      |   2018-01-01     |     2018-12-31   |
    13    Then add Pay cycle details 
    14    | 年      | 月    |  开始时间      |  结束时间     |
    15    | 2018   | 1     | 2018-01-01  | 2018-12-31 |
    16    Then create Pay cycle details 
    17     |   开始时间        |     结束时间       |
    18     |   2018-01-01   |     2018-12-31   |
    19    Then verify Pay cycle details for 南昌分公司 contians Month 12

    二、Step 示例:

         

    1 @When("^I try to delete (.+) Pay account set if exist$")
    2     public void i_try_to_delete_Pay_account_set_if_exist(String condition) throws Throwable {
    3         if(pr.isPayAccountThere(condition)) {
    4             pr.deletePayTerms(condition);
    5         }
    6     }

    三、Page 示例:

     1 /**
     2      * 薪资账套设定菜单的xpath
     3      * @param condition
     4      * @return
     5      */
     6     public String getTrXpathByTotalItemCode(String condition) {
     7         return ".//tr[./td[text()='"+ condition +"']]/td[2]" ;
     8     }
     9     
    10     /**
    11      * 判断薪资账套是否存在, 
    12      * @param condition  薪资账套名称
    13      * @return         
    14      */
    15     public boolean isPayAccountThere(String condition) {
    16         try {
    17           waitForVisible(By.xpath(getTrXpathByTotalItemCode(condition)));
    18           return true;
    19         } catch (Exception e) {
    20           return false;
    21         }
    22     }
  • 相关阅读:
    栈解旋(unwinding)
    自定义异常
    异常的基本使用
    什么是跨域?
    Vue-Vue-router跳转页面时返回顶部
    jquery&vue backTop缓慢返回顶部的方法应用
    Windows 10下使用U盘安装Ubuntu双系统
    Windows下磁盘分配操作
    在双系统(Windows与Ubuntu)下删除Ubuntu启动项
    .net framework体系结构
  • 原文地址:https://www.cnblogs.com/Shanghai-vame/p/8098185.html
Copyright © 2011-2022 走看看