selenium 数据驱动测试

本文档展示了如何使用TestNG进行数据驱动测试,详细解释了两种方法:一是直接在测试类中定义数据提供者,二是结合CSV文件进行数据驱动。通过这两个方法,可以有效地导入和删除卡片类型。
摘要由CSDN通过智能技术生成

方法一:使用TestNG进行数据驱动

package xxx

import java.util.List;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import util.AdminUtil;
import util.ElementInspector;
import util.Log;
/**
 * 
 * @author xxx 
 * Objective: Import all card types which are need on client test.
 */
public class importCardTypeOnCF {
    private WebDriver driver;
    private StringBuffer verificationErrors = new StringBuffer();

    @DataProvider(name = "data1")
    public Object[][] createdata() {
        return new Object[][] {
                { "Auto.piat.aic.sampleodata.action", "\"C:/automation/script/CF/upfileActionCF.exe\"" },
                { "Auto.piat.aic.sampleodata.createItem", "\"C:/automation/script/CF/upfileCreateItemCF.exe\"" },
                };
    }

    @BeforeClass(alwaysRun = true)
    @Parameters({"landscape","userName","passWord"})
    public void setUp(String landscape, String userName, String passWord) throws Exception {
        AdminUtil adminutil = new AdminUtil();
        adminutil.loginOnCF(landscape, userName, passWord);
        driver = adminutil.getDriver();
    }

    @Test(dataProvider = "data1")
    public void importCardTypes(String CardTypeName, String uploadPath) throws Exception {

        Thread.sleep(3000);
        System.out.println("Start to import " + CardTypeName);
        Log.getLogger().info("Start to import " + CardTypeName);
        // Search by card type name, if exist, do nothing, else create the
        // cardtype
        WebElement searchInputbox = driver.findElement(By.xpath(ElementInspector.Search_Inputbox));
        searchInputbox.clear();
        Thread.sleep(3000);
        searchInputbox.sendKeys(CardTypeName);
        Thread.sleep(3000);
        WebElement tbody = driver
                .findElement(By.xpath(ElementInspector.Table_CardType));
        List<WebElement> tr = tbody.findElements(By.tagName("tr"));
        WebElement tr1 = tr.get(0);
        if (tr1.findElement(By.className("xxxMListTblCell")).getText().equalsIgnoreCase(CardTypeName)) {
            System.out.println(CardTypeName + " is already exist on the landscape.");
            Log.getLogger().info(CardTypeName + " is already exist on the landscape.");
            return;
        } else {
            // create new card type button
            WebElement createCardType = driver
                    .findElement(By.xpath(ElementInspector.BUTTON_Create_CardType));
            createCardType.click();
            Thread.sleep(4000);
            // input card type name
            WebElement cardTypeName = driver
                    .findElement(By.xpath(ElementInspector.Name_CardType));
            cardTypeName.sendKeys(CardTypeName);
            Thread.sleep(4000);
            WebElement fileUploadPath = driver.findElement(By.xpath(Elemen

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值