Rebonjour,
Voici le code qui a su extraire le message d'erreur :
Le System.out.println("@AFTER AAAAA sTEXTEALERT=[" + sTEXTEALERT + "]"); renvoit bien dans la console Eclipse/Oxygen :
@AFTER AAAAA sTEXTEALERT=[Informations d'identification fournies non valides]
Mais, le rapport SQUASH dit toujours qu'il ne voit pas d'erreur fonctionnelle (failures ou errors).
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxProfile;
import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class C_RATP_MDP_KO {
private FirefoxBinary binary = new FirefoxBinary(new File("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"));
private FirefoxProfile profile = new FirefoxProfile();
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver(binary,profile);
baseUrl = "
https://monsite:8183/login";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void Logintest() throws Exception {
// String expectedStr = "Informations d'identification fournies non valides";
String expectedStr = "@TEST XXXXXX_MESSAGE_D_ERREUR_BIDON_XXXXX";
System.out.println("@TEST AAAA DEBUT AAAA");
System.out.println("@TEST AAAAA expectedStr=[" + expectedStr + "]");
// log.info("XXXX");
driver.get(baseUrl);
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys("ANAIS");
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("bidon$");
driver.findElement(By.id("submitButton")).click();
driver.findElement(By.name("submit")).click();
WebElement wm_element=driver.findElement(By.className("alert-danger"));
String sTEXTEALERT=wm_element.getText();
System.out.println("@TEST AAAAA sTEXTEALERT=[" + sTEXTEALERT + "]");
assertEquals(expectedStr,sTEXTEALERT);
// Assert.assertTrue(wm_element.contains(expectedStr));
}
@After
public void tearDown() throws Exception {
// String expectedStr = "Informations d'identification fournies non valides";
String expectedStr = "XXXAFTERXXX_MESSAGE_D_ERREUR_BIDON_XXXXX";
System.out.println("@AFTER XXXXX DEBUT AAAA");
System.out.println("@AFTER XXXXX expectedStr=[" + expectedStr + "]");
WebElement wm_element=driver.findElement(By.className("alert-danger"));
String sTEXTEALERT=wm_element.getText();
System.out.println("@AFTER AAAAA sTEXTEALERT=[" + sTEXTEALERT + "]");
assertEquals(expectedStr,sTEXTEALERT);
// Assert.assertTrue(wm_element.contains(expectedStr));
driver.quit();
System.out.println("@AFTER XXXAXX FIN AAAA");
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}