Permission testing development

This commit is contained in:
Xander 2025-04-04 16:15:37 +01:00
parent 8c15eebf1f
commit 711baf98ab

View file

@ -2,12 +2,14 @@ package test;
import main.ConfigureDriver; import main.ConfigureDriver;
import main.DomainGrabber; import main.DomainGrabber;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource; import org.junit.jupiter.params.provider.CsvFileSource;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
public class TestPoster { public class TestPoster {
private static final String domain = DomainGrabber.getDomain(); 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 LOGIN_BUTTON_ID = "wp-submit";
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 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 @ParameterizedTest
@CsvFileSource(resources = "/csv/built/credentials_permissions.csv", numLinesToSkip = 0) @CsvFileSource(resources = "/csv/built/credentials_permissions.csv", numLinesToSkip = 0)
@ -39,9 +41,24 @@ public class TestPoster {
boolean canPost; boolean canPost;
if (role.equals("author")) { if (role.equals("author")) {
canPost = true; canPost = true;
} else {
canPost = false;
} }
boolean postAccessible = true;
try {
WebElement post_button = driver.findElement(By.id(POST_BUTTON_ID)); 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(); //driver.quit();
}
} }