//植入cookie
public void setUserCookie(){
String value = “M0OWNiNDA4NTRlNmYxYzVkZjkzZjI4OTE2M2E0NDMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAODI2OTgwNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4NDYzMTYxNDhAcXEuY29tAAAAAAAAAAAAAAAAAAAAADkxNGVlMTZlM2RiMjNiYmE5Nzk5NmRhMmQ0ZmQ5MzBh62BQX5nELV8”;
driver.manage().deleteAllCookies();
Cookie cookie = new Cookie(“apsid”, value, “.imooc.com”, “/”, null);
driver.manage().addCookie(cookie);
}
@Parameters({“url”})
@Test
public void loginPayOrder(String url){//登录后确认订单
String submitTitle;
payOrderHandle.setUserCookie();
System.out.println(driver.manage().getCookies());
try {
Thread.sleep(2000);
}catch (Exception e){
e.printStackTrace();
}
//刷新页面
// driver.navigate().refresh();
try {
Thread.sleep(2000);
}catch (Exception e){
e.printStackTrace();
}
//跳转到确认订单页面
driver.get(url);
submitTitle = driver.getTitle();
boolean flag = submitTitle.contains(“确认订单_慕课网”);
Assert.assertEquals(flag, true);
payOrderHandle.clickSubmitOrderButton();
}
打印结果:
https://order.imooc.com/pay/confirm?goods_ids=2173
[apsid=M0OWNiNDA4NTRlNmYxYzVkZjkzZjI4OTE2M2E0NDMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAODI2OTgwNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4NDYzMTYxNDhAcXEuY29tAAAAAAAAAAAAAAAAAAAAADkxNGVlMTZlM2RiMjNiYmE5Nzk5NmRhMmQ0ZmQ5MzBh62BQX5nELV8; expires=星期三, 29 八月 2040 02:00:25 CST; path=/; domain=.imooc.com]
java.lang.AssertionError: expected [true] but found [false]
Expected :true
Actual :false
植入cookie后没有打开新的页面