封装selenium之三

来源:互联网 发布:林心如黑历史 知乎 编辑:程序博客网 时间:2024/05/17 06:28

第三种叫做UI Mapping方式

在编写脚本时可能出现这样的脚本

public void testNew() throws Exception {
driver.open("http://www.test.com");


driver.type("loginForm:tbUsername", "xxxxxxxx");
driver.click("loginForm:btnLogin");


driver.click("adminHomeForm:_activitynew");
driver.waitForPageToLoad("30000");


driver.click("addEditEventForm:_IDcancel");
driver.waitForPageToLoad("30000");


driver.click("adminHomeForm:_activityold");
driver.waitForPageToLoad("30000");
}

是不是看起来很乱,还是已经按照对元素的操作进行分隔之后的样子。将没有学过seleniumAPI会觉得难以理解的部分替换掉:

public void testNew() throws Exception {

driver.open("http://www.test.com");


driver.type(admin.username, "xxxxxxxx");

driver.click(admin.loginbutton);


driver.click(admin.events.createnewevent);

driver.waitForPageToLoad("30000");


driver.click(admin.events.cancel);

driver.waitForPageToLoad("30000");


driver.click(admin.events.viewoldevents);
driver.waitForPageToLoad("30000");

}

The locators will still refer to HTML objects, but we have introduced a layer of abstraction between the test script and the UI elements. Values are read from the properties file and used in the Test Class to implement the UI Map. 

之后需要建立properties文件,然后将你的变量与实际的元素位置相对应,实现变量与元素的相对应,通过解析配置文件,将元素值传入对应的方法中。

0 0
原创粉丝点击