现有框架的设计方式如下。我们在VerifyAttributes中Assert一些检查。问题是,我想将Assert更改为软Assert,以便测试不会在单个Assert失败时停止,并且测试继续。如何使用单个软Assert对象进行所有检查?我可以在测试中的父类中创建一个软Assert,并在调用方法时将其作为属性传递吗?
public class TestClass extends BaseTest {
@Test(description="test to verify if the keyboard and mouse attributes are generated)
public void testKeyboardMouseAttributes(String os, String browser, String device){
//User performs some keyboard and mouse actions
InterfaceToVerifyAttributes verifyAttr = new InterfaceToVerifyAttributes("testKeyboardMouseAttributes",os,browser,device);
verifyAttr.keyboardAttributes();
}
}
public class InterfaceToVerifyAttributes {
private String os, browser, device, testcase;
public InterfaceToVerifyAttributes(String tc, String os, String browser, String device) {
this.os = os;
this.browser = browser;
this.device = device;
this.testcase=tc;
}
public void keyboardAttributes(){
VerifyAttributes verifyAttr = new VerifyAttributes(testcase, os, browser, device);
verifyAttr.verifyUnknownSession(false);
verifyAttr.keyboardAttributes();
}}
public class VerifyAttributes{
private String os, browser, device, orgId;
//getters and setters
public void verifyUnknownSession(boolean expected) {
Assert.assertNotNull(api.getSpecifiedParameter("unknown_session"),
" ** should be unknown session ** " + testcase + " " + os + " " + browser + " org_id " + orgId);
}
public void verifyKeyboardPageElements() {
Assert.assertNotNull(//attribute is present);
Assert.assertTrue(//attribute value is equal to something);
//A few other assertions
}
public void verifyMouseElements() {
Assert.assertNotNull(//attribute is present);
Assert.assertTrue(//attribute value is equal to something);
//A few other assertions
}
public void verifyPasswordType() { //This method is not used but is present
Assert.assertNotNull(//attribute is present);
Assert.assertTrue(//attribute value is equal to something);
//A few other assertions
}
}
1条答案
按热度按时间ldfqzlk81#
我能够做到这一点