1、创建Maven工程:
2、解析模型,根据路径生成工具生成测试用例;
3、以上2个步骤参考:http://graphwalker.github.io/Tests_execution/,例子给的模型时基于UI的,所以工程需要集成UI自动化框架,这里以selenium举例;
红色的框中定义了登录页面、首页、修改密码页面,以及对应业务逻辑;
@GraphWalker(value ="random(edge_coverage(100))", start ="e_Init")
@Listeners({ScreenShotListener.class, ExtentTestNGIReporterListener1.class})
public class TestMallPcLoginImpl
extends ExecutionContextimplements MallPcLogin1 {
public final static PathMODEL_PATH = Paths.get("org/myorg/testautomation/MallPcLogin1.graphml");
public static WebDriverwebDriver = Util.driver;
public static StringmallPcLoginUrl ="http://" + CommonUtil.UCENTER_GROUP +"-mall.hipac.cn/mall/view/login/login.html";
private HomeServicehomeService;
private LoginServiceloginService;
private ModifyPwdServicemodifyPwdService;
public Stringusername="11111111111";
public StringoriginPwd="hipac228";
public Stringusernickname="81823962";
public StringcurrentPwd=originPwd;
public StringnewPwd=currentPwd+"1";
@BeforeClass
public void setup() {
homeService =new HomeService(webDriver);
loginService =new LoginService(webDriver);
modifyPwdService=new ModifyPwdService(webDriver);
}
@Override
public void v_ClientNotRunning() {
System.out.println("v_ClientNotRunning--start");
System.out.println("v_ClientNotRunning--end");
}
@Override
public void e_ValidPremiumCredentials() {
System.out.println("e_ValidPremiumCredentials");
System.out.println("loginService==null->" +loginService ==null);
System.out.println("webDriver.getCurrentUrl():"+webDriver.getCurrentUrl());
loginService=new LoginService(webDriver);
//登录XX门店
loginService.passwordLogin(username,currentPwd, "1");
System.out.println("e_ValidPremiumCredentials--end");
}
@Override
public void v_Browse() {
System.out.println("v_Browse--start");
homeService=new HomeService(webDriver);
//基础信息
homeService.enterBaseInfo();
System.out.println("v_Browse--end");
}
@Override
public void e_Logout() {
System.out.println("e_Logout--start");
//退出登录
homeService.loginOut();
System.out.println("e_Logout--end");
}
@Override
public void v_LoginPrompted() {
System.out.println("v_LoginPrompted--start--");
String currentUrl =webDriver.getCurrentUrl();
System.out.println("v_LoginPrompted--currentUrl:" + currentUrl);
Assert.assertTrue(currentUrl.contains("login"), "当前页面还在登录页面");
System.out.println("v_LoginPrompted--end--");
}
@Override
public void e_StartClient() {
System.out.println("e_StartClient--start--");
System.out.println("webDriver==null:" + (webDriver ==null));
webDriver =new ChromeDriver();
//打开测试环境海拍客门店地址
webDriver.get(mallPcLoginUrl);
System.out.println("e_StartClient--end--");
}
@Override
public void e_Close() {
System.out.println("e_Close--start--");
webDriver.quit();
System.out.println(" e_Close:webDriver.close();");
System.out.println("e_Close--end--");
}
@Override
public void e_Init() {
System.out.println("e_Init--start--");
System.out.println("e_Init--end--");
}
@Override
public void e_Exit() {
System.out.println("e_Exit--start--");
webDriver.quit();
System.out.println(" e_Exit: webDriver.close();");
System.out.println("e_Exit--end--");
}
@Override
public void e_modifyPwd() {
System.out.println("e_modifyPwd--start--");
homeService.modifyPwd();
System.out.println("homeService.modifyPwd()-done");
System.out.println("currentPwd:"+currentPwd);
System.out.println("newPwd:"+newPwd);
try {
Thread.sleep(5*1000);
}catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("sleep-done");
//由于会跳转,所有需要重新获取一次页面
modifyPwdService=new ModifyPwdService(webDriver);
newPwd=currentPwd+"1";
modifyPwdService.modifyPwd(currentPwd,newPwd,newPwd);
System.out.println("e_modifyPwd--end--");
try {
Thread.sleep(5*1000);
}catch (InterruptedException e) {
e.printStackTrace();
}
currentPwd=newPwd;
}
@Override
public void e_InvalidCredentials() {
System.out.println("e_InvalidCredentials--start--");
loginService=new LoginService(webDriver);
//登录海拍客门店-非法
loginService.passwordLogin(username, currentPwd+"1", "1");
System.out.println("e_InvalidCredentials--end--");
}
@AfterClass
public void teardown() {
System.out.println("最新的密码是"+currentPwd);
webDriver.quit();
}
@Test
public void runFunctionalTest() {
new TestBuilder()
.setModel(MODEL_PATH)
.setContext(new TestMallPcLoginImpl())
.setPathGenerator(new RandomPath(new EdgeCoverage(100)))
.setStart("e_Init")
.execute();
}
}
运行的结果:日志中会把运行的边和顶点打印出来
目前有2个比较重要的问题未解决:
(1)工具生成的测试用例路径会比较多,如何在测试报告中展示?
(2)如何把错误信息展示给测试人员更方便的去定位?
网友评论