0

我想准备测试,其中 selenium 必须从 excel 文件中读取数据(用户名和密码)并将它们输入到登录字段。

我正在使用带有 selenium 2.0 的 thucydides 框架。

我该怎么做?

谢谢你。

4

2 回答 2

2

“优秀”是必需品吗?

您始终可以将 excel 文件转换为 CSV 格式(另存为...),然后修昔底德可以按照此处所述使用它

测试数据:

NAME,AGE,PLACE OF BIRTH
Jack Smith, 30, Smithville
Joe Brown, 40, Brownville
Mary Williams, 20, Williamsville

代码:

 @RunWith(ThucydidesParameterizedRunner.class)
    @UseTestDataFrom("test-data/simple-data.csv")
    public class SampleCSVDataDrivenScenario {

        private String name;
        private String age;
        private String placeOfBirth;

        public SampleCSVDataDrivenScenario() {
        }

        @Qualifier
        public String getQualifier() {
            return name;
        }

        @Managed
        public WebDriver webdriver;

        @ManagedPages(defaultUrl = "http://www.google.com")
        public Pages pages;

        @Steps
        public SampleScenarioSteps steps;

        @Test
        public void data_driven_test() {
            System.out.println(getName() + "/" + getAge() + "/" + getCity());
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getAge() {
            return age;
        }

        public void setAge(String age) {
            this.age = age;
        }

        public String getPlaceOfBirth() {
            return placeOfBirth;
        }

        public void setPlaceOfBirth(String placeOfBirth) {
            this.placeOfBirth = placeOfBirth;
        }
    }
于 2013-06-06T13:59:30.807 回答
0
Use testNG data provider or use property file 

testNG example

@DataProvider(name = "testData")
    public Object[][] testData() throws Exception {

        Object[][] results;
        ArrayList<Object[]> resultArray = new ArrayList<Object[]>();
        resultArray.add(new Object[] { "Test1" });
                resultArray.add(new Object[] { "Test2" });
        results = resultArray.toArray(new Object[resultArray.size()][]);
        return results;
    }


    @Test( dataProvider = "testData")

    public static void main(String testName) {

        System.out.println(testName);

    }

Result :
Test1
Test2

在您的情况下,您可以添加所需的任何用户名和密码并运行相同的测试

于 2013-06-19T13:45:31.820 回答