Bot Style Tests

Although PageObjects are a useful way of reducing duplication in your tests, it's not always a pattern that teams feel comfortable following. An alternative approach is to follow a more "command-like" style of testing.

 Example:

A "bot" is an action-oriented abstraction over the raw Selenium APIs. This means that if you find that commands aren't doing the Right Thing for your app, it's easy to change them. As an example: 
public class ActionBot {
private final WebDriver driver;

public ActionBot(WebDriver driver) {
this.driver = driver;
}

public void click(By locator) {
driver.findElement(locator).click();
}

public void submit(By locator) {
driver.findElement(locator).submit();
}

/** 
* Type something into an input field. WebDriver doesn't normally clear these
* before typing, so this method does that first. It also sends a return key
* to move the focus out of the element.
*/
public void type(By locator, String text) { 
WebElement element = driver.findElement(locator);
element.clear();
element.sendKeys(text + "\n");
}
}


Once these abstractions have been built and duplication in your tests identified, it's possible to layer PageObjects on top of bots.

转载于:https://my.oschina.net/hcp/blog/55860

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值