尝试将csv文件用于selenium时出现此错误:"构造函数FileReader(String)未定义"

时间:2017-03-25 17:31:26

标签: java csv selenium

我正在尝试在selenium中读取我的登录测试用例的csv文件,我已经快速完成了这一部分(即:代码用于从csv获取数据),但是对于这段代码我有些无法得到怎么了。请帮我解决这个问题。我在Base文件中编写了这段代码,我将在其他文件中调用该方法。

下面是一个代码文件,显示错误。

  

注意:我已经使错误"构造函数CSVReader(FileReader)未定义的行#34;显示

package com.gptoday.com.gptoday.testcases;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import com.gargoylesoftware.htmlunit.javascript.host.file.FileReader;
import java.io.Reader;
import com.opencsv.CSVReader;

public class Base {
    public WebDriver driver;

    @BeforeMethod
    public void BaseSetup(){
        ProfilesIni prof = new ProfilesIni();
        FirefoxProfile ffProfile= prof.getProfile ("vishvesh");
        ffProfile.setAcceptUntrustedCertificates(true);
        ffProfile.setAssumeUntrustedCertificateIssuer(false);

        String BaseUrl = "https://www.gptoday.com";
        System.setProperty("webdriver.gecko.driver", "G:/Workplace/AutomationSetupFiles/Geckdriver/geckodriver.exe"); 
        driver = new FirefoxDriver (ffProfile);
        driver.get(BaseUrl);
    }

    @AfterMethod
    public void afterTest() {
        System.out.println("Success");
    }

    public void CheckCurrentURL(WebDriver driver){
        String actual_url;
        actual_url=driver.getCurrentUrl();   
    }

    public void csv(){
        String csvpath = "G:/Workplace/Test Automation Project";
        CSVReader reader = **new CSVReader(new FileReader(csvpath))**;
        String[] cell=new String[1000];

        while ((cell = reader.readNext())!=null)
        {
            System.out.println("After while loop");
            System.out.println("After for loop");
            String name = cell[0];
            System.out.println("name displayed = "+name );
            String email = cell[1];
            System.out.println("email displayed ="+email );
            String message = cell[2];
            System.out.println("message displayed="+message);

            //driver.findElement(username).sendKeys(name);
            //driver.findElement(password).sendKeys(email);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

导入“java.io.FileReader”,错误应该消失了。