From c25bc0eeecc80ff607f1e728834b39ebef2cc97a Mon Sep 17 00:00:00 2001 From: Adi Onofrei <adrian.onofrei@thinslices.com> Date: Tue, 18 Sep 2018 17:12:44 +0300 Subject: [PATCH] test(Automation): Submit manuscript --- Automation/src/test/java/Constants.java | 26 ++- Automation/src/test/java/CreateAccounts.java | 179 +++++++++++++++++++ Automation/src/test/java/CreateAuthor.java | 104 ----------- Automation/src/test/java/ManuscriptFlow.java | 155 ++++++++++++++++ Automation/src/test/java/Utils.java | 7 + 5 files changed, 363 insertions(+), 108 deletions(-) create mode 100644 Automation/src/test/java/CreateAccounts.java delete mode 100644 Automation/src/test/java/CreateAuthor.java create mode 100644 Automation/src/test/java/ManuscriptFlow.java diff --git a/Automation/src/test/java/Constants.java b/Automation/src/test/java/Constants.java index efd77bf67..eb6c8404b 100644 --- a/Automation/src/test/java/Constants.java +++ b/Automation/src/test/java/Constants.java @@ -1,11 +1,29 @@ +import org.apache.commons.lang3.RandomStringUtils; + public class Constants { - public static final String URL = "http://ec2co-ecsel-m3gy9h288kzs-2054883442.eu-west-1.elb.amazonaws.com/"; + public static final String URL = "http://qa.review.hindawi.com"; public static final String email = "adrian.onofrei+"; - public static final String firstname = "Test FN"; - public static final String lastname = "test LN"; + public static final String firstname = "Test Author"; + public static final String lastname = "Test Author"; public static final String affiliation = "TS affiliation"; - public static final String password = "Testing123"; + public static final String password = "password"; public static final String adminEmail = "admin"; public static final String adminPass = "password"; + public static final String randomStr = RandomStringUtils.randomAlphabetic(4); + public static final String firstnameHE = "Test HE"; + public static final String lastnameHE = "Test HE"; + public static final String passwordHE = "Testing123"; + public static final String emailHE = "adrian.onofrei+HE"; + public static final String affiliationHE = "TS HE affiliation"; + public static final String manusName = RandomStringUtils.randomAlphabetic(16); + public static final String manusAbstract = RandomStringUtils.randomAlphabetic(16); + public static final String fileManuscript = "/Users/adionofrei/Documents/Manuscript.pdf"; + public static final String fileSupplementary = "/Users/adionofrei/Documents/Manuscript.pdf"; + public static final String fileCoverLetter = "/Users/adionofrei/Documents/Manuscript.pdf"; + + + public static String uidAuth = null; + public static String uidHE = null; + } diff --git a/Automation/src/test/java/CreateAccounts.java b/Automation/src/test/java/CreateAccounts.java new file mode 100644 index 000000000..a8b5fca1f --- /dev/null +++ b/Automation/src/test/java/CreateAccounts.java @@ -0,0 +1,179 @@ +import io.restassured.path.json.JsonPath; +import org.junit.*; +import org.openqa.selenium.*; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import static org.junit.Assert.*; +import io.restassured.RestAssured; +import io.restassured.response.Response; +import io.restassured.specification.RequestSpecification; +import org.json.simple.JSONObject; +import java.net.URL; + + +public class CreateAccounts { + + private static WebDriver driver = null; + private static WebDriverWait wait = null; + public String URL = Constants.URL; + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + //driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.firefox()); + driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.chrome()); + //driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); + wait = new WebDriverWait(driver, 10); + String window = driver.getWindowHandle(); + ((JavascriptExecutor) driver).executeScript("alert('Test')"); + driver.switchTo().alert().accept(); + driver.switchTo().window(window); + Utils.disableWarning(); + } + + + @After + public void tearDown() { + driver.quit(); + } + + @Test + public void createNewAuthor() throws Exception { + + Utils.createAuthor(driver,wait, URL, Constants.randomStr, Constants.firstname, Constants.lastname, Constants.affiliation, Constants.email + Constants.randomStr + "@thinslices.com",Constants.password); + + + try { + wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("button[data-test='new-manuscript']"))); + } catch (NoSuchElementException e) { + System.out.println(e.toString()); + } + + WebElement element = driver.findElement(By.xpath("//*[@id=\"root\"]/div/div/div[1]/div[1]/div[2]/div/span[2]")); + String username = element.getText(); + + assertEquals(Constants.firstname+Constants.randomStr, username); + + RestAssured.baseURI = URL; + + //Get user token after login with new account + + RequestSpecification request = RestAssured.given().header("Content-Type", "application/json"); + + JSONObject requestParams = new JSONObject(); + requestParams.put("username", Constants.email + Constants.randomStr + "@thinslices.com"); + requestParams.put("password", Constants.password); + request.body(requestParams.toJSONString()); + Response response = request.post("api/users/authenticate"); + + JsonPath jsonPathEvaluator = response.body().jsonPath(); + String token = jsonPathEvaluator.get("token"); + + //Get user ID and confirmationToken + + RequestSpecification requestUid = RestAssured.given().header("Authorization", "Bearer " + token); + Response responseUid = requestUid.get("api/users/authenticate"); + JsonPath jsonPathEvaluatorUid = responseUid.body().jsonPath(); + + String confirmationToken = jsonPathEvaluatorUid.get("confirmationToken"); + + Constants.uidAuth = jsonPathEvaluatorUid.get("id"); + + //Activate user + + driver.get(URL + "confirm-signup?userId=" + Constants.uidAuth + "&confirmationToken=" + confirmationToken); + + try { + wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//button[contains(text(),'" + "Go to Dashboard" + "')]"))); + } catch (NoSuchElementException e) { + System.out.println(e.toString()); + } + + assertEquals("Your account has been successfully confirmed. Welcome to Hindawi!", driver.findElement(By.xpath("//*[@id=\"root\"]/div/div/div[2]/div/div")).getText()); + } + + @Test + public void createNewHE() throws Exception { + + Utils.createAuthor(driver,wait, URL, Constants.randomStr, Constants.firstnameHE, Constants.lastnameHE, Constants.affiliationHE, Constants.emailHE + Constants.randomStr + "@thinslices.com",Constants.passwordHE); + + + try { + wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("button[data-test='new-manuscript']"))); + } catch (NoSuchElementException e) { + System.out.println(e.toString()); + } + + WebElement element = driver.findElement(By.xpath("//*[@id=\"root\"]/div/div/div[1]/div[1]/div[2]/div/span[2]")); + String username = element.getText(); + + assertEquals(Constants.firstnameHE + Constants.randomStr, username); + + RestAssured.baseURI = URL; + + //Get user token after login with new account + + RequestSpecification request = RestAssured.given().header("Content-Type", "application/json"); + + JSONObject requestParams = new JSONObject(); + requestParams.put("username", Constants.emailHE + Constants.randomStr + "@thinslices.com"); + requestParams.put("password", Constants.passwordHE); + request.body(requestParams.toJSONString()); + Response response = request.post("api/users/authenticate"); + + JsonPath jsonPathEvaluator = response.body().jsonPath(); + String token = jsonPathEvaluator.get("token"); + + //Get user ID and confirmationToken + + RequestSpecification requestUid = RestAssured.given().header("Authorization", "Bearer " + token); + Response responseUid = requestUid.get("api/users/authenticate"); + JsonPath jsonPathEvaluatorUid = responseUid.body().jsonPath(); + + String confirmationToken = jsonPathEvaluatorUid.get("confirmationToken"); + Constants.uidHE = jsonPathEvaluatorUid.get("id"); + + //Activate user + + driver.get(URL + "confirm-signup?userId=" + Constants.uidHE + "&confirmationToken=" + confirmationToken); + + try { + wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//button[contains(text(),'" + "Go to Dashboard" + "')]"))); + } catch (NoSuchElementException e) { + System.out.println(e.toString()); + } + + assertEquals("Your account has been successfully confirmed. Welcome to Hindawi!", driver.findElement(By.xpath("//*[@id=\"root\"]/div/div/div[2]/div/div")).getText()); + + driver.get(URL+"login?next=/"); + Utils.validLogin( driver, wait, URL, Constants.adminEmail, Constants.adminPass); + driver.get(URL + "admin/users/edit/" + Constants.uidHE); + + try { + wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//button[contains(text(),'" + "Save user" + "')]"))); + } catch (NoSuchElementException e) { + System.out.println(e.toString()); + } + + driver.findElement(By.cssSelector("input[name=handlingEditor] + span")).click(); + driver.findElement(By.cssSelector("button[type=submit]")).click(); + + try { + wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("button[data-test='button-add-user']"))); + } catch (NoSuchElementException e) { + System.out.println(e.toString()); + } + + assertEquals(URL + "admin/users", driver.getCurrentUrl() ); + assertEquals(" Add User", driver.findElement(By.cssSelector("button[data-test='button-add-user']")).getText()); + } +} diff --git a/Automation/src/test/java/CreateAuthor.java b/Automation/src/test/java/CreateAuthor.java deleted file mode 100644 index 065b1e929..000000000 --- a/Automation/src/test/java/CreateAuthor.java +++ /dev/null @@ -1,104 +0,0 @@ -import io.restassured.path.json.JsonPath; -import org.apache.commons.lang3.RandomStringUtils; -import org.junit.*; -import org.openqa.selenium.*; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import static org.junit.Assert.*; -import io.restassured.RestAssured; -import io.restassured.response.Response; -import io.restassured.specification.RequestSpecification; -import org.json.simple.JSONObject; -import java.net.URL; - - -public class CreateAuthor { - - private static WebDriver driver = null; - private static WebDriverWait wait = null; - public String URL = Constants.URL; - - @BeforeClass - public static void setUpClass() throws Exception { - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - //driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.firefox()); - driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.chrome()); - //driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); - wait = new WebDriverWait(driver, 10); - String window = driver.getWindowHandle(); - ((JavascriptExecutor) driver).executeScript("alert('Test')"); - driver.switchTo().alert().accept(); - driver.switchTo().window(window); - Utils.disableWarning(); - } - - - @After - public void tearDown() { - driver.quit(); - } - - @Test - public void createNewAuthor() throws Exception { - - String s = RandomStringUtils.randomAlphabetic(8); - Utils.createAuthor(driver,wait, URL, s, Constants.firstname, Constants.lastname, Constants.affiliation, Constants.email+s+"@thinslices.com",Constants.password); - - - try { - wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("button[data-test='new-manuscript']"))); - } catch (NoSuchElementException e) { - System.out.println(e.toString()); - } - - WebElement element = driver.findElement(By.xpath("//*[@id=\"root\"]/div/div/div[1]/div[1]/div[2]/div/span[2]")); - String username = element.getText(); - - assertEquals(Constants.firstname+s, username); - - RestAssured.baseURI = URL; - - //Get user token after login with new account - - RequestSpecification request = RestAssured.given().header("Content-Type", "application/json"); - - JSONObject requestParams = new JSONObject(); - requestParams.put("username", Constants.email+s+"@thinslices.com"); - requestParams.put("password", Constants.password); - request.body(requestParams.toJSONString()); - Response response = request.post("api/users/authenticate"); - - JsonPath jsonPathEvaluator = response.body().jsonPath(); - String token = jsonPathEvaluator.get("token"); - - //Get user ID and confimationToken - - RequestSpecification requestUid = RestAssured.given().header("Authorization", "Bearer "+token); - Response responseUid = requestUid.get("api/users/authenticate"); - JsonPath jsonPathEvaluatorUid = responseUid.body().jsonPath(); - - String confirmationToken = jsonPathEvaluatorUid.get("confirmationToken"); - String uid = jsonPathEvaluatorUid.get("id"); - - //Activate user - - driver.get(URL+"confirm-signup?userId="+uid+"&confirmationToken="+confirmationToken); - - try { - wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//button[contains(text(),'"+"Go to Dashboard"+"')]"))); - } catch (NoSuchElementException e) { - System.out.println(e.toString()); - } - - assertEquals("Your account has been successfully confirmed. Welcome to Hindawi!", driver.findElement(By.xpath("//*[@id=\"root\"]/div/div/div[2]/div/div")).getText()); - } -} diff --git a/Automation/src/test/java/ManuscriptFlow.java b/Automation/src/test/java/ManuscriptFlow.java new file mode 100644 index 000000000..db5c49a81 --- /dev/null +++ b/Automation/src/test/java/ManuscriptFlow.java @@ -0,0 +1,155 @@ +import io.restassured.RestAssured; +import io.restassured.path.json.JsonPath; +import io.restassured.response.Response; +import io.restassured.specification.RequestSpecification; +import org.json.simple.JSONObject; +import org.junit.*; +import org.openqa.selenium.*; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.Select; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.net.URL; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class ManuscriptFlow { + private static WebDriver driver = null; + private static WebDriverWait wait = null; + public String URL = Constants.URL; + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + //driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.firefox()); + driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.chrome()); + //driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); + wait = new WebDriverWait(driver, 10); + String window = driver.getWindowHandle(); + ((JavascriptExecutor) driver).executeScript("alert('Test')"); + driver.switchTo().alert().accept(); + driver.switchTo().window(window); + } + + @After + public void tearDown() throws Exception { + //driver.quit(); + } + + @Test + public void manuscriptFlow() throws Exception { + /* Add constants.random after testing this function separably */ + Utils.validLogin( driver, wait, URL, Constants.email + /*Constants.randomStr*/ "auth1" + "@thinslices.com", Constants.password); + + WebElement validLogin = null; + + try { + validLogin = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("button[data-test='new-manuscript']"))); + } catch (NoSuchElementException e) { + + } + + assertNotNull(validLogin); + + driver.findElement(By.cssSelector("button[data-test='new-manuscript']")).click(); + + try { + wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("button[data-test='submission-next']"))); + } catch (NoSuchElementException e) { + + } + + assertNotNull(driver.findElement(By.cssSelector("button[data-test='submission-next']"))); + + // First step submission flow + driver.findElement(By.cssSelector("[data-test-id='agree-checkbox']")).click(); + driver.findElement(By.cssSelector("button[data-test='submission-next']")).click(); + + // Second step submission flow + try { + wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".wizard-step >[data-test-id='row']:nth-of-type(2) span"))); + } catch (NoSuchElementException e) { + + } + + assertEquals("Please provide the details of all the authors of this manuscript, in the order that they appear on the manuscript. Your details have been prefilled as the submitting author.",driver.findElement(By.cssSelector(".wizard-step >[data-test-id='row']:nth-of-type(2) span")).getText()); + assertEquals("MANUSCRIPT TITLE\n*", driver.findElement(By.cssSelector("[data-test-id='submission-title']")).getText()); + + driver.findElement(By.cssSelector("input[name='metadata.title']")).sendKeys(Constants.manusName); + driver.findElement(By.cssSelector("[data-test-id='submission-type']")).click(); + try { + wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("[data-test-id='submission-type'] div[role=\"option\"]"))); + } catch (NoSuchElementException e) { + + } + driver.findElement(By.cssSelector("[data-test-id='submission-type'] div[role=\"option\"]:nth-child(1)")).click(); + driver.findElement(By.cssSelector("[data-test-id='submission-abstract'] textarea")).sendKeys(Constants.manusAbstract); + WebElement element = driver.findElement(By.cssSelector("[name='conflicts.hasConflicts'][value='no']")); + + Utils.scrollToElement(driver, element); + element.click(); + + driver.findElement(By.cssSelector("[name='conflicts.hasDataAvailability'][value='yes']")).click(); + WebElement element1 = driver.findElement(By.cssSelector("[name='conflicts.hasFunding'][value='yes']")); + + Utils.scrollToElement(driver, element1); + element1.click(); + + WebElement element2 = driver.findElement(By.cssSelector("button[data-test='submission-next']")); + + Utils.scrollToElement(driver, element2); + element2.click(); + + // Third step submission flow + + try { + wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector(".wizard-step [level='2']")))); + } catch (NoSuchElementException e) { + + } + WebElement pageTitle = driver.findElement(By.cssSelector(".wizard-step [level='2']")); + assertEquals("3. Manuscript Files Upload", pageTitle.getText()); + + try { + wait.until(ExpectedConditions.visibilityOf(pageTitle)); + } catch (NoSuchElementException e) { + + } + + driver.findElement(By.cssSelector(/*"[data-test='upload-manuscripts']*/"input[type=\"file\"]")).sendKeys(Constants.fileManuscript); +// driver.findElement(By.cssSelector("[data-test='upload-supplementary'] input[type=\"file\"]")).sendKeys(Constants.fileSupplementary); +// driver.findElement(By.cssSelector("[data-test='upload-coverLetter'] input[type=\"file\"]")).sendKeys(Constants.fileCoverLetter); + + try { + wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button[data-test='submission-next']"))); + } catch (NoSuchElementException e) { + + } + + WebElement element3 = driver.findElement(By.cssSelector("button[data-test='submission-next']")); + Utils.scrollToElement(driver, element3); + element3.click(); + + driver.findElement(By.xpath("//button[contains(.,'AGREE & SUBMIT')]")).click(); + + try { + wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[contains(.,'GO TO DASHBOARD')]"))); + } catch (NoSuchElementException e) { + + } + + driver.findElement(By.xpath("//button[contains(.,'GO TO DASHBOARD')]")).click(); + + } +} diff --git a/Automation/src/test/java/Utils.java b/Automation/src/test/java/Utils.java index cc31dadae..7d10e9b50 100644 --- a/Automation/src/test/java/Utils.java +++ b/Automation/src/test/java/Utils.java @@ -85,5 +85,12 @@ public class Utils { driver.findElement(By.xpath(".//button[contains(text(),'"+"CONFIRM"+"')]")).click(); } + + public static void scrollToElement(WebDriver driver, WebElement el) { + if (driver instanceof JavascriptExecutor) { + ((JavascriptExecutor) driver) + .executeScript("arguments[0].scrollIntoView(true);", el); + } + } } -- GitLab