如何在Java,硒测试中读取Excel数据? [英] How to read excel data in java, selenium testing?
问题描述
我在Java中有一个由硒Web驱动程序支持的代码,用于测试Web应用程序.我的代码如下:
I have a selenium webdriver backed code in java for testing an web application. My code is given below:
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();
}
}
我想修改此代码以读取Microsoft excel数据,并通过此代码进行许多测试.我的excel文件包含各种测试数据.提前感谢!
I want to modify this code for reading microsoft excel data and do many tests by this code. My excel file contains various test data. Thanx in advance!!
推荐答案
您可以使用此api从Java读取excel行: http://jexcelapi.sourceforge.net/ 该教程很棒,可以在这里找到: http://www.andykhan.com/jexcelapi/tutorial .html
You can use this api to read excel rows from java: http://jexcelapi.sourceforge.net/ The tutorial is great and can be found here: http://www.andykhan.com/jexcelapi/tutorial.html
此外,请注意将脚本中的用户名和密码发布到stackoverflow上;)
Also, be careful about posting usernames and passwords in your scripts to stackoverflow ;)
这篇关于如何在Java,硒测试中读取Excel数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!