From 711baf98ab22d9a25676f376d8c5ce231107b6b0 Mon Sep 17 00:00:00 2001 From: xander Date: Fri, 4 Apr 2025 16:15:37 +0100 Subject: [PATCH] Permission testing development --- src/test/TestPoster.java | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/test/TestPoster.java b/src/test/TestPoster.java index f4dcecf..c68592e 100644 --- a/src/test/TestPoster.java +++ b/src/test/TestPoster.java @@ -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; } - WebElement post_button = driver.findElement(By.id(POST_BUTTON_ID)); + boolean postAccessible = true; + try { + WebElement post_button = driver.findElement(By.id(POST_BUTTON_ID)); + post_button.click(); + } catch(NoSuchElementException e) { + postAccessible = false; } - //driver.quit(); + if (canPost) { + assertTrue(driver.getCurrentUrl().startsWith(NEW_POST_URL)); + } + else { + assertTrue(postAccessible == false); + assertFalse(driver.getCurrentUrl().startsWith(NEW_POST_URL)); + } + } + //driver.quit(); } \ No newline at end of file