java.lang.AssertionError: Test Failed ожидаемый [200], но найденный [302] ожидаемый: 200 фактический: 302
Я получаю ошибку перенаправления / выхожу из новой вкладки
WelcomePage welcomePage = psloginPage.clickLogInButton ();
ExaminationReportsPage examinationReportsPage = welcomePage.clickReportsTab();
examinationReportsPage.reportDropDown("Portion Pass Rate (First Time) Cumulative");
examinationReportsPage.startDateDropDown("01 - January", "02", "2017");
examinationReportsPage.endDateDropDown("01 - January", "08", "2017");
String currentPageHandle = driver.getWindowHandle();
Set<Cookie> cookiesInstance1 = driver.manage().getCookies();
examinationReportsPage.clickSubmitButton();
ArrayList<String> tabHandles = new ArrayList<String>(driver.getWindowHandles());
for (String tab : tabHandles) {
if (!tab.equals(currentPageHandle)) {
driver.switchTo().window(tab);
Thread.sleep(5000);
String currentUrl = driver.getCurrentUrl();
try {
URL url = new URL(currentUrl);
try
{
for(Cookie cookie:cookiesInstance1)
{
System.err.println(cookie);
driver.manage().addCookie(cookie);
}
}
catch(Throwable e)
{
System.err.println("Error While setting Cookies: " + e.getMessage());
}
HttpURLConnection objhttpURLConnection = (HttpURLConnection) url.openConnection();
Map<String, List<String>> map = objhttpURLConnection.getHeaderFields();
objhttpURLConnection.setConnectTimeout(10000);
objhttpURLConnection.connect();
//String state=((JavascriptExecutor) driver).executeScript("return document.readyState").toString();
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
System.out.println("Key : " + entry.getKey()+ " ,Value : " + entry.getValue());
}
if (objhttpURLConnection.getResponseCode() != 200) {
System.out.println(currentUrl + " Error*-* +" + objhttpURLConnection.getResponseCode());
System.out.println(objhttpURLConnection.getResponseMessage());
Assert.assertEquals(objhttpURLConnection.getResponseCode(),200,"Test Failed");
}else
{
System.out.println(currentUrl + " Perfect*-* " + objhttpURLConnection.getResponseCode());
System.out.println(currentUrl + " *-* " + objhttpURLConnection.getResponseMessage());
Assert.assertEquals(objhttpURLConnection.getResponseCode(),200,"Test Pass");
}
} catch (Exception e) {
}
}
}
Выход из новой вкладки даже после добавления файлов cookie.