diff --git a/backend/package.json b/backend/package.json index b702876..8b9ba3b 100644 --- a/backend/package.json +++ b/backend/package.json @@ -10,9 +10,9 @@ "local": "cross-env NODE_ENV=local nodemon index.js", "lint": "eslint .", "start:test": "cross-env NODE_ENV=local-test jest --verbose -i", - "start:test:issue":"cross-env NODE_ENV=local-test jest --verbose tests/issue_api.test.js", - "start:test:label":"cross-env NODE_ENV=local-test jest --verbose tests/label_api.test.js", - "start:test:issue-label":"cross-env NODE_ENV=local-test jest --verbose tests/issue-label_cross.test.js" + "start:test:issue": "cross-env NODE_ENV=local-test jest --verbose tests/issue_api.test.js", + "start:test:label": "cross-env NODE_ENV=local-test jest --verbose tests/label_api.test.js", + "start:test:issue-label": "cross-env NODE_ENV=local-test jest --verbose tests/issue-label_cross.test.js" }, "author": "", "license": "ISC", diff --git a/test/.gitignore b/test/.gitignore index fb77e5b..1154b89 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,4 +1,3 @@ target -src/test/java/gmibank/runners +src/test/java/issueTracker/Runners .idea -libraries \ No newline at end of file diff --git a/test/issueTracker.iml b/test/issueTracker.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/test/issueTracker.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/test/pom.xml b/test/pom.xml index 9223bc7..ca21250 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -5,56 +5,35 @@ 4.0.0 org.example - issuetracker + issueTracker 1.0-SNAPSHOT 1.8 1.8 + - - - org.postgresql - postgresql - 42.2.14 - - - - io.rest-assured - rest-assured - 4.3.0 - test - - - - org.testng - testng - 7.1.0 - test - - - - com.itextpdf - itextpdf - 5.4.2 - + - com.microsoft.sqlserver - mssql-jdbc - 8.2.2.jre8 + io.github.bonigarcia + webdrivermanager + 3.8.1 - + + - com.fasterxml.jackson.core - jackson-databind - 2.9.8 + org.seleniumhq.selenium + selenium-java + 3.141.59 + io.cucumber cucumber-java 5.7.0 + io.cucumber @@ -62,71 +41,69 @@ 5.7.0 test + + org.slf4j slf4j-simple 1.7.30 test - + - org.seleniumhq.selenium - selenium-java - 3.141.59 + mysql + mysql-connector-java + 8.0.19 - - io.github.bonigarcia - webdrivermanager - 3.8.1 - - - - org.apache.poi - poi - 4.1.2 - - - - org.apache.poi - poi-ooxml - 4.1.2 - - - - com.github.javafaker - javafaker - 1.0.2 - - - com.itextpdf - itextpdf - 5.5.10 - - - org.apache.pdfbox - pdfbox - 2.0.4 + io.rest-assured + rest-assured + 4.3.0 + test - + + + org.apache.maven.plugins - maven-surefire-plugin + maven-failsafe-plugin + 3.0.0-M1 true + false + + **/Runners/*Runner*.java + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M1 + + classes + perthread + 2 + false + -Duser.language=en + -Xmx1024m + -XX:MaxPermSize=256m + -Dfile.encoding=UTF-8 + false - **/*CukesRunner.java + **/Runners/*Runner*.java + true net.masterthought maven-cucumber-reporting - 4.4.0 + 5.0.0 execution @@ -136,32 +113,18 @@ cucumber-jvm-example - ${project.build.directory} - ${project.build.directory} - - **/cucumber.json - - - - sample.properties - other.properties - - + **/json-reports/*.json + -> + sample.properties + other.properties + - - org.apache.maven.plugins - maven-compiler-plugin - - 8 - 8 - - diff --git a/test/src/test/java/issueTracker/Pages/IssueListPage.java b/test/src/test/java/issueTracker/Pages/IssueListPage.java index f438c8e..7a8e59b 100644 --- a/test/src/test/java/issueTracker/Pages/IssueListPage.java +++ b/test/src/test/java/issueTracker/Pages/IssueListPage.java @@ -17,6 +17,20 @@ public IssueListPage() { public WebElement text; @FindBy(xpath = "//tbody//tr") public List rows; + @FindBy(xpath = "//div[@class='info']") + public WebElement message; + @FindBy(id = "validationCustom01") + public WebElement titleUpdate; + @FindBy(xpath = "//button[@type='submit']") + public WebElement updateButton; + @FindBy(xpath = "//button[@class='btn btn-danger']") + public WebElement cancelButton; + @FindBy(id = "validationCustom02") + public WebElement descriptionUpdate; + @FindBy(id = "validationCustom03") + public WebElement labelsUpdate; + @FindBy(xpath = "//tbody//tr") + public List issueList; public static WebElement findingThead(String columnName) { int columnNumber = 0; @@ -33,4 +47,5 @@ public static WebElement findingThead(String columnName) { WebElement thead = Driver.getDriver().findElement(By.xpath("//thead//th[" + columnNumber + "]")); return thead; } + } \ No newline at end of file diff --git a/test/src/test/java/issueTracker/Runners/Runner.java b/test/src/test/java/issueTracker/Runners/Runner.java deleted file mode 100644 index fa7a6c1..0000000 --- a/test/src/test/java/issueTracker/Runners/Runner.java +++ /dev/null @@ -1,21 +0,0 @@ -package issueTracker.Runners; - -import io.cucumber.junit.Cucumber; -import io.cucumber.junit.CucumberOptions; -import org.junit.runner.RunWith; - -@RunWith(Cucumber.class) -@CucumberOptions(strict = true, - plugin = { - "html:target/default-cucumber-reports", - "json:target/json-reports/cucumber.json", - "junit:target/xml-report/cucumber.xml" - }, - //plugin = "html:target\\default-cucumber-reports", - features ="src/test/resources/features", - glue = "issueTracker/StepDefinitions", - tags = "@api", - dryRun = false -) -public class Runner { -} diff --git a/test/src/test/java/issueTracker/StepDefinitions/ApiStepDefs.java b/test/src/test/java/issueTracker/StepDefinitions/ApiStepDefs.java index 2aaa608..b6b3ebc 100644 --- a/test/src/test/java/issueTracker/StepDefinitions/ApiStepDefs.java +++ b/test/src/test/java/issueTracker/StepDefinitions/ApiStepDefs.java @@ -4,8 +4,7 @@ import io.restassured.http.ContentType; import io.restassured.response.Response; import issueTracker.Utilities.ConfigReader; - -import static io.restassured.RestAssured.*; +import static io.restassured.RestAssured.given; public class ApiStepDefs { @Given("user gets all data from api") diff --git a/test/src/test/java/issueTracker/StepDefinitions/CreateIssueStepDefs.java b/test/src/test/java/issueTracker/StepDefinitions/CreateIssueStepDefs.java index 3e0de71..37d8ee4 100644 --- a/test/src/test/java/issueTracker/StepDefinitions/CreateIssueStepDefs.java +++ b/test/src/test/java/issueTracker/StepDefinitions/CreateIssueStepDefs.java @@ -5,7 +5,7 @@ import issueTracker.Utilities.ConfigReader; import issueTracker.Utilities.Driver; import issueTracker.Utilities.Pages; -import javafx.beans.value.WeakChangeListener; +import issueTracker.Utilities.ReusableMethods; import org.junit.Assert; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; @@ -16,6 +16,7 @@ public class CreateIssueStepDefs { Pages pages = new Pages(); + ReusableMethods reusableMethods =new ReusableMethods(); @Given("user on the homepage") public void user_on_the_homepage() { @@ -53,16 +54,19 @@ public void user_clicks_on_create_new_issue_button() { } @Then("verify that issue list has {string}") public void verify_that_issue_list_has(String title) { + reusableMethods.wait(2); + pages.homePage().issueListButton.click(); + List rowText= new ArrayList<>(); for (int i=0;i http://www.fhctrip.com/Account/Logon +// } + } diff --git a/test/src/test/java/issueTracker/Utilities/DatabaseUtility.java b/test/src/test/java/issueTracker/Utilities/DatabaseUtility.java deleted file mode 100644 index 17368c0..0000000 --- a/test/src/test/java/issueTracker/Utilities/DatabaseUtility.java +++ /dev/null @@ -1,189 +0,0 @@ -package issueTracker.Utilities; -import java.sql.*; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - - -public class DatabaseUtility { - private static Connection connection; - private static Statement statement; - private static ResultSet resultSet; - public static void createConnection() { - String url = "jdbc:postgresql://157.230.48.97:5432/gmibank_db"; - String user = "techprodb_user"; - String password = "Techpro_@126"; - try { - connection = DriverManager.getConnection(url, user, password); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - public static void createConnection(String url, String user, String password) { - try { - connection = DriverManager.getConnection(url, user, password); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - public static void closeConnection() { - try { - if (resultSet != null) { - resultSet.close(); - } - if (statement != null) { - statement.close(); - } - if (connection != null) { - connection.close(); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } - /** - * - * @param query - * @return returns a single cell value. If the results in multiple rows and/or - * columns of data, only first column of the first row will be returned. - * The rest of the data will be ignored - */ - public static Object getCellValue(String query) { - return getQueryResultList(query).get(0).get(0); - } - /** - * - * @param query - * @return returns a list of Strings which represent a row of data. If the query - * results in multiple rows and/or columns of data, only first row will - * be returned. The rest of the data will be ignored - */ - public static List getRowList(String query) { - return getQueryResultList(query).get(0); - } - /** - * - * @param query - * @return returns a map which represent a row of data where key is the column - * name. If the query results in multiple rows and/or columns of data, - * only first row will be returned. The rest of the data will be ignored - */ - public static Map getRowMap(String query) { - return getQueryResultMap(query).get(0); - } - /** - * - * @param query - * @return returns query result in a list of lists where outer list represents - * collection of rows and inner lists represent a single row - */ - public static List> getQueryResultList(String query) { - executeQuery(query); - List> rowList = new ArrayList<>(); - ResultSetMetaData rsmd; - try { - rsmd = resultSet.getMetaData(); - while (resultSet.next()) { - List row = new ArrayList<>(); - for (int i = 1; i <= rsmd.getColumnCount(); i++) { - row.add(resultSet.getObject(i)); - } - rowList.add(row); - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return rowList; - } - /** - * - * @param query - * @param column - * @return list of values of a single column from the result set - */ - public static List getColumnData(String query, String column) { - executeQuery(query); - List rowList = new ArrayList<>(); - ResultSetMetaData rsmd; - try { - rsmd = resultSet.getMetaData(); - while (resultSet.next()) { - rowList.add(resultSet.getObject(column)); - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return rowList; - } - /** - * - * @param query - * @return returns query result in a list of maps where the list represents - * collection of rows and a map represents represent a single row with - * key being the column name - */ - public static List> getQueryResultMap(String query) { - executeQuery(query); - List> rowList = new ArrayList<>(); - ResultSetMetaData rsmd; - try { - rsmd = resultSet.getMetaData(); - while (resultSet.next()) { - Map colNameValueMap = new HashMap<>(); - for (int i = 1; i <= rsmd.getColumnCount(); i++) { - colNameValueMap.put(rsmd.getColumnName(i), resultSet.getObject(i)); - } - rowList.add(colNameValueMap); - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return rowList; - } - /** - * - * @param query - * @return List of columns returned in result set - */ - public static List getColumnNames(String query) { - executeQuery(query); - List columns = new ArrayList<>(); - ResultSetMetaData rsmd; - try { - rsmd = resultSet.getMetaData(); - int columnCount = rsmd.getColumnCount(); - for (int i = 1; i <= columnCount; i++) { - columns.add(rsmd.getColumnName(i)); - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return columns; - } - private static void executeQuery(String query) { - try { - statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - try { - resultSet = statement.executeQuery(query); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - public static int getRowCount() throws Exception { - resultSet.last(); - int rowCount = resultSet.getRow(); - return rowCount; - } -} diff --git a/test/src/test/java/issueTracker/Utilities/Driver.java b/test/src/test/java/issueTracker/Utilities/Driver.java index ed8bfd7..fa03e38 100644 --- a/test/src/test/java/issueTracker/Utilities/Driver.java +++ b/test/src/test/java/issueTracker/Utilities/Driver.java @@ -1,36 +1,25 @@ package issueTracker.Utilities; -import com.github.javafaker.Faker; -import com.google.common.base.Function; - import io.github.bonigarcia.wdm.WebDriverManager; -import org.junit.Assert; -import org.openqa.selenium.*; +import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; -import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.safari.SafariDriver; -import org.openqa.selenium.support.ui.*; -import java.time.Duration; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - public class Driver { private Driver() { + //we don't want to create another abject. Singleton pattern } - + //create a driver instance static WebDriver driver; - + //to initialize the driver we create a static method public static WebDriver getDriver() { + //create the driver if and only if it is null if (driver == null) { switch (ConfigReader.getProperty("browser")) { case "chrome": @@ -55,448 +44,18 @@ public static WebDriver getDriver() { break; } } - driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); + driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.manage().window().maximize(); return driver; } - public static void closeDriver() { - if (driver != null) { - //driver.quit(); - - driver = null; - } - } - - public static void wait(int secs) { - try { - Thread.sleep(1000 * secs); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } -// public static void login (String userType){ -// UserInfoPage userInfoPage = new UserInfoPage(); -// userInfoPage.accountItem.click(); -// userInfoPage.login.click(); -// String entranceUserName = userType + "name"; -// String entrancePassword = userType+ "Password"; -// userInfoPage.username.sendKeys(ConfigReader.getProperty(entranceUserName)); -// userInfoPage.password.sendKeys(ConfigReader.getProperty(entrancePassword)); -// userInfoPage.signInButton.click(); -// } -// public static void create(String role) { -// RegisterPage register = new RegisterPage(); -// Faker faker = new Faker(); -// String SSN = faker.number().digits(3) + "-" + faker.number().digits(2) + "-" + faker.number().digits(4); -// String firstName = faker.name().firstName(); -// String lastName = faker.name().lastName(); -// String address = faker.address().fullAddress(); -// String phoneNumber = faker.number().digits(3) + "-" + faker.number().digits(3) + "-" + faker.number().digits(4); -// String userName = faker.name().username(); -// String email = faker.internet().emailAddress(); -// String password = faker.internet().password(7, 10, true, true, true); -// register.ssnBox.sendKeys(SSN); -// register.firstnameBox.sendKeys(firstName); -// register.lastnameBox.sendKeys(lastName); -// register.addressBox.sendKeys(address); -// register.mobilePhoneBox.sendKeys(phoneNumber); -// register.usernameBox.sendKeys(userName); -// register.emailBox.sendKeys(email); -// register.newPasswordBox.sendKeys(password); -// register.passwordConfirmBox.sendKeys(password); -// register.registerButton2.click(); -// WriteToText.saveTestData(email, firstName, lastName, SSN, role); -// Driver.login("admin"); -// Admin admin = new Admin(); -// admin.adminMenu.click(); -// Driver.wait(1); -// admin.item.click(); -// Driver.wait(1); -// admin.item2.click(); -// Driver.wait(1); -// for(int i=1;i<21;i++){ -// String xpath = "//tbody//tr["+i+"]//td["+3+"]"; -// String data=driver.findElement(By.xpath(xpath)).getText(); -// if(data.equals(email)){ -// Driver.getDriver().findElement(By.xpath("//tbody//tr["+i+"]//td["+4+"]")).click(); -// Driver.getDriver().findElement(By.xpath("(//a[@class='btn btn-primary btn-sm'])[1]")).click(); -// //String upper = role.toUpperCase(); -// Driver.wait(2); -// Actions actions = new Actions(Driver.getDriver()); -// JavascriptExecutor js = (JavascriptExecutor) Driver.getDriver(); -// js.executeScript("window.scrollBy(0,500)"); //Scroll vertically down by 1000 pixels -// Driver.wait(2); -// Select select = new Select(admin.kutu); -// select.getFirstSelectedOption().click(); -// Driver.getDriver().findElement(By.xpath("//option[@value='ROLE_"+role+"']")).click(); -// -// Driver.wait(2); -// Driver.getDriver().findElement(By.xpath("//button[@class='btn btn-primary']")).click(); -// } -// -// -// -// } -// -// } -// public static void UIverification(String role){ -// Admin admin = new Admin(); -// String emaildata = ReadText.returnEmail(); -// //System.out.println(emaildata+"?????"); -// JavascriptExecutor js = (JavascriptExecutor) Driver.getDriver(); -// js.executeScript("window.scrollBy(0,-500)"); //Scroll vertically down by 1000 pixels -// Driver.wait(2); -// //admin.item2.click(); -// Driver.wait(2); -// admin.item2.click(); -// for(int i=1;i<21;i++){ -// String xpath = "//tbody//tr["+i+"]//td["+3+"]"; -// String data=driver.findElement(By.xpath(xpath)).getText(); -// if(data.equals(emaildata)){ -// Driver.wait(2); -// String actualRole = Driver.getDriver().findElement(By.xpath("//tbody//tr["+i+"]//td["+6+"]")).getText(); -// String expectedRole = "ROLE_"+role; -// Assert.assertTrue(actualRole.equals(expectedRole)); -// -// -// } -// -// -// -// -// } -// System.out.println("UI verification is done for ==> " + ReadText.returnFirstName()+" | " + ReadText.returnLastName() + " | " + ReadText.returnSSn()); -// -// -// } - public static void waitAndClick(WebElement element, int timeout) { - for (int i = 0; i < timeout; i++) { - try { - element.click(); - return; - } catch (WebDriverException e) { - wait(1); - } - } - } - public static void switchToWindow(String targetTitle) { - String origin = Driver.getDriver().getWindowHandle(); - for (String handle : Driver.getDriver().getWindowHandles()) { - Driver.getDriver().switchTo().window(handle); - if (Driver.getDriver().getTitle().equals(targetTitle)) { - return; - } - } - Driver.getDriver().switchTo().window(origin); - } - public static void hover(WebElement element) { - Actions actions = new Actions(Driver.getDriver()); - actions.moveToElement(element).perform(); - } - /** - * return a list of string from a list of elements ignores any element with no - * text - * - * @param list - * @return - */ - - - public static List getElementsText(List list) { - List elemTexts = new ArrayList<>(); - for (WebElement el : list) { - elemTexts.add(el.getText()); - } - return elemTexts; - } - - - public static List getElementsText(By locator) { - List elems = Driver.getDriver().findElements(locator); - List elemTexts = new ArrayList<>(); - for (WebElement el : elems) { - elemTexts.add(el.getText()); - } - return elemTexts; - } - public static WebElement waitForVisibility(WebElement element, int timeToWaitInSec) { - WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeToWaitInSec); - return wait.until(ExpectedConditions.visibilityOf(element)); - } - public static WebElement waitForVisibility(By locator, int timeout) { - WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeout); - return wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); - } - public static Boolean waitForInVisibility(By locator, int timeout) { - WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeout); - return wait.until(ExpectedConditions.invisibilityOfElementLocated(locator)); - } - public static WebElement waitForClickablility(WebElement element, int timeout) { - WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeout); - return wait.until(ExpectedConditions.elementToBeClickable(element)); - } - public static WebElement waitForClickablility(By locator, int timeout) { - WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeout); - return wait.until(ExpectedConditions.elementToBeClickable(locator)); - } - - public static void waitForPageToLoad(long timeOutInSeconds) { - ExpectedCondition expectation = new ExpectedCondition() { - public Boolean apply(WebDriver driver) { - return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete"); - } - }; - try { - WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeOutInSeconds); - wait.until(expectation); - } catch (Exception error) { - error.printStackTrace(); - } - } - public static WebElement fluentWait(final WebElement webElement, int timeinsec) { - FluentWait wait = new FluentWait(Driver.getDriver()) - .withTimeout(Duration.ofSeconds(timeinsec)) - .pollingEvery(Duration.ofMillis(500)) - .ignoring(NoSuchElementException.class); - WebElement element = wait.until(new Function() { - public WebElement apply(WebDriver driver) { - return webElement; - } - }); - return element; - } - /** - * Verifies whether the element matching the provided locator is displayed on page - * fails if the element matching the provided locator is not found or not displayed - * - * @param by - */ - public static void verifyElementDisplayed(By by) { - try { - assertTrue("Element not visible: " + by, Driver.getDriver().findElement(by).isDisplayed()); - } catch (NoSuchElementException e) { - Assert.fail("Element not found: " + by); - } - } - /** - * Verifies whether the element matching the provided locator is NOT displayed on page - * fails if the element matching the provided locator is not found or not displayed - * - * @param by - */ - public static void verifyElementNotDisplayed(By by) { - try { - assertFalse("Element should not be visible: " + by, Driver.getDriver().findElement(by).isDisplayed()); - } catch (NoSuchElementException e) { - e.printStackTrace(); - } - } - /** - * Verifies whether the element is displayed on page - * fails if the element is not found or not displayed - * - * @param element - */ - public static void verifyElementDisplayed(WebElement element) { - try { - assertTrue("Element not visible: " + element, element.isDisplayed()); - } catch (NoSuchElementException e) { - Assert.fail("Element not found: " + element); - } - } - /** - * Waits for element to be not stale - * - * @param element - */ - public void waitForStaleElement(WebElement element) { - int y = 0; - while (y <= 15) { - if (y == 1) - try { - element.isDisplayed(); - break; - } catch (StaleElementReferenceException st) { - y++; - try { - Thread.sleep(300); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } catch (WebDriverException we) { - y++; - try { - Thread.sleep(300); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - /** - * Selects a random value from a dropdown list and returns the selected Web Element - * - * @param select - * @return - */ - public static WebElement selectRandomTextFromDropdown(Select select) { - Random random = new Random(); - List weblist = select.getOptions(); - int optionIndex = 1 + random.nextInt(weblist.size() - 1); - select.selectByIndex(optionIndex); - return select.getFirstSelectedOption(); - } - - - public static void selectDropdown (WebElement element, int index){ - Select dropdown = new Select(element); - dropdown.selectByIndex(index); - } - - public static void selectDropdownCountry (WebElement element, int countryIndex){ - Select dropdown = new Select(element); - dropdown.selectByIndex(countryIndex); -//select dropdownlist - } - - public static void selectDropdown (WebElement element, String str){ - Select dropdown = new Select(element); - dropdown.selectByVisibleText(str); - } - //generate number for ssn 321-56-6789 - public static int getRandomInteger(int maximum, int minimum){ - return ((int) (Math.random()*(maximum - minimum))) + minimum; - - } - -// public static void waitAndClick(WebElement element, int timeout) { -// for (int i = 0; i < timeout; i++) { -// try { -// element.click(); -// return; -// } catch (WebDriverException e) { -// wait(1); -// } -// } -// } - - - - - /** - * Clicks on an element using JavaScript - * - * @param element - */ - public static void clickWithJS(WebElement element) { - ((JavascriptExecutor) Driver.getDriver()).executeScript("arguments[0].scrollIntoView(true);", element); - ((JavascriptExecutor) Driver.getDriver()).executeScript("arguments[0].click();", element); - } - /** - * Scrolls down to an element using JavaScript - * - * @param element - */ - public static void scrollToElement(WebElement element) { - ((JavascriptExecutor) Driver.getDriver()).executeScript("arguments[0].scrollIntoView(true);", element); - } - /** - * Performs double click action on an element - * - * @param element - */ - public static void doubleClick(WebElement element) { - new Actions(Driver.getDriver()).doubleClick(element).build().perform(); - } - /** - * Changes the HTML attribute of a Web Element to the given value using JavaScript - * - * @param element - * @param attributeName - * @param attributeValue - */ - public static void setAttribute(WebElement element, String attributeName, String attributeValue) { - ((JavascriptExecutor) Driver.getDriver()).executeScript("arguments[0].setAttribute(arguments[1], arguments[2]);", element, attributeName, attributeValue); - } - /** - * @param element - * @param check - */ - public static void selectCheckBox(WebElement element, boolean check) { - if (check) { - if (!element.isSelected()) { - element.click(); - } - } else { - if (element.isSelected()) { - element.click(); - } - } - } - public static void clickWithTimeOut(WebElement element, int timeout) { - for (int i = 0; i < timeout; i++) { - try { - element.click(); - return; - } catch (WebDriverException e) { - wait(1); - } + if (driver != null) {//if the driver is pointing chrome + driver.quit();//quit the driver + driver = null;//set it back to null to make sure driver is null + // so I can initialize it again + //This is important especially you do cross browser testing(testing with + // multiple browser like chrome, firefox, ie etc.) } } - /** - * executes the given JavaScript command on given web element - * - * @param element - */ - public static void executeJScommand(WebElement element, String command) { - JavascriptExecutor jse = (JavascriptExecutor) Driver.getDriver(); - jse.executeScript(command, element); - } - /** - * executes the given JavaScript command on given web element - * - * @param command - */ - public static void executeJScommand(String command) { - JavascriptExecutor jse = (JavascriptExecutor) Driver.getDriver(); - jse.executeScript(command); - } - - public boolean isElementSelected(By locator){ return webAction(locator).isSelected(); } - public void sendValue(By locator, String value){ - try { - webAction(locator).sendKeys(value); - }catch (Exception e){ - System.out.println("Some exception occured while sending value"+ locator); - } - } - public static WebElement webAction(final By locator){ - Wait wait = new FluentWait(getDriver()) - .withTimeout(Duration.ofSeconds(15)) - .pollingEvery(Duration.ofSeconds(1)) - .ignoring(java.util.NoSuchElementException.class) - .ignoring(StaleElementReferenceException.class) - .ignoring(ElementClickInterceptedException.class) - .withMessage( - "Webdriver waited for 15 seconds not still could not find the element therefore TimeOutExceptions" - ); - return wait.until(new java.util.function.Function() { - @Override - public WebElement apply(WebDriver webDriver) { - return null; - } - }); - } - - public static void waitAndSendText(WebElement element,String text, int timeout) { - for (int i = 0; i < timeout; i++) { - try { - element.sendKeys(text); - return; - } catch (WebDriverException e) { - wait(1); - } - } - }} +} diff --git a/test/src/test/java/issueTracker/Utilities/ExcelUtil.java b/test/src/test/java/issueTracker/Utilities/ExcelUtil.java deleted file mode 100644 index 37ea5b8..0000000 --- a/test/src/test/java/issueTracker/Utilities/ExcelUtil.java +++ /dev/null @@ -1,116 +0,0 @@ -package issueTracker.Utilities; - -import org.apache.poi.ss.usermodel.*; - -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -// We can use this excel utilities class to read and write excel files (for xls, xlsx files). -// These are the reusable custom methods we can use in our test classes - -public class ExcelUtil { - private Workbook workBook; - private Sheet workSheet; - private String path; - public ExcelUtil(String path, String sheetName) {//This Constructor is to open and access the excel file - this.path = path; - try { - // Opening the Excel file - FileInputStream fileInputStream = new FileInputStream(path); - // accessing the workbook - workBook = WorkbookFactory.create(fileInputStream); - //getting the worksheet - workSheet = workBook.getSheet(sheetName); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - //===============Getting the number of columns in a specific single row================= - public int columnCount() { - //getting how many numbers in row 1 - return workSheet.getRow(0).getLastCellNum(); - } - //===============how do you get the last row number?Index start at 0.==================== - public int rowCount() { - return workSheet.getLastRowNum() + 1; - }//adding 1 to get the actual count - //==============When you enter row and column number, then you get the data========== - public String getCellData(int rowNum, int colNum) { - Cell cell; - try { - cell = workSheet.getRow(rowNum).getCell(colNum); - String cellData = cell.toString(); - return cellData; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - //============getting all data into two dimentional array and returning the data=== - public String[][] getDataArray() { - String[][] data = new String[rowCount()][columnCount()]; - for (int i = 0; i < rowCount(); i++) { - for (int j = 0; j < columnCount(); j++) { - String value = getCellData(i, j); - data[i][j] = value; - } - } - return data; - } - //This will get the list of the data in the excel file - //This is a list of map. This takes the data as string and will return the data as a Map of String - public List> getDataList() { - // getting all columns - List columns = getColumnsNames(); - // method will return this - List> data = new ArrayList<>(); - for (int i = 1; i < rowCount(); i++) { - // get each row - Row row = workSheet.getRow(i); - // creating map of the row using the column and value - // key=column, value=cell - Map rowMap = new HashMap(); - for (Cell cell : row) { - int columnIndex = cell.getColumnIndex(); - rowMap.put(columns.get(columnIndex), cell.toString()); - } - data.add(rowMap); - } - return data; - } - //==============going to the first row and reading each row one by one==================// - public List getColumnsNames() { - List columns = new ArrayList<>(); - for (Cell cell : workSheet.getRow(0)) { - columns.add(cell.toString()); - } - return columns; - } - //=========When you enter the row and column number, returning the value===============// - public void setCellData(String value, int rowNum, int colNum) { - Cell cell; - Row row; - try { - row = workSheet.getRow(rowNum); - cell = row.getCell(colNum); - if (cell == null) {//if there is no value, create a cell. - cell = row.createCell(colNum); - cell.setCellValue(value); - } else { - cell.setCellValue(value); - } - FileOutputStream fileOutputStream = new FileOutputStream(path); - workBook.write(fileOutputStream); - fileOutputStream.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - public void setCellData(String value, String columnName, int row) { - int column = getColumnsNames().indexOf(columnName); - setCellData(value, row, column); - } -} diff --git a/test/src/test/java/issueTracker/Utilities/ReadText.java b/test/src/test/java/issueTracker/Utilities/ReadText.java deleted file mode 100644 index 28bf5ef..0000000 --- a/test/src/test/java/issueTracker/Utilities/ReadText.java +++ /dev/null @@ -1,349 +0,0 @@ -package issueTracker.Utilities; - - - -import java.io.BufferedReader; -import java.io.FileReader; -import java.util.ArrayList; -import java.util.List; - -public class ReadText { -// public static List returnCustomer(String filePath){ -// Listall = new ArrayList<>(); -// try(BufferedReader br = new BufferedReader(new FileReader(ConfigReader.getProperty(filePath)))) { -// StringBuilder sb = new StringBuilder(); -// String line = br.readLine(); -// -// while (line != null) { -// Customer customer = new Customer(); -// sb.append(line); -// sb.append(System.lineSeparator()); -// line = br.readLine(); -// String [] each = line.split(","); -// customer.setFirstName(each[0]); -// customer.setLastName(each[1]); -// customer.setSsn(each[2]); -// all.add(customer); -// } -// String everything = sb.toString(); -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return all; -// } -// -// public static List returnCustomerSNN(String filePath){ -// Listall = new ArrayList<>(); -// try(BufferedReader br = new BufferedReader(new FileReader(filePath))) { -// StringBuilder sb = new StringBuilder(); -// String line = br.readLine(); -// System.out.println(line); -// int i = 0; -// while (line != null) { -// Customer customer = new Customer(); -// customer.setSsn(line.split(",")[0]); -// sb.append(System.lineSeparator()); -// line = br.readLine(); -// -// System.out.println(i++); -// -// all.add(customer); -// } -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return all; -// } -// -// public static List readTxtData(String filePath)throws Exception{ -// List list = new ArrayList<>(); -// BufferedReader br = new BufferedReader(new FileReader(filePath)); -// try { -// StringBuilder sb = new StringBuilder(); -// String line = br.readLine(); -// Customer customer = new Customer(); -// while (line != null) { -// sb.append(line); -// sb.append(System.lineSeparator()); -// line = br.readLine(); -//// customer.setSsn(line); -// -// } -// String everything = sb.toString(); -// -// customer.setSsn(everything); -// list.add(customer); -// } finally { -// br.close(); -// } -// return list; -// -// } -// -// public static List returnAllStates(String filePath){ -// Listall = new ArrayList<>(); -// try(BufferedReader br = new BufferedReader(new FileReader(filePath))) { -// StringBuilder sb = new StringBuilder(); -// String line = br.readLine(); -// System.out.println(line); -// int i = 0; -// while (line != null) { -// States state = new States(); -// String [] allLine = line.split(","); -// -// int id = Integer.parseInt(allLine[1].trim()); -// state.setId(id); -// state.setName(allLine[0]); -// sb.append(System.lineSeparator()); -// line = br.readLine(); -// -// System.out.println(i++); -// -// all.add(state); -// } -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return all; -// } -// -// public static List returnCustomerSNNList(String filePath){ -// Listall = new ArrayList<>(); -// try(BufferedReader br = new BufferedReader(new FileReader(filePath))) { -// StringBuilder sb = new StringBuilder(); -// String line = br.readLine(); -// System.out.println(line); -// int i = 0; -// while (line != null) { -// Customer customer = new Customer(); -// customer.setSsn(line.split(",")[0]); -// sb.append(System.lineSeparator()); -// line = br.readLine(); -// -// //System.out.println(i++); -// -// all.add(customer.getSsn()); -// } -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return all; -// } -// -// -// public static List returnAllStates2(String filePath){ -// Listall = new ArrayList<>(); -// try(BufferedReader br = new BufferedReader(new FileReader(filePath))) { -// StringBuilder sb = new StringBuilder(); -// String line = br.readLine(); -// System.out.println(line); -// int i = 0; -// while (line != null) { -// States states = new States(); -// states.setName(line.split(",")[0].trim()); -// states.setId(Integer.parseInt(line.split(",")[1].trim())); -// sb.append(System.lineSeparator()); -// line = br.readLine(); -// -// System.out.println(i++); -// -// all.add(states); -// } -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return all; -// } -// -// public static List returnAllStates3(String filePath){ -// Listall = new ArrayList<>(); -// try(BufferedReader br = new BufferedReader(new FileReader(filePath))) { -// StringBuilder sb = new StringBuilder(); -// String line = br.readLine(); -// System.out.println(line); -// int i = 0; -// while (line != null) { -// String temp = ""; -// temp =line.split(",")[0].trim(); -// -// sb.append(System.lineSeparator()); -// line = br.readLine(); -// -// System.out.println(i++); -// -// all.add(temp); -// } -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return all; -// } -// public static List returnCountryId(String filePath){ -// Listall = new ArrayList<>(); -// try(BufferedReader br = new BufferedReader(new FileReader(filePath))) { -// StringBuilder sb = new StringBuilder(); -// String line = br.readLine(); -// System.out.println(line); -// int i = 0; -// while (line != null) { -// Country country = new Country(); -// country.setId(Integer.parseInt(line.split(",")[0])); -// sb.append(System.lineSeparator()); -// line = br.readLine(); -// -// //System.out.println(i++); -// -// all.add(String.valueOf(country.getId())); -// } -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return all; -// } -// public static List returnApplicantSNNList(String filePath){ -// Listall = new ArrayList<>(); -// try(BufferedReader br = new BufferedReader(new FileReader(filePath))) { -// StringBuilder sb = new StringBuilder(); -// String line = br.readLine(); -// System.out.println(line); -// int i = 0; -// while (line != null) { -// NewApplicant newApplicant = new NewApplicant(); -// newApplicant.setSSN(line.split(",")[0]); -// sb.append(System.lineSeparator()); -// line = br.readLine(); -// -// //System.out.println(i++); -// -// all.add(newApplicant.getSSN()); -// } -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return all; -// } -// public static String returnEmail(){ -// Listall = new ArrayList<>(); -// try(BufferedReader br = new BufferedReader(new FileReader("src/test/java/gmibank/test-data/test-data.txt"))) { -// StringBuilder sb = new StringBuilder(); -// String line = br.readLine(); -// int i = 0; -// while (line != null) { -// String lines = line.split(",")[0]; -// sb.append(System.lineSeparator()); -// line = br.readLine(); -// -// //System.out.println(i++); -// -// all.add(lines); -// } -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return all.get(all.size()-1); -// } -// public static String returnSSn(){ -// Listall = new ArrayList<>(); -// try(BufferedReader br = new BufferedReader(new FileReader("src/test/java/gmibank/test-data/test-data.txt"))) { -// StringBuilder sb = new StringBuilder(); -// String line = br.readLine(); -// int i = 0; -// while (line != null) { -// String lines = line.split(",")[4]; -// sb.append(System.lineSeparator()); -// line = br.readLine(); -// -// //System.out.println(i++); -// -// all.add(lines); -// } -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return all.get(all.size()-1); -// } -// public static String returnRole(){ -// Listall = new ArrayList<>(); -// try(BufferedReader br = new BufferedReader(new FileReader("src/test/java/gmibank/test-data/test-data.txt"))) { -// StringBuilder sb = new StringBuilder(); -// String line = br.readLine(); -// int i = 0; -// while (line != null) { -// String lines = line.split(",")[3]; -// sb.append(System.lineSeparator()); -// line = br.readLine(); -// -// //System.out.println(i++); -// -// all.add(lines); -// } -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return all.get(all.size()-1); -// } -// public static String returnFirstName(){ -// Listall = new ArrayList<>(); -// try(BufferedReader br = new BufferedReader(new FileReader("src/test/java/gmibank/test-data/test-data.txt"))) { -// StringBuilder sb = new StringBuilder(); -// String line = br.readLine(); -// int i = 0; -// while (line != null) { -// String lines = line.split(",")[1] ; -// sb.append(System.lineSeparator()); -// line = br.readLine(); -// -// //System.out.println(i++); -// -// all.add(lines); -// } -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return all.get(all.size()-1); -// } -// public static String returnLastName(){ -// Listall = new ArrayList<>(); -// try(BufferedReader br = new BufferedReader(new FileReader("src/test/java/gmibank/test-data/test-data.txt"))) { -// StringBuilder sb = new StringBuilder(); -// String line = br.readLine(); -// int i = 0; -// while (line != null) { -// String lines = line.split(",")[2] ; -// sb.append(System.lineSeparator()); -// line = br.readLine(); -// -// //System.out.println(i++); -// -// all.add(lines); -// } -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return all.get(all.size()-1); -// } -// public static List returnAllSSn(){ -// Listall = new ArrayList<>(); -// try(BufferedReader br = new BufferedReader(new FileReader("src/test/java/gmibank/test-data/test-data.txt"))) { -// StringBuilder sb = new StringBuilder(); -// String line = br.readLine(); -// int i = 0; -// while (line != null) { -// String lines = line.split(",")[4]; -// sb.append(System.lineSeparator()); -// line = br.readLine(); -// -// //System.out.println(i++); -// -// all.add(lines); -// } -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return all; -// } -// -//// public static void main(String[] args) { -//// System.out.println(returnRole()); -//// } -} diff --git a/test/src/test/java/issueTracker/Utilities/ReadTxt.java b/test/src/test/java/issueTracker/Utilities/ReadTxt.java deleted file mode 100644 index 739a73c..0000000 --- a/test/src/test/java/issueTracker/Utilities/ReadTxt.java +++ /dev/null @@ -1,5 +0,0 @@ -package issueTracker.Utilities; - -public class ReadTxt { - -} diff --git a/test/src/test/java/issueTracker/Utilities/ReusableMethods.java b/test/src/test/java/issueTracker/Utilities/ReusableMethods.java new file mode 100644 index 0000000..3dbf156 --- /dev/null +++ b/test/src/test/java/issueTracker/Utilities/ReusableMethods.java @@ -0,0 +1,34 @@ +package issueTracker.Utilities; + +import org.openqa.selenium.WebDriverException; +import org.openqa.selenium.WebElement; + +public class ReusableMethods { + public static void wait(int secs) { + try { + Thread.sleep(1000 * secs); + } catch (InterruptedException e) { + e.printStackTrace(); + } + +} public static void waitAndClick(WebElement element, int timeout) { + for (int i = 0; i < timeout; i++) { + try { + element.click(); + return; + } catch (WebDriverException e) { + wait(1); + } + } + } + public static void waitAndSendText(WebElement element,String text, int timeout) { + for (int i = 0; i < timeout; i++) { + try { + element.sendKeys(text); + return; + } catch (WebDriverException e) { + wait(1); + } + } + } +} diff --git a/test/src/test/java/issueTracker/Utilities/WriteToText.java b/test/src/test/java/issueTracker/Utilities/WriteToText.java deleted file mode 100644 index fb1c3e8..0000000 --- a/test/src/test/java/issueTracker/Utilities/WriteToText.java +++ /dev/null @@ -1,99 +0,0 @@ -package issueTracker.Utilities; - - - -import java.io.BufferedWriter; -import java.io.FileWriter; - -public class WriteToText { -// public static void saveDataInFile(String fileName, Customer[] customers) { -// try { -// BufferedWriter writer = new BufferedWriter(new FileWriter(fileName, true)); -// for (int i=0;i