I used the Selenium IDE to record a test case. The goal was to assert the correctness of the static text on a page. I exported the test case as Java / JUnit 4 / WebDriver and the code looked like this.
assertEquals("Please select the ratings year and file type for the data that you are attempting to upload. \n\n Ratings Year: The year in which the data was submitted/collected.", driver.findElement(By.cssSelector("p")).getText());
I edited the format of the code a bit to match how the rest of the case is coded:
// Expected text for each part of the reporting year page
String rMainHeading = "Upload Data Files";
String rHeading = "Select Ratings Year and File Type for Clinical Measures Data";
String rBody1 = "Please select the ratings year and file type for the data that you are attempting to upload. \n\n Ratings Year: The year in which the data was submitted/collected.";
// Reporting year page text locations
WebElement reportingMainH = driver.findElement(By.cssSelector("h1"));
WebElement reportingHeader = driver.findElement(By.cssSelector("h2"));
WebElement reportingBody1 = driver.findElement(By.cssSelector("p"));
System.out.println("stopA");
// Checking the Reporting Year page text is displayed as expected
try {
assertEquals ((reportingMainH.getText()),rMainHeading);
assertEquals ((reportingHeader.getText()),rHeading);
System.out.println("stop1");
assertEquals ((reportingBody1.getText()),rBody1);
System.out.println("stop2");
WebElement reportingWords = driver.findElement(By.id("submissionForm"));
String reportingYearText = reportingWords.getText();
System.out.println("4) The static text on the Reporting Year page has been confirmed.");
//System.out.println(reportingYearText);
setupScript.screenshot(driver);
}
catch (Exception e) {
System.out.println("*******The text on the page does not match the expect results of XXX-1938. This case has failed.");
}
The test case is failing after "stop1" so the I'm not sure how to make this string assertion work. I tried using a String.join, but that also failed. Here is what the element looks likes upon inspection.
How can I deal with the \n to assert this text correctly?
reportingBody1.getText()and copy and paste it to the variablerbody1