Updated TestPoster to now test posting functionality

This commit is contained in:
Xander 2025-04-05 02:47:30 +01:00
parent 711baf98ab
commit 7ba185d387

View file

@ -16,10 +16,16 @@ public class TestPoster {
private static final String LOGIN_PAGE = "https://"+domain+"/wp-login.php"; private static final String LOGIN_PAGE = "https://"+domain+"/wp-login.php";
private static final String USERNAME_BOX_ID = "user_login"; private static final String USERNAME_BOX_ID = "user_login";
private static final String PASSWORD_BOX_ID = "user_pass"; private static final String PASSWORD_BOX_ID = "user_pass";
private static final String POST_TITLE_ID = "title";
private static final String POST_CONTENT_ID = "content";
private static final String LOGIN_BUTTON_ID = "wp-submit"; private static final String LOGIN_BUTTON_ID = "wp-submit";
private static final String POST_BUTTON_NAV_ID = "wp-admin-bar-new-content";
private static final String POST_EDITOR_SWITCH_ID = "content-html";
private static final String PUBLISH_BUTTON_ID = "publish";
private static final String LOGGGEDIN_URL = "https://"+domain+"/wp-admin/"; private static final String LOGGGEDIN_URL = "https://"+domain+"/wp-admin/";
private static final String POST_BUTTON_ID = "wp-admin-bar-new-content";
private static final String NEW_POST_URL = "https://"+domain+"/wp-admin/post-new.php"; private static final String NEW_POST_URL = "https://"+domain+"/wp-admin/post-new.php";
private static final String POST_CONTENT_TEXT = "Lorem ipsum dolor amet";
private static final String POST_TITLE_TEXT = "Lipsum 4 u";
@ParameterizedTest @ParameterizedTest
@CsvFileSource(resources = "/csv/built/credentials_permissions.csv", numLinesToSkip = 0) @CsvFileSource(resources = "/csv/built/credentials_permissions.csv", numLinesToSkip = 0)
@ -33,7 +39,7 @@ public class TestPoster {
WebElement login = driver.findElement(By.id(LOGIN_BUTTON_ID)); WebElement login = driver.findElement(By.id(LOGIN_BUTTON_ID));
username.sendKeys(usernameText); username.sendKeys(usernameText);
System.out.println("Testing "+usernameText); System.out.println("Testing " + usernameText);
password.sendKeys(passwordText); password.sendKeys(passwordText);
login.click(); login.click();
@ -46,19 +52,28 @@ public class TestPoster {
} }
boolean postAccessible = true; boolean postAccessible = true;
try { try {
WebElement post_button = driver.findElement(By.id(POST_BUTTON_ID)); WebElement post_button = driver.findElement(By.id(POST_BUTTON_NAV_ID));
post_button.click(); post_button.click();
} catch(NoSuchElementException e) { } catch (NoSuchElementException e) {
System.out.println("Post inaccessible!");
postAccessible = false; postAccessible = false;
} }
if (canPost) { if (canPost) { //if there's permission to post, carry on
assertTrue(driver.getCurrentUrl().startsWith(NEW_POST_URL)); assertTrue(driver.getCurrentUrl().startsWith(NEW_POST_URL));
} WebElement title = driver.findElement(By.id(POST_TITLE_ID));
else { WebElement content = driver.findElement(By.id(POST_CONTENT_ID));
WebElement textSwitch = driver.findElement(By.id(POST_EDITOR_SWITCH_ID));
WebElement publishButton = driver.findElement(By.id(PUBLISH_BUTTON_ID));
textSwitch.click();
title.sendKeys(POST_TITLE_TEXT);
content.sendKeys(POST_CONTENT_TEXT);
publishButton.click();
} else { //if there's no permission to post
assertTrue(postAccessible == false); assertTrue(postAccessible == false);
assertFalse(driver.getCurrentUrl().startsWith(NEW_POST_URL)); assertFalse(driver.getCurrentUrl().startsWith(NEW_POST_URL));
} }
//driver.quit();
} }
//driver.quit();
} }