├── .gitignore ├── README.md ├── Spring2019TestNGFrameworkFinal.iml ├── configuration.properties ├── multi_browser_parallel_testing.xml ├── multi_browser_testing.xml ├── pom.xml ├── regression.xml ├── runner_with_data_provider.xml ├── runner_with_parameters.xml ├── screenshots ├── _verifyDateTest.png ├── _verifyTimeTest.png ├── _verifyTimeTest2.png └── _verifyTodaysDateTest.png ├── smoke_test_using_groups.xml ├── smoketest.xml ├── src ├── main │ └── resources │ │ └── log4j2.xml └── test │ ├── java │ └── com │ │ └── vytrack │ │ ├── pages │ │ ├── activites │ │ │ ├── CalendarEventsPage.java │ │ │ └── CallsPage.java │ │ ├── dashboards │ │ │ ├── DashboardPage.java │ │ │ └── ManageDashboards.java │ │ └── login_navigation │ │ │ └── LoginPage.java │ │ ├── tests │ │ ├── components │ │ │ ├── activities │ │ │ │ └── CalendarEventsTests.java │ │ │ ├── login_navigation │ │ │ │ └── LoginTests.java │ │ │ └── review_sessions_code │ │ │ │ └── WebTableComparisonTest.java │ │ └── smoketest │ │ │ └── SmokeTest.java │ │ └── utilities │ │ ├── BasePage.java │ │ ├── BrowserUtils.java │ │ ├── ConfigurationReader.java │ │ ├── Driver.java │ │ ├── ExcelUtil.java │ │ ├── Pages.java │ │ └── TestBase.java │ └── resources │ ├── Countries.xlsx │ ├── EmployeesTestData.xlsx │ ├── Vytrack testusers.xlsx │ └── ~$Countries.xlsx ├── testngrunner.xml └── testngrunner2.xml /.gitignore: -------------------------------------------------------------------------------- 1 | ### Eclipse ### 2 | .metadata 3 | bin/ 4 | tmp/ 5 | *.tmp 6 | *.bak 7 | *.swp 8 | *~.nib 9 | local.properties 10 | .settings/ 11 | .loadpath 12 | .recommenders 13 | 14 | # External tool builders 15 | .externalToolBuilders/ 16 | 17 | # Locally stored "Eclipse launch configurations" 18 | *.launch 19 | 20 | 21 | # PyDev specific (Python IDE for Eclipse) 22 | *.pydevproject 23 | 24 | # CDT-specific (C/C++ Development Tooling) 25 | .cproject 26 | 27 | # CDT- autotools 28 | .autotools 29 | 30 | # Java annotation processor (APT) 31 | .factorypath 32 | 33 | # PDT-specific (PHP Development Tools) 34 | .buildpath 35 | 36 | # sbteclipse plugin 37 | .target 38 | 39 | # Tern plugin 40 | .tern-project 41 | 42 | # TeXlipse plugin 43 | .texlipse 44 | 45 | # STS (Spring Tool Suite) 46 | .springBeans 47 | 48 | # Code Recommenders 49 | .recommenders/ 50 | 51 | # Annotation Processing 52 | .apt_generated/ 53 | 54 | # Scala IDE specific (Scala & Java development for Eclipse) 55 | .cache-main 56 | .scala_dependencies 57 | .worksheet 58 | 59 | ### Eclipse Patch ### 60 | # Eclipse Core 61 | .project 62 | 63 | # JDT-specific (Eclipse Java Development Tools) 64 | .classpath 65 | 66 | # Annotation Processing 67 | .apt_generated 68 | 69 | .sts4-cache/ 70 | 71 | ### Intellij ### 72 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 73 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 74 | .idea/vcs.xml 75 | 76 | # User-specific stuff 77 | .idea/**/workspace.xml 78 | .idea/**/tasks.xml 79 | .idea/**/usage.statistics.xml 80 | .idea/**/dictionaries 81 | .idea/**/shelf 82 | 83 | # Generated files 84 | .idea/**/contentModel.xml 85 | 86 | # Sensitive or high-churn files 87 | .idea/**/dataSources/ 88 | .idea/**/dataSources.ids 89 | .idea/**/dataSources.local.xml 90 | .idea/**/sqlDataSources.xml 91 | .idea/**/dynamic.xml 92 | .idea/**/uiDesigner.xml 93 | .idea/**/dbnavigator.xml 94 | 95 | # Gradle 96 | .idea/**/gradle.xml 97 | .idea/**/libraries 98 | 99 | # Gradle and Maven with auto-import 100 | # When using Gradle or Maven with auto-import, you should exclude module files, 101 | # since they will be recreated, and may cause churn. Uncomment if using 102 | # auto-import. 103 | # .idea/modules.xml 104 | # .idea/*.iml 105 | # .idea/modules 106 | # *.iml 107 | # *.ipr 108 | 109 | # CMake 110 | cmake-build-*/ 111 | 112 | # Mongo Explorer plugin 113 | .idea/**/mongoSettings.xml 114 | 115 | # File-based project format 116 | *.iws 117 | 118 | # IntelliJ 119 | out/ 120 | 121 | # mpeltonen/sbt-idea plugin 122 | .idea_modules/ 123 | 124 | # JIRA plugin 125 | atlassian-ide-plugin.xml 126 | 127 | # Cursive Clojure plugin 128 | .idea/replstate.xml 129 | 130 | # Crashlytics plugin (for Android Studio and IntelliJ) 131 | com_crashlytics_export_strings.xml 132 | crashlytics.properties 133 | crashlytics-build.properties 134 | fabric.properties 135 | 136 | # Editor-based Rest Client 137 | .idea/httpRequests 138 | 139 | # Android studio 3.1+ serialized cache file 140 | .idea/caches/build_file_checksums.ser 141 | 142 | ### Intellij Patch ### 143 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 144 | 145 | # *.iml 146 | # modules.xml 147 | # .idea/misc.xml 148 | # *.ipr 149 | 150 | # Sonarlint plugin 151 | .idea/sonarlint 152 | 153 | ### Java ### 154 | # Compiled class file 155 | *.class 156 | 157 | # Log file 158 | *.log 159 | 160 | # BlueJ files 161 | *.ctxt 162 | 163 | # Mobile Tools for Java (J2ME) 164 | .mtj.tmp/ 165 | 166 | # Package Files # 167 | *.jar 168 | *.war 169 | *.nar 170 | *.ear 171 | *.zip 172 | *.tar.gz 173 | *.rar 174 | 175 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 176 | hs_err_pid* 177 | 178 | ### Maven ### 179 | target/ 180 | pom.xml.tag 181 | pom.xml.releaseBackup 182 | pom.xml.versionsBackup 183 | pom.xml.next 184 | release.properties 185 | dependency-reduced-pom.xml 186 | buildNumber.properties 187 | .mvn/timing.properties 188 | .mvn/wrapper/maven-wrapper.jar 189 | 190 | ### OSX ### 191 | # General 192 | .DS_Store 193 | .AppleDouble 194 | .LSOverride 195 | 196 | # Icon must end with two \r 197 | Icon 198 | 199 | # Thumbnails 200 | ._* 201 | 202 | # Files that might appear in the root of a volume 203 | .DocumentRevisions-V100 204 | .fseventsd 205 | .Spotlight-V100 206 | .TemporaryItems 207 | .Trashes 208 | .VolumeIcon.icns 209 | .com.apple.timemachine.donotpresent 210 | 211 | # Directories potentially created on remote AFP share 212 | .AppleDB 213 | .AppleDesktop 214 | Network Trash Folder 215 | Temporary Items 216 | .apdisk 217 | itwillbeignored.txt 218 | 219 | test-output/ 220 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spring2019FinalTestNGFramework 2 | 3 | In order to run specific xml file: *mvn clean verify -P Parameterized -Drunner=smoketest.xml* 4 | -------------------------------------------------------------------------------- /Spring2019TestNGFrameworkFinal.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /configuration.properties: -------------------------------------------------------------------------------- 1 | #######BROWSER CONFIG 2 | browser=firefox 3 | environment=qa2 4 | 5 | ######CREDENTIALS 6 | storemanagerusername=storemanager85 7 | storemanagerpassword=UserUser123 8 | 9 | salesmanagerusername=salesmanager110 10 | salesmanagerpassword=UserUser123 11 | 12 | #####Environments 13 | urlqa1=http://qa1.vytrack.com/user/login 14 | urlqa2=http://qa2.vytrack.com/user/login 15 | urlqa3=http://qa3.vytrack.com/user/login 16 | 17 | #########WAITS 18 | SHORT_WAIT=8 19 | MEDIUM_WAIT=15 20 | LONG_WAIT=30 21 | explicitwait=5 22 | implicitwait=5 23 | 24 | 25 | -------------------------------------------------------------------------------- /multi_browser_parallel_testing.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /multi_browser_testing.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.vytrack 8 | Spring2019TestNGFrameworkFinal 9 | 1.0-SNAPSHOT 10 | 11 | 1.8 12 | 1.8 13 | UTF-8 14 | 15 | 16 | 17 | 18 | org.apache.maven.plugins 19 | maven-surefire-plugin 20 | 3.0.0-M3 21 | 22 | 23 | smoketest.xml 24 | 25 | 26 | 27 | 28 | org.apache.maven.plugins 29 | maven-compiler-plugin 30 | 31 | 8 32 | 8 33 | 34 | 35 | 36 | 37 | 38 | 39 | Parameterized 40 | 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-compiler-plugin 45 | 46 | 8 47 | 8 48 | 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-surefire-plugin 53 | 3.0.0-M3 54 | 55 | classes 56 | perthread 57 | 2 58 | 2 59 | false 60 | -Duser.language=en 61 | -Xmx1024m 62 | -XX:MaxPermSize=256m 63 | -Dfile.encoding=UTF-8 64 | false 65 | 66 | 67 | ${runner} 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | Parallel 76 | 77 | 78 | 79 | org.apache.maven.plugins 80 | maven-surefire-plugin 81 | 3.0.0-M3 82 | 83 | classes 84 | perthread 85 | 3 86 | 3 87 | false 88 | -Duser.language=en 89 | -Xmx1024m 90 | -XX:MaxPermSize=256m 91 | -Dfile.encoding=UTF-8 92 | false 93 | 94 | testngrunner.xml 95 | testngrunner2.xml 96 | smoketest.xml 97 | 98 | 99 | 100 | 101 | org.apache.maven.plugins 102 | maven-compiler-plugin 103 | 104 | 8 105 | 8 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | org.seleniumhq.selenium 115 | selenium-java 116 | 3.141.59 117 | 118 | 119 | io.github.bonigarcia 120 | webdrivermanager 121 | 3.7.0 122 | test 123 | 124 | 125 | com.github.javafaker 126 | javafaker 127 | 0.18 128 | 129 | 130 | org.testng 131 | testng 132 | 6.14.3 133 | test 134 | 135 | 136 | com.aventstack 137 | extentreports 138 | 4.0.6 139 | 140 | 141 | org.apache.logging.log4j 142 | log4j-api 143 | 2.12.0 144 | 145 | 146 | org.apache.logging.log4j 147 | log4j-core 148 | 2.12.0 149 | 150 | 151 | org.slf4j 152 | slf4j-simple 153 | 1.7.21 154 | 155 | 156 | org.apache.poi 157 | poi 158 | 4.1.0 159 | 160 | 161 | org.apache.poi 162 | poi-ooxml 163 | 4.1.0 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /regression.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /runner_with_data_provider.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /runner_with_parameters.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /screenshots/_verifyDateTest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybertek-B11/Spring2019FinalTestNGFramework/ba0adde5d43af9b5365bcade65bbc89f39264d13/screenshots/_verifyDateTest.png -------------------------------------------------------------------------------- /screenshots/_verifyTimeTest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybertek-B11/Spring2019FinalTestNGFramework/ba0adde5d43af9b5365bcade65bbc89f39264d13/screenshots/_verifyTimeTest.png -------------------------------------------------------------------------------- /screenshots/_verifyTimeTest2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybertek-B11/Spring2019FinalTestNGFramework/ba0adde5d43af9b5365bcade65bbc89f39264d13/screenshots/_verifyTimeTest2.png -------------------------------------------------------------------------------- /screenshots/_verifyTodaysDateTest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybertek-B11/Spring2019FinalTestNGFramework/ba0adde5d43af9b5365bcade65bbc89f39264d13/screenshots/_verifyTodaysDateTest.png -------------------------------------------------------------------------------- /smoke_test_using_groups.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /smoketest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/pages/activites/CalendarEventsPage.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.pages.activites; 2 | 3 | import com.vytrack.utilities.BasePage; 4 | import com.vytrack.utilities.BrowserUtils; 5 | import com.vytrack.utilities.ConfigurationReader; 6 | import com.vytrack.utilities.Driver; 7 | import org.openqa.selenium.By; 8 | import org.openqa.selenium.WebElement; 9 | import org.openqa.selenium.support.FindBy; 10 | import org.openqa.selenium.support.PageFactory; 11 | import org.openqa.selenium.support.ui.ExpectedConditions; 12 | import org.openqa.selenium.support.ui.Select; 13 | import org.openqa.selenium.support.ui.WebDriverWait; 14 | 15 | import java.time.LocalDate; 16 | import java.time.LocalDateTime; 17 | import java.time.LocalTime; 18 | import java.time.format.DateTimeFormatter; 19 | import java.time.temporal.ChronoUnit; 20 | import java.util.List; 21 | 22 | public class CalendarEventsPage extends BasePage { 23 | @FindBy(css = "[title='Create Calendar event']") 24 | public WebElement createCalendarEventBtn; 25 | 26 | @FindBy(css = "a[title='Grid Settings']") 27 | public WebElement gridSettingsElement; 28 | 29 | @FindBy(css = "a[title='Reset']") 30 | public WebElement resetBtnElement; 31 | 32 | @FindBy(css = ".grid-header-cell__label") 33 | public List headers; 34 | 35 | @FindBy(css = "[id^='date_selector_oro_calendar_event_form_start']") 36 | public WebElement startDate; 37 | @FindBy(css = "[id^='date_selector_oro_calendar_event_form_end']") 38 | public WebElement endDate; 39 | 40 | @FindBy(css = "[id^='time_selector_oro_calendar_event_form_start']") 41 | public WebElement startTime; 42 | 43 | @FindBy(css = "[id^='time_selector_oro_calendar_event_form_end']") 44 | public WebElement endTime; 45 | 46 | @FindBy(css = "select[class='ui-timepicker-wrapper']") 47 | public WebElement timeDropdown; 48 | 49 | @FindBy(css = "select[class='ui-datepicker-month']") 50 | public WebElement monthDropdown; 51 | 52 | @FindBy(css = "select[class='ui-datepicker-year']") 53 | public WebElement yearDropdown; 54 | 55 | @FindBy(css = "[id^='recurrence-repeat-view']") 56 | public WebElement repeatCheckbox; 57 | 58 | 59 | public void selectGridSetting(String name, boolean yesOrNo) { 60 | //click on grid options 61 | waitUntilLoaderScreenDisappear(); 62 | gridSettingsElement.click(); 63 | //create locator for grid option based on the name 64 | String locator = "//td//label[text()='" + name + "']/../following-sibling::td//input"; 65 | //find element 66 | //you can also call Driver.get() 67 | WebElement gridOption = Driver.getDriver().findElement(By.xpath(locator)); 68 | //if param yesOrNo is true, and checkbox is not selected yet 69 | //click on it 70 | //or 71 | //ckeckbox is selected and you want to unselect it 72 | if ((yesOrNo == true && !gridOption.isSelected()) || ( 73 | yesOrNo == false && gridOption.isSelected())) { 74 | gridOption.click(); 75 | } 76 | } 77 | 78 | public boolean verifyHeaderExists(String headerNameOrColumnName) { 79 | for (WebElement tableHeader : headers) { 80 | if (tableHeader.getText().equalsIgnoreCase(headerNameOrColumnName)) { 81 | return true; 82 | } 83 | } 84 | return false; 85 | } 86 | 87 | /** 88 | * Simple method that can select start or end date on create calendar event page 89 | * 90 | * @param date format MM/dd/yyy for example 12/12/2019 91 | * @param startOrEnd which date to click on start or end 92 | */ 93 | public void selectStartOrEndDate(String date, String startOrEnd) { 94 | waitUntilLoaderScreenDisappear(); 95 | LocalDate ld = LocalDate.of(Integer.parseInt(date.substring(date.lastIndexOf("/") + 1)), 96 | Integer.parseInt(date.substring(0, date.indexOf("/"))), 97 | Integer.parseInt(date.substring(date.indexOf("/") + 1, date.lastIndexOf("/")))); 98 | 99 | String month = DateTimeFormatter.ofPattern("MMM").format(ld); 100 | int year = ld.getYear(); 101 | int day = ld.getDayOfMonth(); 102 | 103 | 104 | //locator for day 105 | String dayLocator = "//a[@class='ui-state-default' and text()='" + day + "']"; 106 | 107 | //click on start or end date 108 | if (startOrEnd.equalsIgnoreCase("start")) { 109 | BrowserUtils.waitForVisibility(startDate, 5); 110 | startDate.click(); 111 | } else { 112 | BrowserUtils.waitForVisibility(endDate, 5); 113 | endDate.click(); 114 | } 115 | 116 | //select month 117 | new Select(monthDropdown).selectByVisibleText(month); 118 | 119 | 120 | //select year 121 | new Select(yearDropdown).selectByVisibleText(year + ""); 122 | 123 | //select day 124 | Driver.getDriver().findElement(By.xpath(dayLocator)).click(); 125 | } 126 | 127 | public void selectTomorrowDay() { 128 | int day = LocalDate.now().plusDays(1).getDayOfMonth(); 129 | int month = LocalDate.now().plusDays(1).getMonth().getValue(); 130 | waitUntilLoaderScreenDisappear(); 131 | startDate.click(); 132 | Select monthSelect = new Select(monthDropdown); 133 | monthSelect.selectByIndex(month - 1); 134 | String dayLocator = "//table[@class='ui-datepicker-calendar']//a[text()='" + day + "']"; 135 | Driver.getDriver().findElement(By.xpath(dayLocator)).click(); 136 | } 137 | 138 | 139 | public void selectADay(int plusDays) { 140 | int day = LocalDate.now().plusDays(plusDays).getDayOfMonth(); 141 | int month = LocalDate.now().plusDays(plusDays).getMonth().getValue(); 142 | waitUntilLoaderScreenDisappear(); 143 | startDate.click(); 144 | Select monthSelect = new Select(monthDropdown); 145 | monthSelect.selectByIndex(month - 1); 146 | String dayLocator = "//table[@class='ui-datepicker-calendar']//a[text()='" + day + "']"; 147 | Driver.getDriver().findElement(By.xpath(dayLocator)).click(); 148 | } 149 | 150 | public void selectTodaysDate() { 151 | int day = LocalDate.now().getDayOfMonth(); 152 | startDate.click(); 153 | String dayLocator = "//table[@class='ui-datepicker-calendar']//a[text()='" + day + "']"; 154 | try { 155 | Driver.getDriver().findElement(By.xpath(dayLocator)).click(); 156 | } catch (Exception e) { 157 | try { 158 | Thread.sleep(1000); 159 | } catch (InterruptedException ex) { 160 | ex.printStackTrace(); 161 | } 162 | Driver.getDriver().findElement(By.xpath(dayLocator)).click(); 163 | } 164 | } 165 | 166 | public void selectStartTime(int plusHours) { 167 | String time = LocalDateTime.now().plusHours(plusHours).format(DateTimeFormatter.ofPattern("h:00 a")); 168 | waitUntilLoaderScreenDisappear(); 169 | String startTimeToSelect = "(//li[text()='" + time + "'])[1]"; 170 | startTime.click(); 171 | new WebDriverWait(Driver.getDriver(), 10).until(ExpectedConditions.presenceOfElementLocated(By.xpath(startTimeToSelect))); 172 | Driver.getDriver().findElement(By.xpath(startTimeToSelect)).click(); 173 | } 174 | 175 | public void selectStartTime(String time) { 176 | waitUntilLoaderScreenDisappear(); 177 | String startTimeToSelect = "(//li[text()='" + time + "'])[1]"; 178 | startTime.click(); 179 | new WebDriverWait(Driver.getDriver(), 10).until(ExpectedConditions.presenceOfElementLocated(By.xpath(startTimeToSelect))); 180 | Driver.getDriver().findElement(By.xpath(startTimeToSelect)).click(); 181 | } 182 | 183 | public void selectEndTime(String time) { 184 | waitUntilLoaderScreenDisappear(); 185 | String endTimeToSelect = "(//li[text()='" + time + "'])[2]"; 186 | startTime.click(); 187 | Driver.getDriver().findElement(By.xpath(endTimeToSelect)).click(); 188 | } 189 | 190 | public long differenceBetweenStartTimeAndEndTime() { 191 | LocalTime actualStartTime = LocalTime.parse(startTime.getAttribute("value"), DateTimeFormatter.ofPattern("h:mm a")); 192 | try { 193 | new WebDriverWait(Driver.getDriver(), 3).until(ExpectedConditions.invisibilityOf(startTime)); 194 | } catch (Exception e) { 195 | System.out.println(e); 196 | } 197 | LocalTime actualEndTime = LocalTime.parse(endTime.getAttribute("value"), DateTimeFormatter.ofPattern("h:mm a")); 198 | return ChronoUnit.HOURS.between(actualStartTime, actualEndTime); 199 | } 200 | 201 | public void clickOnCreateCalendarEvent() { 202 | waitUntilLoaderScreenDisappear(); 203 | BrowserUtils.waitForStaleElement(createCalendarEventBtn); 204 | BrowserUtils.waitForClickablility(createCalendarEventBtn, Integer.valueOf(ConfigurationReader.getProperty("SHORT_WAIT"))); 205 | createCalendarEventBtn.click(); 206 | } 207 | 208 | public String getStartDate() { 209 | return startDate.getAttribute("value"); 210 | } 211 | 212 | public String getEndDate() { 213 | return endDate.getAttribute("value"); 214 | } 215 | 216 | public String getSartTime() { 217 | return startTime.getAttribute("value"); 218 | } 219 | 220 | public String getEndTime() { 221 | return endTime.getAttribute("value"); 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/pages/activites/CallsPage.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.pages.activites; 2 | 3 | import com.vytrack.utilities.BasePage; 4 | import com.vytrack.utilities.Driver; 5 | import org.openqa.selenium.support.PageFactory; 6 | 7 | public class CallsPage extends BasePage { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/pages/dashboards/DashboardPage.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.pages.dashboards; 2 | 3 | import com.vytrack.utilities.BasePage; 4 | import com.vytrack.utilities.Driver; 5 | import org.openqa.selenium.support.PageFactory; 6 | 7 | public class DashboardPage extends BasePage { 8 | public DashboardPage() { 9 | PageFactory.initElements(Driver.getDriver(), this); 10 | 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/pages/dashboards/ManageDashboards.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.pages.dashboards; 2 | 3 | import com.vytrack.utilities.BasePage; 4 | 5 | public class ManageDashboards extends BasePage { 6 | } 7 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/pages/login_navigation/LoginPage.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.pages.login_navigation; 2 | 3 | import com.vytrack.utilities.BrowserUtils; 4 | import com.vytrack.utilities.ConfigurationReader; 5 | import com.vytrack.utilities.Driver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.support.CacheLookup; 8 | import org.openqa.selenium.support.FindBy; 9 | import org.openqa.selenium.support.PageFactory; 10 | 11 | public class LoginPage { 12 | public LoginPage(){PageFactory.initElements(Driver.getDriver(), this);} 13 | 14 | @FindBy(id = "prependedInput") 15 | @CacheLookup 16 | public WebElement userNameElement; 17 | 18 | @FindBy(name = "_password") 19 | @CacheLookup 20 | public WebElement passwordElement; 21 | 22 | @FindBy(id="_submit") 23 | public WebElement loginButtonElement; 24 | 25 | @FindBy(className = "custom-checkbox__icon") 26 | public WebElement rememberMeElement; 27 | 28 | @FindBy(partialLinkText = "Forgot your password?") 29 | public WebElement forgotPasswordElement; 30 | 31 | @FindBy(tagName = "h2") 32 | public WebElement titleElement; 33 | 34 | @FindBy(css = "[class='alert alert-error'] > div") 35 | public WebElement errorMessageElement; 36 | 37 | 38 | public void login(String username, String password){ 39 | userNameElement.sendKeys(username); 40 | passwordElement.sendKeys(password); 41 | loginButtonElement.click(); 42 | } 43 | 44 | public void login(){ 45 | String username = ConfigurationReader.getProperty("storemanagerusername"); 46 | String password = ConfigurationReader.getProperty("storemanagerpassword"); 47 | userNameElement.sendKeys(username); 48 | passwordElement.sendKeys(password); 49 | loginButtonElement.click(); 50 | } 51 | 52 | public String getErrorMessage(){ 53 | return errorMessageElement.getText(); 54 | } 55 | 56 | public void clickRememberMe(){ 57 | BrowserUtils.waitForClickablility(rememberMeElement, Integer.valueOf(ConfigurationReader.getProperty("SHORT_WAIT"))); 58 | if(!rememberMeElement.isSelected()){ 59 | rememberMeElement.click(); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/tests/components/activities/CalendarEventsTests.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.tests.components.activities; 2 | 3 | import com.vytrack.utilities.BrowserUtils; 4 | import com.vytrack.utilities.ConfigurationReader; 5 | import com.vytrack.utilities.TestBase; 6 | import org.testng.Assert; 7 | import org.testng.annotations.Test; 8 | 9 | public class CalendarEventsTests extends TestBase { 10 | 11 | @Test 12 | public void verifyTitleColumn() { 13 | extentLogger = report.createTest("Verify column that column names are adjustable"); 14 | String username = ConfigurationReader.getProperty("storemanagerusername"); 15 | String password = ConfigurationReader.getProperty("storemanagerpassword"); 16 | //login 17 | pages.loginPage().login(username, password); 18 | 19 | //go to Calendar Events page 20 | 21 | pages.dashboardPage().navigateToModule("Activities", "Calendar Events"); 22 | 23 | //deselect title option from grid settings 24 | pages.calendarEventsPage().selectGridSetting("Title", false); 25 | BrowserUtils.waitPlease(3); 26 | 27 | //Verify that title column name is not visible any more 28 | Assert.assertFalse(pages.calendarEventsPage().verifyHeaderExists("Title"), "Title column name still visible."); 29 | extentLogger.pass("Verified that title column name is not visible any more."); 30 | 31 | //to close grid settings menu 32 | pages.calendarEventsPage().gridSettingsElement.click(); 33 | extentLogger.info("Click on grid settings button."); 34 | 35 | //select title option again 36 | pages.calendarEventsPage().selectGridSetting("Title", true); 37 | 38 | //Verify that title column name is visible again 39 | Assert.assertTrue(pages.calendarEventsPage().verifyHeaderExists("Title"), "Title column is not visible."); 40 | extentLogger.pass("Verified that title column name is visible again."); 41 | } 42 | 43 | @Test(description = "Verify that date auto adjustable") 44 | public void verifyDateTest() { 45 | extentLogger = report.createTest("Verify column that date is adjustable"); 46 | 47 | String username = ConfigurationReader.getProperty("storemanagerusername"); 48 | String password = ConfigurationReader.getProperty("storemanagerpassword"); 49 | //login 50 | pages.loginPage().login(username, password); 51 | 52 | //go to Calendar Events page 53 | pages.dashboardPage().navigateToModule("Activities", "Calendar Events"); 54 | 55 | pages.calendarEventsPage().clickOnCreateCalendarEvent(); 56 | extentLogger.info("Click on create calendar event button."); 57 | 58 | pages.calendarEventsPage().selectStartOrEndDate("8/15/2019", "start"); 59 | 60 | // verify start date is the same as end date 61 | Assert.assertEquals(pages.calendarEventsPage().getStartDate(), pages.calendarEventsPage().getEndDate()); 62 | extentLogger.pass("Verified start date is the same as end date"); 63 | 64 | 65 | } 66 | 67 | @Test(description = "Verify that date auto adjustable with today's and tomorrow's date.") 68 | public void verifyTodaysDateTest() { 69 | extentLogger = report.createTest("Verify that date auto adjustable with today's and tomorrow's date."); 70 | 71 | String username = ConfigurationReader.getProperty("storemanagerusername"); 72 | String password = ConfigurationReader.getProperty("storemanagerpassword"); 73 | //login 74 | pages.loginPage().login(username, password); 75 | 76 | //go to Calendar Events page 77 | pages.dashboardPage().navigateToModule("Activities", "Calendar Events"); 78 | 79 | //click to create calendar event 80 | pages.calendarEventsPage().clickOnCreateCalendarEvent(); 81 | extentLogger.info("Click on create calendar event button."); 82 | 83 | //select tomorrow date 84 | pages.calendarEventsPage().selectTomorrowDay(); 85 | extentLogger.info("Select tomorrows date."); 86 | 87 | Assert.assertEquals(pages.calendarEventsPage().getStartDate(), pages.calendarEventsPage().getEndDate()); 88 | extentLogger.pass("Verified that start date is equals to today's date."); 89 | 90 | //select today's date 91 | pages.calendarEventsPage().selectTodaysDate(); 92 | 93 | //verify that start and end date is the same 94 | Assert.assertEquals(pages.calendarEventsPage().getStartDate(), pages.calendarEventsPage().getEndDate()); 95 | extentLogger.pass("Verified that start date is equals to today's date."); 96 | 97 | } 98 | 99 | @Test(description = "Verify that end time changes exactly 1 hour later.") 100 | public void verifyTimeTest() { 101 | extentLogger = report.createTest("Verify that end time changes exactly 1 hours later"); 102 | 103 | String username = ConfigurationReader.getProperty("storemanagerusername"); 104 | String password = ConfigurationReader.getProperty("storemanagerpassword"); 105 | //login 106 | pages.loginPage().login(username, password); 107 | 108 | //go to Calendar Events page 109 | pages.dashboardPage().navigateToModule("Activities", "Calendar Events"); 110 | 111 | //click to create calendar event 112 | pages.calendarEventsPage().clickOnCreateCalendarEvent(); 113 | extentLogger.info("Click on create calendar event button."); 114 | 115 | //select any time 116 | pages.calendarEventsPage().selectStartTime("1:00 PM"); 117 | extentLogger.info("Select start time as 1:00 PM"); 118 | 119 | //Verify that end time changes exactly 1 hour later 120 | Assert.assertEquals(pages.calendarEventsPage().differenceBetweenStartTimeAndEndTime(), 1); 121 | extentLogger.pass("Verified that end time exactly 1 hour later."); 122 | 123 | } 124 | 125 | @Test(description = "Verify that end time is 12:30 AM") 126 | public void verifyTimeTest2() { 127 | extentLogger = report.createTest("Verify that end time is 12:30 AM"); 128 | 129 | String username = ConfigurationReader.getProperty("storemanagerusername"); 130 | String password = ConfigurationReader.getProperty("storemanagerpassword"); 131 | //login 132 | pages.loginPage().login(username, password); 133 | 134 | //go to Calendar Events page 135 | pages.dashboardPage().navigateToModule("Activities", "Calendar Events"); 136 | 137 | //click to create calendar event 138 | pages.calendarEventsPage().clickOnCreateCalendarEvent(); 139 | extentLogger.info("Click on create calendar event button."); 140 | 141 | //select 11:30 PM 142 | pages.calendarEventsPage().selectStartTime("11:30 PM"); 143 | extentLogger.info("Select start time: 1:30 PM"); 144 | 145 | //Verify that end time is 12:30 AM 146 | Assert.assertEquals(pages.calendarEventsPage().getEndTime(), "12:30 AM"); 147 | extentLogger.pass("Verified that end time is 12:30 AM."); 148 | } 149 | 150 | } 151 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/tests/components/login_navigation/LoginTests.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.tests.components.login_navigation; 2 | 3 | import com.vytrack.pages.dashboards.DashboardPage; 4 | import com.vytrack.pages.login_navigation.LoginPage; 5 | import com.vytrack.utilities.ConfigurationReader; 6 | import com.vytrack.utilities.ExcelUtil; 7 | import com.vytrack.utilities.TestBase; 8 | import org.testng.Assert; 9 | import org.testng.annotations.DataProvider; 10 | import org.testng.annotations.Parameters; 11 | import org.testng.annotations.Test; 12 | 13 | public class LoginTests extends TestBase { 14 | 15 | @Test 16 | public void loginTest1() { 17 | extentLogger = report.createTest("Login as store manager"); 18 | 19 | //we are instantiating page class inside a tests class, 20 | //because for second test, if we run all tests in a row, driver will have null session 21 | String username = ConfigurationReader.getProperty("storemanagerusername"); 22 | String password = ConfigurationReader.getProperty("storemanagerpassword"); 23 | pages.loginPage().clickRememberMe(); 24 | pages.loginPage().login(username, password); 25 | //to verify that Dashboard page opened 26 | //Once page name Dashboard displays, means that we are logged successfully 27 | Assert.assertEquals(pages.dashboardPage().getPageSubTitle(), "Dashboard"); 28 | extentLogger.pass("Verified page name: " + pages.dashboardPage().getPageSubTitle()); 29 | } 30 | 31 | @Test(description = "Login with invalid credentials and verify warning message") 32 | public void negativeLoginTest1() { 33 | extentLogger = report.createTest("Negative login test"); 34 | extentLogger.info("Login with wrongusername username and wrongpassword password"); 35 | pages.loginPage().login("wrongusername", "wrongpassword"); 36 | Assert.assertEquals(pages.loginPage().getErrorMessage(), "Invalid user name or password."); 37 | extentLogger.pass("Verified that Message present: " + pages.loginPage().getErrorMessage()); 38 | } 39 | 40 | 41 | @Test 42 | @Parameters({ "username", "password" }) // get data from data testng.xml 43 | public void loginWithParameters(String username, String password) { 44 | extentLogger = report.createTest("Login as store manager"); 45 | 46 | //we are instantiating page class inside a tests class, 47 | //because for second test, if we run all tests in a row, driver will have null session 48 | pages.loginPage().clickRememberMe(); 49 | pages.loginPage().login(username, password); 50 | //to verify that Dashboard page opened 51 | //Once page name Dashboard displays, means that we are logged successfully 52 | Assert.assertEquals(pages.dashboardPage().getPageSubTitle(), "Dashboard"); 53 | extentLogger.pass("Verified page name: " + pages.dashboardPage().getPageSubTitle()); 54 | } 55 | 56 | @Test(dataProvider = "credentials_info") // get data from data provider 57 | public void loginWithDataProvider(String username, String password) { 58 | extentLogger = report.createTest("Login as store manager"); 59 | System.out.println(username+" :: "+password); 60 | //we are instantiating page class inside a tests class, 61 | //because for second test, if we run all tests in a row, driver will have null session 62 | pages.loginPage().clickRememberMe(); 63 | pages.loginPage().login(username, password); 64 | //to verify that Dashboard page opened 65 | //Once page name Dashboard displays, means that we are logged successfully 66 | Assert.assertEquals(pages.dashboardPage().getPageSubTitle(), "Dashboard"); 67 | extentLogger.pass("Verified page name: " + pages.dashboardPage().getPageSubTitle()); 68 | } 69 | 70 | @DataProvider(name = "credentials_info") 71 | public static Object[][] credentials() { 72 | return new Object[][] { { "storemanager85", "UserUser123" }, 73 | { "salesmanager110", "UserUser123" }}; 74 | 75 | } 76 | 77 | 78 | @Test(description = "Login with invalid credentials and verify warning message") 79 | public void negativeLoginTest2() { 80 | extentLogger = report.createTest("Negative login test"); 81 | extentLogger.info("Login with wrongusername username and wrongpassword password"); 82 | pages.loginPage().login("wrongusername", "wrongpassword"); 83 | softAssert.assertEquals(pages.loginPage().getErrorMessage(), "Invalid user name or password."); 84 | extentLogger.pass("Verified that Message present: " + pages.loginPage().getErrorMessage()); 85 | } 86 | 87 | 88 | 89 | @Test(dataProvider = "credentials_list") // get data from data provider 90 | public void loginWithDataProvider(String execute, String username, String password, String firstname, String lastname, String result) { 91 | extentLogger = report.createTest("DDT test" + username); 92 | if (execute.equals("y")) { 93 | new LoginPage().login(username, password); 94 | DashboardPage dashboardPage = new DashboardPage(); 95 | String actualFullName = dashboardPage.userFullName.getText(); 96 | String expectedFullName = firstname+lastname; 97 | Assert.assertEquals(actualFullName, expectedFullName); 98 | dashboardPage.logOut(); 99 | } 100 | } 101 | 102 | @DataProvider(name = "credentials_list") 103 | public static Object[][] credentials1 () { 104 | ExcelUtil qa3 = new ExcelUtil("src/test/resources/Vytrack testusers.xlsx", "QA3-short"); 105 | return qa3.getDataArray(); 106 | } 107 | 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/tests/components/review_sessions_code/WebTableComparisonTest.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.tests.components.review_sessions_code; 2 | 3 | import com.vytrack.utilities.BrowserUtils; 4 | import com.vytrack.utilities.Driver; 5 | import io.github.bonigarcia.wdm.WebDriverManager; 6 | import org.openqa.selenium.By; 7 | import org.openqa.selenium.WebDriver; 8 | import org.testng.annotations.Test; 9 | 10 | public class WebTableComparisonTest { 11 | 12 | @Test 13 | public void test(){ 14 | WebDriver driver = Driver.getDriver(); 15 | driver.get("http://practice.cybertekschool.com/tables"); 16 | 17 | // get size 18 | int colNum = driver.findElements(By.xpath("//table[@id='table1']/tbody/tr[1]/td")).size(); 19 | int rowNum = driver.findElements(By.xpath("//table[@id='table1']/tbody/tr")).size(); 20 | 21 | System.out.println(colNum); 22 | System.out.println(rowNum); 23 | 24 | for (int i = 1; i <= rowNum; i++) { 25 | for (int j = 1; j <= colNum; j++) { 26 | String xpath1 = "//table[@id='table1']/tbody/tr["+i+"]/td["+j+"]"; 27 | String xpath2 = "//table[@id='table2']/tbody/tr["+i+"]/td["+j+"]"; 28 | 29 | String val1 = driver.findElement(By.xpath(xpath1)).getText(); 30 | String val2 = driver.findElement(By.xpath(xpath2)).getText(); 31 | 32 | System.out.println("val1 = " + val1); 33 | System.out.println("val2 = " + val2); 34 | 35 | System.out.println(); 36 | 37 | } 38 | } 39 | 40 | BrowserUtils.waitFor(4); 41 | driver.quit(); 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/tests/smoketest/SmokeTest.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.tests.smoketest; 2 | 3 | import com.vytrack.utilities.ConfigurationReader; 4 | import com.vytrack.utilities.TestBase; 5 | import org.testng.Assert; 6 | import org.testng.annotations.Test; 7 | 8 | public class SmokeTest extends TestBase { 9 | 10 | @Test(groups= {"smoke"}) 11 | public void verifyDashboards() { 12 | extentLogger = report.createTest("Verify Dashboards module"); 13 | String username = ConfigurationReader.getProperty("storemanagerusername"); 14 | String password = ConfigurationReader.getProperty("storemanagerpassword"); 15 | pages.loginPage().login(username, password); 16 | 17 | pages.dashboardPage().navigateToModule("Dashboards", "Dashboard"); 18 | Assert.assertEquals(pages.dashboardPage().getPageSubTitle(), "Dashboard"); 19 | extentLogger.pass("Verified that Dashboard page opens"); 20 | 21 | pages.dashboardPage().navigateToModule("Dashboards", "Manage Dashboards"); 22 | Assert.assertEquals(pages.dashboardPage().getPageSubTitle(), "All Manage Dashboards"); 23 | extentLogger.pass("Verified that Manage Dashboards page opens"); 24 | } 25 | 26 | @Test(groups= {"smoke"}) 27 | public void verifyFleet() { 28 | extentLogger = report.createTest("Verify Fleet module"); 29 | String username = ConfigurationReader.getProperty("storemanagerusername"); 30 | String password = ConfigurationReader.getProperty("storemanagerpassword"); 31 | pages.loginPage().login(username, password); 32 | 33 | pages.dashboardPage().navigateToModule("Fleet", "Vehicles"); 34 | Assert.assertEquals(pages.dashboardPage().getPageSubTitle(), "All Cars"); 35 | extentLogger.pass("Verified that Vehicles page opens"); 36 | 37 | pages.dashboardPage().navigateToModule("Fleet", "Vehicle Costs"); 38 | Assert.assertEquals(pages.dashboardPage().getPageSubTitle(), "All Vehicle Costs"); 39 | extentLogger.pass("Verified that Vehicle Costs page opens"); 40 | 41 | pages.dashboardPage().navigateToModule("Fleet", "Vehicle Contracts"); 42 | Assert.assertEquals(pages.dashboardPage().getPageSubTitle(), "All Vehicle Contract"); 43 | extentLogger.pass("Verified that Vehicle Contracts page opens"); 44 | 45 | } 46 | 47 | @Test(groups= {"smoke"}) 48 | public void verifySales() { 49 | extentLogger = report.createTest("Verify Sales module"); 50 | String username = ConfigurationReader.getProperty("storemanagerusername"); 51 | String password = ConfigurationReader.getProperty("storemanagerpassword"); 52 | pages.loginPage().login(username, password); 53 | 54 | pages.dashboardPage().navigateToModule("Sales", "Opportunities"); 55 | Assert.assertEquals(pages.dashboardPage().getPageSubTitle(), "Open Opportunities"); 56 | extentLogger.pass("Verified that Opportunities page opens"); 57 | 58 | 59 | } 60 | 61 | @Test(groups= {"smoke"}) 62 | public void verifySystem() { 63 | extentLogger = report.createTest("Verify System module"); 64 | pages.loginPage().login(); // login with default credentials 65 | pages.dashboardPage().navigateToModule("System", "Jobs"); 66 | Assert.assertEquals(pages.dashboardPage().getPageSubTitle(), "All Jobs List"); 67 | extentLogger.pass("Verified that Jobs page opens"); 68 | } 69 | 70 | @Test(groups= {"smoke"}) 71 | public void verifyMarketing() { 72 | extentLogger = report.createTest("Verify Marketing module"); 73 | pages.loginPage().login(); // login with default credentials 74 | pages.dashboardPage().navigateToModule("Marketing", "Campaigns"); 75 | Assert.assertEquals(pages.dashboardPage().getPageSubTitle(), "All Campaigns"); 76 | extentLogger.pass("Verified that Campaigns page opens"); 77 | } 78 | 79 | @Test(groups= {"smoke"}) 80 | public void verifyCustomers() { 81 | extentLogger = report.createTest("Verify Customers module"); 82 | pages.loginPage().login(); // login with default credentials 83 | pages.dashboardPage().navigateToModule("Customers", "Accounts"); 84 | Assert.assertEquals(pages.dashboardPage().getPageSubTitle(), "All Accounts"); 85 | extentLogger.pass("Verified that Accounts page opens"); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/utilities/BasePage.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.utilities; 2 | import org.apache.logging.log4j.LogManager; 3 | import org.apache.logging.log4j.Logger; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebElement; 6 | import org.openqa.selenium.interactions.Actions; 7 | import org.openqa.selenium.support.CacheLookup; 8 | import org.openqa.selenium.support.FindBy; 9 | import org.openqa.selenium.support.PageFactory; 10 | import org.openqa.selenium.support.ui.ExpectedConditions; 11 | import org.openqa.selenium.support.ui.WebDriverWait; 12 | 13 | public abstract class BasePage { 14 | //we don't want to access these variables outside 15 | private static final Logger logger = LogManager.getLogger(); 16 | 17 | @FindBy(css = "#user-menu>a") 18 | public WebElement userFullName; 19 | 20 | @FindBy(linkText = "Logout") 21 | public WebElement logOutLink; 22 | 23 | @FindBy(css = "div[class='loader-mask shown']") 24 | @CacheLookup 25 | protected WebElement loaderMask; 26 | 27 | @FindBy(css = "h1[class='oro-subtitle']") 28 | protected WebElement pageSubTitle; 29 | 30 | 31 | public BasePage() { 32 | PageFactory.initElements(Driver.getDriver(), this); 33 | } 34 | 35 | 36 | /** 37 | * @return page name, for example: Dashboard 38 | */ 39 | public String getPageSubTitle() { 40 | //ant time we are verifying page name, or page subtitle, loader mask appears 41 | waitUntilLoaderScreenDisappear(); 42 | BrowserUtils.waitForStaleElement(pageSubTitle); 43 | return pageSubTitle.getText(); 44 | } 45 | 46 | 47 | /** 48 | * Waits until loader screen present. If loader screen will not pop up at all, 49 | * NoSuchElementException will be handled bu try/catch block 50 | * Thus, we can continue in any case. 51 | */ 52 | public void waitUntilLoaderScreenDisappear() { 53 | try { 54 | WebDriverWait wait = new WebDriverWait(Driver.getDriver(), 5); 55 | wait.until(ExpectedConditions.invisibilityOf(loaderMask)); 56 | } catch (Exception e) { 57 | logger.error("Loader mask doesn't present."); 58 | System.out.println("Loader mask doesn't present."); 59 | } 60 | } 61 | 62 | /** 63 | * This method will navigate user to the specific module in vytrack application. 64 | * For example: if tab is equals to Activities, and module equals to Calls, 65 | * Then method will navigate user to this page: http://qa2.vytrack.com/call/ 66 | * 67 | * @param tab 68 | * @param module 69 | */ 70 | public void navigateToModule(String tab, String module) { 71 | String tabLocator = "//span[normalize-space()='" + tab + "' and contains(@class, 'title title-level-1')]"; 72 | String moduleLocator = "//span[normalize-space()='" + module + "' and contains(@class, 'title title-level-2')]"; 73 | try { 74 | BrowserUtils.waitForClickablility(By.xpath(tabLocator), Integer.valueOf(ConfigurationReader.getProperty("SHORT_WAIT"))); 75 | WebElement tabElement = Driver.getDriver().findElement(By.xpath(tabLocator)); 76 | new Actions(Driver.getDriver()).moveToElement(tabElement).pause(200).doubleClick(tabElement).build().perform(); 77 | } catch (Exception e) { 78 | logger.error("Failed to click on :: "+tab); 79 | logger.error(e); 80 | BrowserUtils.clickWithWait(By.xpath(tabLocator), Integer.valueOf(ConfigurationReader.getProperty("SHORT_WAIT"))); 81 | } 82 | try { 83 | BrowserUtils.waitForPresenceOfElement(By.xpath(moduleLocator), Integer.valueOf(ConfigurationReader.getProperty("SHORT_WAIT"))); 84 | BrowserUtils.waitForVisibility(By.xpath(moduleLocator), Integer.valueOf(ConfigurationReader.getProperty("SHORT_WAIT"))); 85 | BrowserUtils.scrollToElement(Driver.getDriver().findElement(By.xpath(moduleLocator))); 86 | Driver.getDriver().findElement(By.xpath(moduleLocator)).click(); 87 | } catch (Exception e) { 88 | logger.error("Failed to click on :: "+module); 89 | logger.error(e); 90 | BrowserUtils.waitForStaleElement(Driver.getDriver().findElement(By.xpath(moduleLocator))); 91 | BrowserUtils.clickWithTimeOut(Driver.getDriver().findElement(By.xpath(moduleLocator)), Integer.valueOf(ConfigurationReader.getProperty("SHORT_WAIT"))); 92 | } 93 | } 94 | 95 | public void logOut(){ 96 | BrowserUtils.waitFor(2); 97 | BrowserUtils.clickWithJS(userFullName); 98 | BrowserUtils.clickWithJS(logOutLink); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/utilities/BrowserUtils.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.utilities; 2 | 3 | import org.apache.commons.io.FileUtils; 4 | import org.apache.logging.log4j.LogManager; 5 | import org.apache.logging.log4j.Logger; 6 | import org.openqa.selenium.*; 7 | import org.openqa.selenium.interactions.Actions; 8 | import org.openqa.selenium.support.ui.ExpectedCondition; 9 | import org.openqa.selenium.support.ui.ExpectedConditions; 10 | import org.openqa.selenium.support.ui.WebDriverWait; 11 | import org.testng.Assert; 12 | 13 | import java.io.File; 14 | import java.io.IOException; 15 | import java.text.SimpleDateFormat; 16 | import java.time.LocalDateTime; 17 | import java.time.format.DateTimeFormatter; 18 | import java.util.ArrayList; 19 | import java.util.Date; 20 | import java.util.List; 21 | 22 | import static org.testng.AssertJUnit.assertTrue; 23 | 24 | public class BrowserUtils { 25 | private static final Logger logger = LogManager.getLogger(); 26 | 27 | /** 28 | * @param expectedResult 29 | * @param actualResult Verifies if two strings are equals. 30 | */ 31 | public static void verifyEquals(String expectedResult, String actualResult) { 32 | if (expectedResult.equals(actualResult)) { 33 | System.out.println("Passed"); 34 | } else { 35 | System.out.println("Failed"); 36 | System.out.println("Expected result: " + expectedResult); 37 | System.out.println("Actual result: " + actualResult); 38 | } 39 | } 40 | 41 | /** 42 | * This method will put on pause execution 43 | * 44 | * @param seconds 45 | */ 46 | public static void waitPlease(int seconds) { 47 | try { 48 | Thread.sleep(seconds * 1000); 49 | } catch (Exception e) { 50 | logger.error(e); 51 | System.out.println(e.getMessage()); 52 | } 53 | 54 | } 55 | 56 | /** 57 | * @param page 58 | * @param driver This method will open example page based on link name 59 | */ 60 | public static void openPage(String page, WebDriver driver) { 61 | //we will find all examples on the home page 62 | List listOfExamples = driver.findElements(By.tagName("a")); 63 | for (WebElement example : listOfExamples) { 64 | if (example.getText().contains(page)) { 65 | example.click(); 66 | break; 67 | } 68 | } 69 | } 70 | 71 | public static void verifyIsDisplayed(WebElement element) { 72 | if (element.isDisplayed()) { 73 | System.out.println("PASSED"); 74 | System.out.println(element.getText() + ": is visible"); 75 | } else { 76 | System.out.println("FAILED"); 77 | System.out.println(element.getText() + ": is not visible!"); 78 | } 79 | } 80 | 81 | /** 82 | * This method will recover in case of exception after unsuccessful the click, 83 | * and will try to click on element again. 84 | * 85 | * @param driver 86 | * @param by 87 | * @param attempts 88 | */ 89 | public static void clickWithWait(WebDriver driver, By by, int attempts) { 90 | int counter = 0; 91 | //click on element as many as you specified in attempts parameter 92 | while (counter < attempts) { 93 | try { 94 | //selenium must look for element again 95 | driver.findElement(by).click(); 96 | //if click is successful - then break 97 | break; 98 | } catch (WebDriverException e) { 99 | //if click failed 100 | //print exception 101 | logger.error(e); 102 | //print attempt 103 | logger.error("Attempt :: " + ++counter); 104 | //wait for 1 second, and try to click again 105 | waitPlease(1); 106 | } 107 | } 108 | } 109 | 110 | /** 111 | * This method will recover in case of exception after unsuccessful the click, 112 | * and will try to click on element again. 113 | * 114 | * @param by 115 | * @param attempts 116 | */ 117 | public static void clickWithWait(By by, int attempts) { 118 | int counter = 0; 119 | //click on element as many as you specified in attempts parameter 120 | while (counter < attempts) { 121 | try { 122 | //selenium must look for element again 123 | clickWithJS(Driver.getDriver().findElement(by)); 124 | //if click is successful - then break 125 | break; 126 | } catch (WebDriverException e) { 127 | //if click failed 128 | //print exception 129 | logger.error(e); 130 | //print attempt 131 | logger.error("Attempt :: " + ++counter); 132 | //wait for 1 second, and try to click again 133 | waitPlease(1); 134 | } 135 | } 136 | } 137 | 138 | 139 | /* 140 | * switches to new window by the exact title 141 | */ 142 | public static void switchToWindow(String targetTitle) { 143 | String origin = Driver.getDriver().getWindowHandle(); 144 | for (String handle : Driver.getDriver().getWindowHandles()) { 145 | Driver.getDriver().switchTo().window(handle); 146 | if (Driver.getDriver().getTitle().equals(targetTitle)) { 147 | return; 148 | } 149 | } 150 | Driver.getDriver().switchTo().window(origin); 151 | } 152 | 153 | /** 154 | * Moves the mouse to given element 155 | * 156 | * @param element on which to hover 157 | */ 158 | public static void hover(WebElement element) { 159 | Actions actions = new Actions(Driver.getDriver()); 160 | actions.moveToElement(element).perform(); 161 | } 162 | 163 | /** 164 | * return a list of string from a list of elements 165 | * text 166 | * 167 | * @param list of webelements 168 | * @return 169 | */ 170 | public static List getElementsText(List list) { 171 | List elemTexts = new ArrayList<>(); 172 | for (WebElement el : list) { 173 | if (!el.getText().isEmpty()) { 174 | elemTexts.add(el.getText()); 175 | } 176 | } 177 | return elemTexts; 178 | } 179 | 180 | /** 181 | * Extracts text from list of elements matching the provided locator into new List 182 | * 183 | * @param locator 184 | * @return list of strings 185 | */ 186 | public static List getElementsText(By locator) { 187 | List elems = Driver.getDriver().findElements(locator); 188 | List elemTexts = new ArrayList<>(); 189 | for (WebElement el : elems) { 190 | if (!el.getText().isEmpty()) { 191 | elemTexts.add(el.getText()); 192 | } 193 | } 194 | return elemTexts; 195 | } 196 | 197 | /** 198 | * Performs a pause 199 | * 200 | * @param seconds 201 | */ 202 | public static void waitFor(int seconds) { 203 | try { 204 | Thread.sleep(seconds * 1000); 205 | } catch (InterruptedException e) { 206 | e.printStackTrace(); 207 | } 208 | } 209 | 210 | /** 211 | * Waits for the provided element to be visible on the page 212 | * 213 | * @param element 214 | * @param timeToWaitInSec 215 | * @return 216 | */ 217 | public static WebElement waitForVisibility(WebElement element, int timeToWaitInSec) { 218 | WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeToWaitInSec); 219 | return wait.until(ExpectedConditions.visibilityOf(element)); 220 | } 221 | 222 | /** 223 | * Waits for element matching the locator to be visible on the page 224 | * 225 | * @param locator 226 | * @param timeout 227 | * @return 228 | */ 229 | public static WebElement waitForVisibility(By locator, int timeout) { 230 | WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeout); 231 | return wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); 232 | } 233 | 234 | /** 235 | * Waits for provided element to be clickable 236 | * 237 | * @param element 238 | * @param timeout 239 | * @return 240 | */ 241 | public static WebElement waitForClickablility(WebElement element, int timeout) { 242 | WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeout); 243 | return wait.until(ExpectedConditions.elementToBeClickable(element)); 244 | } 245 | 246 | /** 247 | * Waits for element matching the locator to be clickable 248 | * 249 | * @param locator 250 | * @param timeout 251 | * @return 252 | */ 253 | public static WebElement waitForClickablility(By locator, int timeout) { 254 | WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeout); 255 | return wait.until(ExpectedConditions.elementToBeClickable(locator)); 256 | } 257 | 258 | /** 259 | * waits for backgrounds processes on the browser to complete 260 | * 261 | * @param timeOutInSeconds 262 | */ 263 | public static void waitForPageToLoad(long timeOutInSeconds) { 264 | ExpectedCondition expectation = new ExpectedCondition() { 265 | public Boolean apply(WebDriver driver) { 266 | return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete"); 267 | } 268 | }; 269 | try { 270 | WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeOutInSeconds); 271 | wait.until(expectation); 272 | } catch (Throwable error) { 273 | error.printStackTrace(); 274 | } 275 | } 276 | 277 | /** 278 | * Verifies whether the element matching the provided locator is displayed on page 279 | * 280 | * @param by 281 | * @throws AssertionError if the element matching the provided locator is not found or not displayed 282 | */ 283 | public static void verifyElementDisplayed(By by) { 284 | try { 285 | assertTrue("Element not visible: " + by, Driver.getDriver().findElement(by).isDisplayed()); 286 | } catch (NoSuchElementException e) { 287 | logger.error(e); 288 | e.printStackTrace(); 289 | Assert.fail("Element not found: " + by); 290 | } 291 | } 292 | 293 | /** 294 | * Verifies whether the element matching the provided locator is NOT displayed on page 295 | * 296 | * @param by 297 | * @throws AssertionError the element matching the provided locator is displayed 298 | */ 299 | public static void verifyElementNotDisplayed(By by) { 300 | try { 301 | Assert.assertFalse(Driver.getDriver().findElement(by).isDisplayed(), "Element should not be visible: " + by); 302 | } catch (NoSuchElementException e) { 303 | logger.error(e); 304 | e.printStackTrace(); 305 | } 306 | } 307 | 308 | /** 309 | * Verifies whether the element is displayed on page 310 | * 311 | * @param element 312 | * @throws AssertionError if the element is not found or not displayed 313 | */ 314 | public static void verifyElementDisplayed(WebElement element) { 315 | try { 316 | assertTrue("Element not visible: " + element, element.isDisplayed()); 317 | } catch (NoSuchElementException e) { 318 | e.printStackTrace(); 319 | logger.error(":::Element not found:::"); 320 | Assert.fail("Element not found: " + element); 321 | } 322 | } 323 | 324 | /** 325 | * Waits for element to be not stale 326 | * 327 | * @param element 328 | */ 329 | public static void waitForStaleElement(WebElement element) { 330 | int y = 0; 331 | while (y <= 15) { 332 | try { 333 | element.isDisplayed(); 334 | break; 335 | } catch (StaleElementReferenceException st) { 336 | y++; 337 | try { 338 | Thread.sleep(200); 339 | } catch (InterruptedException e) { 340 | e.printStackTrace(); 341 | } 342 | } 343 | break; 344 | } 345 | } 346 | 347 | /** 348 | * Clicks on an element using JavaScript 349 | * 350 | * @param element 351 | */ 352 | public static void clickWithJS(WebElement element) { 353 | ((JavascriptExecutor) Driver.getDriver()).executeScript("arguments[0].scrollIntoView(true);", element); 354 | ((JavascriptExecutor) Driver.getDriver()).executeScript("arguments[0].click();", element); 355 | } 356 | 357 | /** 358 | * Scrolls down to an element using JavaScript 359 | * 360 | * @param element 361 | */ 362 | public static void scrollToElement(WebElement element) { 363 | ((JavascriptExecutor) Driver.getDriver()).executeScript("arguments[0].scrollIntoView(true);", element); 364 | } 365 | 366 | /** 367 | * Performs double click action on an element 368 | * 369 | * @param element 370 | */ 371 | public static void doubleClick(WebElement element) { 372 | new Actions(Driver.getDriver()).doubleClick(element).build().perform(); 373 | } 374 | 375 | /** 376 | * Changes the HTML attribute of a Web Element to the given value using JavaScript 377 | * 378 | * @param element 379 | * @param attributeName 380 | * @param attributeValue 381 | */ 382 | public static void setAttribute(WebElement element, String attributeName, String attributeValue) { 383 | ((JavascriptExecutor) Driver.getDriver()).executeScript("arguments[0].setAttribute(arguments[1], arguments[2]);", element, attributeName, attributeValue); 384 | } 385 | 386 | /** 387 | * Highlighs an element by changing its background and border color 388 | * 389 | * @param element 390 | */ 391 | public static void highlight(WebElement element) { 392 | ((JavascriptExecutor) Driver.getDriver()).executeScript("arguments[0].setAttribute('style', 'background: yellow; border: 2px solid red;');", element); 393 | waitFor(1); 394 | ((JavascriptExecutor) Driver.getDriver()).executeScript("arguments[0].removeAttribute('style', 'background: yellow; border: 2px solid red;');", element); 395 | } 396 | 397 | /** 398 | * Checks or unchecks given checkbox 399 | * 400 | * @param element 401 | * @param check 402 | */ 403 | public static void selectCheckBox(WebElement element, boolean check) { 404 | if (check) { 405 | if (!element.isSelected()) { 406 | element.click(); 407 | } 408 | } else { 409 | if (element.isSelected()) { 410 | element.click(); 411 | } 412 | } 413 | } 414 | 415 | /** 416 | * attempts to click on provided element until given time runs out 417 | * 418 | * @param element 419 | * @param timeout 420 | */ 421 | public static void clickWithTimeOut(WebElement element, int timeout) { 422 | for (int i = 0; i < timeout; i++) { 423 | try { 424 | element.click(); 425 | break; 426 | } catch (WebDriverException e) { 427 | waitFor(1); 428 | } 429 | } 430 | } 431 | 432 | /** 433 | * executes the given JavaScript command on given web element 434 | * 435 | * @param element 436 | */ 437 | public static void executeJScommand(WebElement element, String command) { 438 | JavascriptExecutor jse = (JavascriptExecutor) Driver.getDriver(); 439 | jse.executeScript(command, element); 440 | } 441 | 442 | /** 443 | * executes the given JavaScript command on given web element 444 | * 445 | * @param command 446 | */ 447 | public static void executeJScommand(String command) { 448 | JavascriptExecutor jse = (JavascriptExecutor) Driver.getDriver(); 449 | jse.executeScript(command); 450 | } 451 | 452 | /* 453 | * takes screenshot 454 | * @param name 455 | * take a name of a test and returns a path to screenshot takes 456 | */ 457 | public static String getScreenshot(String name) { 458 | // name the screenshot with the current date time to avoid duplicate name 459 | String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_hh:mm:ss a")); 460 | 461 | // TakesScreenshot ---> interface from selenium which takes screenshots 462 | TakesScreenshot ts = (TakesScreenshot) Driver.getDriver(); 463 | File source = ts.getScreenshotAs(OutputType.FILE); 464 | // full path to the screenshot location 465 | String target = System.getProperty("user.dir") + "/test-output/Screenshots/" + name + date + ".png"; 466 | 467 | File finalDestination = new File(target); 468 | 469 | // save the screenshot to the path given 470 | try { 471 | FileUtils.copyFile(source, finalDestination); 472 | } catch (IOException e) { 473 | e.printStackTrace(); 474 | } 475 | return target; 476 | } 477 | 478 | 479 | public static void waitForPresenceOfElement(By by, long time) { 480 | new WebDriverWait(Driver.getDriver(), time).until(ExpectedConditions.presenceOfElementLocated(by)); 481 | } 482 | 483 | public static void waitForsStaleness(By by) { 484 | new WebDriverWait(Driver.getDriver(), Integer.valueOf(ConfigurationReader.getProperty("SHORT_WAIT"))). 485 | until(ExpectedConditions.stalenessOf(Driver.getDriver().findElement(by))); 486 | } 487 | 488 | 489 | } 490 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/utilities/ConfigurationReader.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.utilities; 2 | 3 | import java.io.FileInputStream; 4 | import java.util.Properties; 5 | 6 | public class ConfigurationReader { 7 | private static Properties configFile; 8 | 9 | static { 10 | try { 11 | //path to our .properties file 12 | //MIGHT BE WRONG PATH HERE, PAY ATTENTION 13 | String path = "configuration.properties"; 14 | //we create object of input stream to access file 15 | System.out.println(path); 16 | //provides access to file 17 | FileInputStream input = new FileInputStream(path); 18 | //initialize configFile 19 | configFile = new Properties(); 20 | //load properties file 21 | configFile.load(input); 22 | //close input stream 23 | input.close(); 24 | } catch (Exception e){ 25 | e.printStackTrace(); 26 | } 27 | } 28 | 29 | public static String getProperty(String key){ 30 | return configFile.getProperty(key); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/utilities/Driver.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.utilities; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.WebDriverException; 6 | import org.openqa.selenium.chrome.ChromeDriver; 7 | import org.openqa.selenium.chrome.ChromeOptions; 8 | import org.openqa.selenium.edge.EdgeDriver; 9 | import org.openqa.selenium.firefox.FirefoxDriver; 10 | import org.openqa.selenium.firefox.FirefoxOptions; 11 | import org.openqa.selenium.ie.InternetExplorerDriver; 12 | import org.openqa.selenium.safari.SafariDriver; 13 | 14 | public class Driver { 15 | private static WebDriver driver; 16 | 17 | private Driver() { 18 | } 19 | 20 | public synchronized static WebDriver getDriver(String browser) { 21 | 22 | 23 | // String browser ==> it originally comes from xml file to test base class, from test base it comes here 24 | 25 | 26 | if (driver == null) { 27 | // first we check if the value from xml file is null or not 28 | // if the value from xml file NOT null we use 29 | // the value from xml file IS null, we get the browser from properties file 30 | 31 | browser = browser == null ? ConfigurationReader.getProperty("browser") : browser; 32 | 33 | switch (browser) { 34 | case "chrome": 35 | WebDriverManager.chromedriver().setup(); 36 | driver = new ChromeDriver(); 37 | break; 38 | case "chromeHeadless": 39 | WebDriverManager.chromedriver().setup(); 40 | driver = new ChromeDriver(new ChromeOptions().setHeadless(true)); 41 | break; 42 | 43 | case "firefox": 44 | WebDriverManager.firefoxdriver().setup(); 45 | driver = new FirefoxDriver(); 46 | break; 47 | case "firefoxHeadless": 48 | WebDriverManager.firefoxdriver().setup(); 49 | driver = new FirefoxDriver(new FirefoxOptions().setHeadless(true)); 50 | break; 51 | 52 | case "ie": 53 | if (System.getProperty("os.name").toLowerCase().contains("mac")) 54 | throw new WebDriverException("You are operating Mac OS which doesn't support Internet Explorer"); 55 | WebDriverManager.iedriver().setup(); 56 | driver = new InternetExplorerDriver(); 57 | break; 58 | 59 | case "edge": 60 | WebDriverManager.edgedriver().setup(); 61 | driver = new EdgeDriver(); 62 | break; 63 | case "safari": 64 | if (System.getProperty("os.name").toLowerCase().contains("windows")) 65 | throw new WebDriverException("You are operating Windows OS which doesn't support Safari"); 66 | WebDriverManager.getInstance(SafariDriver.class).setup(); 67 | driver = new SafariDriver(); 68 | break; 69 | default: 70 | throw new RuntimeException("Illegal browser type!"); 71 | } 72 | } 73 | return driver; 74 | } 75 | 76 | public static WebDriver getDriver() { 77 | 78 | return getDriver(null); 79 | } 80 | 81 | public static void closeDriver() { 82 | if (driver != null) { 83 | driver.quit(); 84 | driver = null; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/utilities/ExcelUtil.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.utilities; 2 | 3 | 4 | import org.apache.poi.ss.usermodel.*; 5 | import org.testng.Assert; 6 | 7 | import java.io.FileInputStream; 8 | import java.io.FileOutputStream; 9 | import java.util.ArrayList; 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /* 15 | * This is a utility for reading from writing to excel files. 16 | * it works with xls and xlsx files. 17 | */ 18 | public class ExcelUtil { 19 | 20 | private Sheet workSheet; 21 | private Workbook workBook; 22 | private String path; 23 | 24 | public ExcelUtil(String path, String sheetName) { 25 | this.path = path; 26 | try { 27 | // Open the Excel file 28 | FileInputStream ExcelFile = new FileInputStream(path); 29 | // Access the required test data sheet 30 | workBook = WorkbookFactory.create(ExcelFile); 31 | workSheet = workBook.getSheet(sheetName); 32 | // check if sheet is null or not. null means sheetname was wrong 33 | Assert.assertNotNull(workSheet, "Sheet: \""+sheetName+"\" does not exist\n"); 34 | 35 | } catch (Exception e) { 36 | throw new RuntimeException(e); 37 | } 38 | } 39 | 40 | public String getCellData(int rowNum, int colNum) { 41 | Cell cell; 42 | try { 43 | cell = workSheet.getRow(rowNum).getCell(colNum); 44 | String cellData = cell.toString(); 45 | return cellData; 46 | } catch (Exception e) { 47 | throw new RuntimeException(e); 48 | } 49 | } 50 | 51 | public String[][] getDataArray() { 52 | 53 | String[][] data = new String[rowCount()][columnCount()]; 54 | 55 | for (int i = 0; i > getDataList() { 66 | // get all columns 67 | List columns = getColumnsNames(); 68 | // this will be returned 69 | List> data = new ArrayList<>(); 70 | 71 | for (int i = 1; i < rowCount(); i++) { 72 | // get each row 73 | Row row = workSheet.getRow(i); 74 | // create map of the row using the column and value 75 | // column map key, cell value --> map bvalue 76 | Map rowMap = new HashMap(); 77 | for (Cell cell : row) { 78 | int columnIndex = cell.getColumnIndex(); 79 | rowMap.put(columns.get(columnIndex), cell.toString()); 80 | } 81 | 82 | data.add(rowMap); 83 | } 84 | 85 | return data; 86 | } 87 | 88 | public List getColumnsNames() { 89 | List columns = new ArrayList<>(); 90 | 91 | for (Cell cell : workSheet.getRow(0)) { 92 | columns.add(cell.toString()); 93 | } 94 | return columns; 95 | } 96 | 97 | public void setCellData(String value, int rowNum, int colNum) { 98 | Cell cell; 99 | Row row; 100 | 101 | try { 102 | row = workSheet.getRow(rowNum); 103 | cell = row.getCell(colNum); 104 | 105 | if (cell == null) { 106 | cell = row.createCell(colNum); 107 | cell.setCellValue(value); 108 | } else { 109 | cell.setCellValue(value); 110 | } 111 | FileOutputStream fileOut = new FileOutputStream(path); 112 | workBook.write(fileOut); 113 | 114 | fileOut.close(); 115 | } catch (Exception e) { 116 | e.printStackTrace(); 117 | } 118 | } 119 | 120 | public void setCellData(String value, String columnName, int row) { 121 | int column = getColumnsNames().indexOf(columnName); 122 | setCellData(value, row, column); 123 | } 124 | 125 | public int columnCount() { 126 | return workSheet.getRow(0).getLastCellNum(); 127 | } 128 | 129 | public int rowCount() { 130 | return workSheet.getLastRowNum()+1; 131 | } 132 | 133 | } 134 | 135 | 136 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/utilities/Pages.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.utilities; 2 | 3 | import com.vytrack.pages.activites.CalendarEventsPage; 4 | import com.vytrack.pages.dashboards.DashboardPage; 5 | import com.vytrack.pages.dashboards.ManageDashboards; 6 | import com.vytrack.pages.login_navigation.LoginPage; 7 | 8 | public class Pages { 9 | private LoginPage loginPage; 10 | private CalendarEventsPage calendarEventsPage; 11 | private DashboardPage dashboardPage; 12 | private ManageDashboards manageDashboards; 13 | 14 | 15 | public LoginPage loginPage() { 16 | if (loginPage == null) { 17 | loginPage = new LoginPage(); 18 | } 19 | return loginPage; 20 | } 21 | 22 | public CalendarEventsPage calendarEventsPage() { 23 | if (calendarEventsPage == null) { 24 | calendarEventsPage = new CalendarEventsPage(); 25 | } 26 | return calendarEventsPage; 27 | } 28 | 29 | public DashboardPage dashboardPage() { 30 | if (dashboardPage == null) { 31 | dashboardPage = new DashboardPage(); 32 | } 33 | return dashboardPage; 34 | } 35 | 36 | public ManageDashboards manageDashboards() { 37 | if (manageDashboards == null) { 38 | manageDashboards = new ManageDashboards(); 39 | } 40 | return manageDashboards; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/vytrack/utilities/TestBase.java: -------------------------------------------------------------------------------- 1 | package com.vytrack.utilities; 2 | 3 | import com.aventstack.extentreports.ExtentReports; 4 | import com.aventstack.extentreports.ExtentTest; 5 | import com.aventstack.extentreports.Status; 6 | import com.aventstack.extentreports.markuputils.ExtentColor; 7 | import com.aventstack.extentreports.markuputils.MarkupHelper; 8 | import com.aventstack.extentreports.reporter.ExtentHtmlReporter; 9 | import org.apache.logging.log4j.LogManager; 10 | import org.apache.logging.log4j.Logger; 11 | import org.openqa.selenium.WebDriver; 12 | import org.testng.ITestResult; 13 | import org.testng.annotations.*; 14 | import org.testng.asserts.SoftAssert; 15 | 16 | import java.io.IOException; 17 | import java.time.LocalDate; 18 | import java.time.format.DateTimeFormatter; 19 | import java.util.concurrent.TimeUnit; 20 | 21 | public class TestBase { 22 | 23 | //should be public/protected !!!! 24 | protected WebDriver driver; 25 | protected Pages pages; 26 | protected SoftAssert softAssert; 27 | protected static ExtentReports report; 28 | protected static ExtentHtmlReporter htmlReporter; 29 | protected static ExtentTest extentLogger; 30 | private static final Logger logger = LogManager.getLogger(); 31 | 32 | 33 | @BeforeSuite(alwaysRun = true) 34 | @Parameters("test") 35 | public void setUpTest(@Optional String test) { 36 | // actual reporter 37 | report = new ExtentReports(); 38 | // System.getProperty("user.dir") ---> get the path to current project 39 | // test-output --> folder in the current project, will be created by testng if 40 | // it does not already exist 41 | // report.html --> name of the report file 42 | if (test == null) { 43 | test = "reports"; 44 | } 45 | String filePath = System.getProperty("user.dir") + "/test-output/" + test + "/" + LocalDate.now().format(DateTimeFormatter.ofPattern("MM_dd_yyyy")) + "/report.html"; 46 | htmlReporter = new ExtentHtmlReporter(filePath); 47 | logger.info("Report path: "+filePath); 48 | report.attachReporter(htmlReporter); 49 | report.setSystemInfo("ENV", "qa"); 50 | report.setSystemInfo("ENV", "qa"); 51 | report.setSystemInfo("browser", ConfigurationReader.getProperty("browser")); 52 | report.setSystemInfo("OS", System.getProperty("os.name")); 53 | htmlReporter.config().setDocumentTitle("VYTrack Test automation"); 54 | htmlReporter.config().setReportName("VYTrack Test automation"); 55 | if (System.getenv("runner") != null) { 56 | extentLogger.info("Running: " + System.getenv("runner")); 57 | } 58 | } 59 | 60 | 61 | @BeforeMethod(alwaysRun = true) 62 | @Parameters("browser") 63 | public void setup(@Optional String browser) { 64 | driver = Driver.getDriver(browser); 65 | pages = new Pages(); 66 | softAssert = new SoftAssert(); 67 | driver.manage().timeouts().implicitlyWait(Long.valueOf(ConfigurationReader.getProperty("implicitwait")), TimeUnit.SECONDS); 68 | driver.manage().window().maximize(); 69 | String URL = ConfigurationReader.getProperty("url"+ConfigurationReader.getProperty("environment")); 70 | driver.get(URL); 71 | logger.info("URL: "+URL); 72 | } 73 | 74 | @AfterMethod(alwaysRun = true) 75 | @Parameters("browser") 76 | public void teardown(@Optional String browser, ITestResult result) { 77 | // checking if the test method failed 78 | if (result.getStatus() == ITestResult.FAILURE) { 79 | // get screenshot using the utility method and save the location of the screenshot 80 | String screenshotLocation = BrowserUtils.getScreenshot(result.getName()); 81 | 82 | // capture the name of test method 83 | extentLogger.fail(result.getName()); 84 | 85 | // add the screenshot to the report 86 | try { 87 | extentLogger.addScreenCaptureFromPath(screenshotLocation); 88 | } catch (IOException e) { 89 | e.printStackTrace(); 90 | } 91 | // capture the exception thrown 92 | extentLogger.fail(result.getThrowable()); 93 | 94 | } else if (result.getStatus() == ITestResult.SUCCESS) { 95 | extentLogger.log(Status.PASS, MarkupHelper.createLabel(result.getName() + " PASSED ", ExtentColor.GREEN)); 96 | } else if (result.getStatus() == ITestResult.SKIP) { 97 | extentLogger.skip("Test Case Skipped is " + result.getName()); 98 | } 99 | if(browser == null){ 100 | browser = ConfigurationReader.getProperty("browser"); 101 | } 102 | extentLogger.log(Status.INFO, MarkupHelper.createLabel("Browser: "+browser, ExtentColor.ORANGE)); 103 | softAssert.assertAll(); 104 | Driver.closeDriver(); 105 | } 106 | 107 | @AfterSuite(alwaysRun = true) 108 | public void tearDownTest() { 109 | logger.info(":: FLUSHING REPORT ::"); 110 | report.flush(); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/test/resources/Countries.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybertek-B11/Spring2019FinalTestNGFramework/ba0adde5d43af9b5365bcade65bbc89f39264d13/src/test/resources/Countries.xlsx -------------------------------------------------------------------------------- /src/test/resources/EmployeesTestData.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybertek-B11/Spring2019FinalTestNGFramework/ba0adde5d43af9b5365bcade65bbc89f39264d13/src/test/resources/EmployeesTestData.xlsx -------------------------------------------------------------------------------- /src/test/resources/Vytrack testusers.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybertek-B11/Spring2019FinalTestNGFramework/ba0adde5d43af9b5365bcade65bbc89f39264d13/src/test/resources/Vytrack testusers.xlsx -------------------------------------------------------------------------------- /src/test/resources/~$Countries.xlsx: -------------------------------------------------------------------------------- 1 | Cybertek Cybertek Cybertek Cybertek -------------------------------------------------------------------------------- /testngrunner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /testngrunner2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | --------------------------------------------------------------------------------