首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在java、selenium测试中读取excel数据?

如何在java、selenium测试中读取excel数据?
EN

Stack Overflow用户
提问于 2013-01-07 13:44:28
回答 5查看 15.9K关注 0票数 1

我用java编写了selenium webdriver支持的代码,用于测试web应用程序。我的代码如下:

代码语言:javascript
复制
package testcases;

import com.thoughtworks.selenium.Selenium;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.regex.Pattern;

public class Untitled {
private Selenium selenium;

@Before
public void setUp() throws Exception {
        WebDriver driver = new FirefoxDriver();
        String baseUrl = "http://www.himalayanpalmistry.com/";
        selenium = new WebDriverBackedSelenium(driver, baseUrl);
}

@Test
public void testUntitled() throws Exception {
        selenium.open("/mabiz/");
        selenium.select("id=register_type", "label=für Unternehmen");
        selenium.click("id=rgst");
        selenium.waitForPageToLoad("30000");
        selenium.type("id=username", "javatesting1");
        selenium.type("id=password", "12345678");
        selenium.type("id=confirm_password", "12345678");
        selenium.type("id=name", "java testing");
        selenium.type("id=position", "java testing");
        selenium.type("id=company", "java testing");
        selenium.type("id=address", "java testing");
        selenium.type("id=zipcode", "12345");
        selenium.type("id=city", "safdj");
        selenium.type("id=phone", "kfajs");
        selenium.type("id=email", "tsandesh23@hotmail.com");
        selenium.click("id=show_contact_info");
        selenium.click("id=product_select3");
        selenium.click("id=term_condition1");
        selenium.click("name=submit_one");
        selenium.waitForPageToLoad("30000");
}

@After
public void tearDown() throws Exception {
        selenium.stop();
}
}

我想修改这段代码来读取微软的excel数据,并用这段代码做很多测试。我的excel文件包含各种测试数据。提前感谢!!

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2013-01-07 19:44:22

您可以使用此接口从http://www.andykhan.com/jexcelapi/tutorial.htmlhttp://jexcelapi.sourceforge.net/中读取excel行该教程非常棒,可以在以下位置找到:java

另外,在脚本中发布用户名和密码到stackoverflow时也要小心;)

票数 1
EN

Stack Overflow用户

发布于 2013-01-07 13:53:48

您可以使用Apache POI访问Excel http://poi.apache.org/spreadsheet/index.html

票数 0
EN

Stack Overflow用户

发布于 2013-01-07 13:59:02

java中有许多API可用于从Excel读取数据。

  1. JExcelApi.
  2. POI

解决的问题

将Excel另存为CSV文件(以防您不想使用任何外部API),并将其作为文本文件正常读取。但是使用逗号作为分隔符。

有关更多信息,请查看此链接:How to read and write excel file in java

我希望这能有所帮助:-)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14190556

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档