参数硒问题

时间:2014-06-18 15:09:56

标签: java exception selenium

我有以下硒测试代码。 问题是,当我想使用csv文件时,我必须从generateData() - test中给出下一个测试参数。但是它没有用,当我尝试在Eclipse中运行测试时,它一直给我这个错误:java.lang.Exception:方法testSeleniumRegistrerenKlant应该没有参数。

public class SeleniumRegistrerenKlant {
    private WebDriver driver;
    private String baseUrl;
    private boolean acceptNextAlert = true;
    private StringBuffer verificationErrors = new StringBuffer();

    @Before
    public void setUp() throws Exception {
        driver = new FirefoxDriver();
        baseUrl = "http://localhost:8080/";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void generateData() throws Exception {
        String username;
        String realname;
        String pwd;
        String email;
        String adres;
        String postcode;

        BufferedReader reader = null;

        try {
            File file = new File("tpwc1.csv");
            reader = new BufferedReader(new FileReader(file));

            String line;
            while ((line = reader.readLine()) != null) {
                @SuppressWarnings("resource")
                Scanner s = new Scanner(line);
                s.useDelimiter(";");
                while (s.hasNext()) {
                    username = s.next();
                    realname = s.next();
                    pwd = s.next();
                    email = s.next();
                    adres = s.next();
                    postcode = s.next();
                    testSeleniumRegisterenKlant(username, realname, pwd, email,
                            adres, postcode);
                }

            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    @Test
    public void testSeleniumRegisterenKlant(String username, String realname,
            String pwd, String email, String adres, String postcode)
            throws Exception {
        driver.get(baseUrl + "/atd/index.jsp");
        driver.findElement(By.linkText("Registreer")).click();
        driver.findElement(By.name("username")).clear();
        driver.findElement(By.name("username")).sendKeys(username);
        driver.findElement(By.name("realname")).clear();
        driver.findElement(By.name("realname")).sendKeys(realname);
        driver.findElement(By.name("pwd")).clear();
        driver.findElement(By.name("pwd")).sendKeys(pwd);
        driver.findElement(By.name("pwd2")).clear();
        driver.findElement(By.name("pwd2")).sendKeys(pwd);
        driver.findElement(By.name("email")).clear();
        driver.findElement(By.name("email")).sendKeys(email);
        driver.findElement(By.name("email2")).clear();
        driver.findElement(By.name("email2")).sendKeys(email);
        driver.findElement(By.name("adres")).clear();
        driver.findElement(By.name("adres")).sendKeys(adres);
        driver.findElement(By.name("postcode")).clear();
        driver.findElement(By.name("postcode")).sendKeys(postcode);
        driver.findElement(By.cssSelector("input.down")).click();
    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
    }

    private boolean isElementPresent(By by) {
        try {
            driver.findElement(by);
            return true;
        } catch (NoSuchElementException e) {
            return false;
        }
    }

    private boolean isAlertPresent() {
        try {
            driver.switchTo().alert();
            return true;
        } catch (NoAlertPresentException e) {
            return false;
        }
    }

    private String closeAlertAndGetItsText() {
        try {
            Alert alert = driver.switchTo().alert();
            String alertText = alert.getText();
            if (acceptNextAlert) {
                alert.accept();
            } else {
                alert.dismiss();
            }
            return alertText;
        } finally {
            acceptNextAlert = true;
        }
    }
}

0 个答案:

没有答案