mirror of
https://dev.azure.com/Foster-X/CMP329%20CW2/_git/CMP329%20CW2
synced 2025-07-27 05:53:32 +00:00
Permission testing development
This commit is contained in:
parent
8c15eebf1f
commit
711baf98ab
1 changed files with 20 additions and 3 deletions
|
@ -2,12 +2,14 @@ package test;
|
|||
|
||||
import main.ConfigureDriver;
|
||||
import main.DomainGrabber;
|
||||
import org.openqa.selenium.NoSuchElementException;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.By;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvFileSource;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
public class TestPoster {
|
||||
private static final String domain = DomainGrabber.getDomain();
|
||||
|
@ -17,7 +19,7 @@ public class TestPoster {
|
|||
private static final String LOGIN_BUTTON_ID = "wp-submit";
|
||||
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 POST_URL = "https://"+domain+"/wp-admin/post-new.php";
|
||||
private static final String NEW_POST_URL = "https://"+domain+"/wp-admin/post-new.php";
|
||||
@ParameterizedTest
|
||||
@CsvFileSource(resources = "/csv/built/credentials_permissions.csv", numLinesToSkip = 0)
|
||||
|
||||
|
@ -39,9 +41,24 @@ public class TestPoster {
|
|||
boolean canPost;
|
||||
if (role.equals("author")) {
|
||||
canPost = true;
|
||||
} else {
|
||||
canPost = false;
|
||||
}
|
||||
boolean postAccessible = true;
|
||||
try {
|
||||
WebElement post_button = driver.findElement(By.id(POST_BUTTON_ID));
|
||||
post_button.click();
|
||||
} catch(NoSuchElementException e) {
|
||||
postAccessible = false;
|
||||
}
|
||||
if (canPost) {
|
||||
assertTrue(driver.getCurrentUrl().startsWith(NEW_POST_URL));
|
||||
}
|
||||
else {
|
||||
assertTrue(postAccessible == false);
|
||||
assertFalse(driver.getCurrentUrl().startsWith(NEW_POST_URL));
|
||||
}
|
||||
|
||||
}
|
||||
//driver.quit();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue