mirror of
https://dev.azure.com/Foster-X/CMP329%20CW2/_git/CMP329%20CW2
synced 2025-07-27 06:03:32 +00:00
Updated TestPoster to now test posting functionality
This commit is contained in:
parent
711baf98ab
commit
7ba185d387
1 changed files with 24 additions and 9 deletions
|
@ -16,10 +16,16 @@ public class TestPoster {
|
|||
private static final String LOGIN_PAGE = "https://"+domain+"/wp-login.php";
|
||||
private static final String USERNAME_BOX_ID = "user_login";
|
||||
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 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 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 POST_CONTENT_TEXT = "Lorem ipsum dolor amet";
|
||||
private static final String POST_TITLE_TEXT = "Lipsum 4 u";
|
||||
@ParameterizedTest
|
||||
@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));
|
||||
|
||||
username.sendKeys(usernameText);
|
||||
System.out.println("Testing "+usernameText);
|
||||
System.out.println("Testing " + usernameText);
|
||||
password.sendKeys(passwordText);
|
||||
login.click();
|
||||
|
||||
|
@ -46,19 +52,28 @@ public class TestPoster {
|
|||
}
|
||||
boolean postAccessible = true;
|
||||
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();
|
||||
} catch(NoSuchElementException e) {
|
||||
} catch (NoSuchElementException e) {
|
||||
System.out.println("Post inaccessible!");
|
||||
postAccessible = false;
|
||||
}
|
||||
if (canPost) {
|
||||
if (canPost) { //if there's permission to post, carry on
|
||||
assertTrue(driver.getCurrentUrl().startsWith(NEW_POST_URL));
|
||||
}
|
||||
else {
|
||||
WebElement title = driver.findElement(By.id(POST_TITLE_ID));
|
||||
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);
|
||||
assertFalse(driver.getCurrentUrl().startsWith(NEW_POST_URL));
|
||||
}
|
||||
|
||||
}
|
||||
//driver.quit();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue