尝试个人翻译selenium官方的测试设计模式篇,由于本人个人能力有限,翻译内容没有进行校对,还有很多晦涩难懂的地方,部分地方翻译出来强加了个人理解,所以本文仅供个人学习参考,文末有对应文档的官网链接可供参考。
selenium.click(elementLocator);
selenium.waitForPageToLoad(waitPeriod);
/**
* Clicks and Waits for page to load.
*
* param elementLocator
* param waitPeriod
*/
public void clickAndWait(String elementLocator, String waitPeriod) {
selenium.click(elementLocator);
selenium.waitForPageToLoad(waitPeriod);
}
/**
* Selenum-RC -- Clicks on an element only if it is available on a page.
*
* param elementLocator
*/
public void safeClick(String elementLocator) {
if(selenium.isElementPresent(elementLocator)) {
selenium.click(elementLocator);
} else {
// Using the TestNG API for logging
Reporter.log("Element: " + elementLocator + ", is not available on a page - "
+selenium.getLocation());
}
}
/**
* Selenium-WebDriver -- Clicks on an element only if it is available on a page.
*
* param elementLocator
*/
public void safeClick(String elementLocator) {
WebElement webElement = getDriver().findElement(By.XXXX(elementLocator));
if(webElement != null) {
selenium.click(webElement);
} else {
// Using the TestNG API for logging
Reporter.log("Element: " + elementLocator + ", is not available on a page - "
+ getDriver().getUrl());
}
}
public void testNew() throws Exception {
selenium.open("http://www.test.com");
selenium.type("loginForm:tbUsername", "xxxxxxxx");
selenium.click("loginForm:btnLogin");
selenium.click("adminHomeForm:_activitynew");
selenium.waitForPageToLoad("30000");
selenium.click("addEditEventForm:_IDcancel");
selenium.waitForPageToLoad("30000");
selenium.click("adminHomeForm:_activityold");
selenium.waitForPageToLoad("30000");
}
public void testNew() throws Exception {
selenium.open("http://www.test.com");
selenium.type(admin.username, "xxxxxxxx");
selenium.click(admin.loginbutton);
selenium.click(admin.events.createnewevent);
selenium.waitForPageToLoad("30000");
selenium.click(admin.events.cancel);
selenium.waitForPageToLoad("30000");
selenium.click(admin.events.viewoldevents);
selenium.waitForPageToLoad("30000");
}
public void testNew() throws Exception {
// Open app url.
selenium.open("http://www.test.com");
// Provide admin username.
selenium.type(admin.username, "xxxxxxxx");
// Click on Login button.
selenium.click(admin.loginbutton);
// Click on Create New Event button.
selenium.click(admin.events.createnewevent);
selenium.waitForPageToLoad("30000");
// Click on Cancel button.
selenium.click(admin.events.cancel);
selenium.waitForPageToLoad("30000");
// Click on View Old Events button.
selenium.click(admin.events.viewoldevents);
selenium.waitForPageToLoad("30000");
}
admin.username = loginForm:tbUsername
admin.loginbutton = loginForm:btnLogin
admin.events.createnewevent = adminHomeForm:_activitynew
admin.events.cancel = addEditEventForm:_IDcancel
admin.events.viewoldevents = adminHomeForm:_activityold
原文地址:测试设计注意事项
上一节:
selenium自动化测试设计模式原文翻译(二)
下一节: