├── .gitignore ├── configuration.properties ├── pom.xml ├── regression_test_runner.xml ├── smoke_test_runner.xml ├── src └── test │ ├── java │ └── com │ │ └── cybertek │ │ ├── base │ │ ├── TestBase.java │ │ ├── VytrackPageBase.java │ │ └── VytrackTestBase.java │ │ ├── pages │ │ ├── CreateCalendarEventsPage.java │ │ ├── CreateContactsPage.java │ │ ├── DashboardPage.java │ │ ├── LoginPage.java │ │ ├── LoginPageNoPageFactory.java │ │ └── VehiclesPage.java │ │ ├── tests │ │ ├── day10_webelement │ │ │ ├── CheckboxesTest.java │ │ │ ├── DisabledAndDisplayedTests.java │ │ │ ├── ListOfElementsTests.java │ │ │ ├── OrderOfTests.java │ │ │ └── RadioButtonsTest.java │ │ ├── day11_select_actions │ │ │ ├── ActionsClassDemo.java │ │ │ ├── JavaScriptExecutorTests.java │ │ │ └── SelectClassTests.java │ │ ├── day12_pops_tabs_alerts_iframes │ │ │ ├── IframeExample.java │ │ │ ├── PopupAndAlertsExamples.java │ │ │ └── TabsAndWindowsExample.java │ │ ├── day13_waits_and_synchronization │ │ │ ├── ExplicitWaitExamples.java │ │ │ ├── ImplicitWaitExamples.java │ │ │ ├── RandomStuff.java │ │ │ ├── ThreadSleepExample.java │ │ │ └── VytrachLoginTestWithWait.java │ │ ├── day14_test_base_props_driver │ │ │ ├── FileUploadTests.java │ │ │ ├── PropertiesExamples.java │ │ │ ├── Singleton.java │ │ │ └── TestingTestBaseTests.java │ │ ├── day15_webtables │ │ │ └── WebTablesTests.java │ │ ├── day16_page_object_model │ │ │ ├── NegativeLoginTests.java │ │ │ ├── PageHeadersTests.java │ │ │ └── PositiveLoginTests.java │ │ ├── day17_ddt_dataprovider_pom2 │ │ │ ├── CreateCalendarEventTests.java │ │ │ ├── MenuOptionsTests.java │ │ │ ├── UserInfoDataDrivenTests.java │ │ │ └── UserInfoDataDrivenTests2.java │ │ ├── day18_html_report │ │ │ └── ExtentReportExample.java │ │ ├── day19_excel_io │ │ │ ├── ExcelUtilityDemo.java │ │ │ ├── ExcelWriteExample.java │ │ │ ├── ReadExcelExample.java │ │ │ └── VytrackExcelDDTTests.java │ │ ├── day1_Navigation │ │ │ ├── BookitTitleVerify.java │ │ │ ├── EtsyTitleVerify.java │ │ │ ├── FirstClass.java │ │ │ ├── Navigations.java │ │ │ ├── VerifyBookItURL.java │ │ │ ├── VerifyTitle.java │ │ │ ├── VerifyURL.java │ │ │ ├── VrifyURLOfPracticeWeb.java │ │ │ └── task1.java │ │ ├── day20_jdbc │ │ │ ├── MySQLJDBCConnectionDemo.java │ │ │ └── OracleJDBCConnectionDemo.java │ │ ├── day21_db_testing │ │ │ ├── CreateNewContactDBTest.java │ │ │ └── DbUtilityDemo.java │ │ ├── day2_Locators │ │ │ ├── EbaySearch.java │ │ │ ├── FindElemet.java │ │ │ └── login.java │ │ ├── day3_locators2 │ │ │ ├── FakerPractice.java │ │ │ ├── GetAttributeValue.java │ │ │ ├── LinkText.java │ │ │ ├── VerifyErrorMassage.java │ │ │ └── VerifyLogin.java │ │ ├── day4_xpath │ │ │ ├── ClicikvsSubmit.java │ │ │ ├── GetAttribute.java │ │ │ ├── PracticeFactory.java │ │ │ ├── XpathPractice.java │ │ │ ├── getAttribute2.java │ │ │ ├── getText.java │ │ │ └── textMethodOfXpath.java │ │ ├── day5_more_xpath │ │ │ ├── ClassNameExample.java │ │ │ └── XpathDemo.java │ │ ├── day6_css │ │ │ └── CssExample.java │ │ ├── day7_review │ │ │ ├── AmazonCssExample.java │ │ │ ├── AmazonTestWithText.java │ │ │ ├── AmazonTests.java │ │ │ ├── StaleElementExample.java │ │ │ └── SystemPropertiesExample.java │ │ ├── day8_review_2 │ │ │ ├── EbaySearchTest.java │ │ │ ├── GetAttributeExamples.java │ │ │ └── VytrackTests.java │ │ ├── day9_testng_intro │ │ │ ├── BeforeAndAfterTest.java │ │ │ ├── FirstTestNGTest.java │ │ │ └── TestNGAssertionsTest.java │ │ ├── office_hours1 │ │ │ └── GoogleSearchTest.java │ │ ├── office_hours2 │ │ │ ├── GoogleHoverTest.java │ │ │ └── SelectClassPracticeTests.java │ │ ├── office_hours3 │ │ │ ├── DifferentBrowsers.java │ │ │ └── EtsyTests.java │ │ └── office_hours4 │ │ │ ├── ChangeMenuSoftAssertTest.java │ │ │ ├── CookiesExample.java │ │ │ ├── CountryInformationDDT.java │ │ │ ├── IframesExample.java │ │ │ ├── JavaScriptExecutorExample.java │ │ │ ├── SoftAssertionsExamples.java │ │ │ └── WebTablesPractice.java │ │ └── utilities │ │ ├── BrowserUtils.java │ │ ├── ConfigurationReader.java │ │ ├── DBUtils.java │ │ ├── Driver.java │ │ ├── ExcelUtil.java │ │ └── WebDriverFactory.java │ └── resources │ ├── Countries.xlsx │ └── Vytrack testusers.xlsx └── testng_runner.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .idea 3 | *.iml 4 | *.DS_Store 5 | test-output -------------------------------------------------------------------------------- /configuration.properties: -------------------------------------------------------------------------------- 1 | browser=chrome 2 | url=http://practice.cybertekschool.com 3 | vytrack_url=https://qa3.vytrack.com/ 4 | driver_username=user1 5 | driver_password=UserUser123 6 | sales_manager_username=salesmanager101 7 | sales_manager_password=UserUser123 8 | store_manager_username=storemanager51 9 | store_manager_password=UserUser123 10 | qa3_db_host=107.23.27.171 11 | qa3_db_port=3306 12 | qa3_db_name=bitnami_orocrm 13 | qa3_db_username=qa_user 14 | qa3_db_password=qa_user -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 4.0.0 8 | 9 | com.cybertek 10 | fall-2019-selenium-project 11 | 1.0-SNAPSHOT 12 | 13 | 14 | 1.8 15 | 1.8 16 | 17 | 18 | 19 | 20 | 21 | org.seleniumhq.selenium 22 | selenium-java 23 | 3.141.59 24 | 25 | 26 | 27 | 28 | io.github.bonigarcia 29 | webdrivermanager 30 | 3.8.1 31 | 32 | 33 | 34 | 35 | com.github.javafaker 36 | javafaker 37 | 1.0.1 38 | 39 | 40 | 41 | org.testng 42 | testng 43 | 7.1.0 44 | test 45 | 46 | 47 | 48 | com.aventstack 49 | extentreports 50 | 4.0.4 51 | 52 | 53 | 54 | org.apache.poi 55 | poi 56 | 4.1.2 57 | 58 | 59 | 60 | org.apache.poi 61 | poi-ooxml 62 | 4.1.2 63 | 64 | 65 | com.oracle.ojdbc 66 | ojdbc8 67 | 19.3.0.0 68 | 69 | 70 | mysql 71 | mysql-connector-java 72 | 8.0.18 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /regression_test_runner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /smoke_test_runner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/base/TestBase.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.base; 2 | 3 | import com.cybertek.utilities.Driver; 4 | import com.cybertek.utilities.WebDriverFactory; 5 | import org.openqa.selenium.WebDriver; 6 | import org.testng.annotations.AfterMethod; 7 | import org.testng.annotations.BeforeMethod; 8 | 9 | public abstract class TestBase { 10 | protected WebDriver driver; 11 | 12 | @BeforeMethod 13 | public void setUpMethod() { 14 | driver = Driver.getDriver(); 15 | 16 | } 17 | 18 | @AfterMethod 19 | public void tearDownMethod() throws InterruptedException { 20 | // Thread.sleep(5000); 21 | Driver.closeDriver(); 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/base/VytrackPageBase.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.base; 2 | 3 | import com.cybertek.utilities.Driver; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebElement; 6 | import org.openqa.selenium.support.FindBy; 7 | import org.openqa.selenium.support.PageFactory; 8 | import org.openqa.selenium.support.ui.ExpectedConditions; 9 | import org.openqa.selenium.support.ui.WebDriverWait; 10 | 11 | import java.util.List; 12 | 13 | public abstract class VytrackPageBase { 14 | 15 | public VytrackPageBase() { 16 | PageFactory.initElements(Driver.getDriver(), this); 17 | } 18 | 19 | @FindBy(className = "oro-subtitle") 20 | public WebElement pageHeader; 21 | 22 | @FindBy(xpath = "//span[contains(text(), 'Fleet')][@class='title title-level-1']") 23 | public WebElement fleet; 24 | 25 | @FindBy(xpath = "//span[.='Vehicles'][@class='title title-level-2']") 26 | public WebElement vehicles; 27 | 28 | @FindBy(xpath = "(//a[@class='dropdown-toggle'])[1]") 29 | public WebElement accountHolderName; 30 | 31 | @FindBy(css = ".title-level-1") 32 | public List menu1Options; 33 | 34 | public void changeMenu(String menu1, String menu2) { 35 | String menu1X = "//span[contains(text(), '"+menu1+"')][@class='title title-level-1']"; 36 | WebElement menu1El = Driver.getDriver().findElement(By.xpath(menu1X)); 37 | 38 | String menu2X = "//span[.='"+menu2+"'][@class='title title-level-2']"; 39 | WebElement menu2El = Driver.getDriver().findElement(By.xpath(menu2X)); 40 | 41 | WebDriverWait wait =new WebDriverWait(Driver.getDriver(), 5); 42 | 43 | wait.until(ExpectedConditions.elementToBeClickable(menu1El)); 44 | 45 | menu1El.click(); 46 | try { 47 | Thread.sleep(500); 48 | } catch (InterruptedException e) { 49 | e.printStackTrace(); 50 | } 51 | wait.until(ExpectedConditions.elementToBeClickable(menu2El)); 52 | menu2El.click(); 53 | 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/base/VytrackTestBase.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.base; 2 | 3 | import com.aventstack.extentreports.ExtentReports; 4 | import com.aventstack.extentreports.ExtentTest; 5 | import com.aventstack.extentreports.reporter.ExtentHtmlReporter; 6 | import com.cybertek.pages.*; 7 | import com.cybertek.utilities.BrowserUtils; 8 | import com.cybertek.utilities.ConfigurationReader; 9 | import com.cybertek.utilities.Driver; 10 | import org.openqa.selenium.WebDriver; 11 | import org.openqa.selenium.support.ui.WebDriverWait; 12 | import org.testng.ITestResult; 13 | import org.testng.annotations.*; 14 | import org.testng.asserts.SoftAssert; 15 | 16 | import java.io.IOException; 17 | 18 | public abstract class VytrackTestBase { 19 | protected WebDriver driver; 20 | protected WebDriverWait wait; 21 | protected SoftAssert softAssert; 22 | protected LoginPage loginPage; 23 | protected DashboardPage dashboardPage; 24 | protected VehiclesPage vehiclesPage; 25 | protected CreateCalendarEventsPage createCalendarEventsPage; 26 | protected CreateContactsPage createContactsPage; 27 | 28 | protected ExtentReports report; 29 | private ExtentHtmlReporter htmlReporter; 30 | protected ExtentTest test; 31 | 32 | @BeforeSuite 33 | public void setUpSuite() { 34 | report = new ExtentReports(); 35 | String path = System.getProperty("user.dir") + "/test-output/report.html"; 36 | htmlReporter = new ExtentHtmlReporter(path); 37 | htmlReporter.config().setReportName("Vytrack Automated Tests"); 38 | 39 | report.attachReporter(htmlReporter); 40 | report.setSystemInfo("Environment", "QA"); 41 | report.setSystemInfo("Browser", ConfigurationReader.getProperty("browser")); 42 | 43 | } 44 | 45 | @AfterSuite 46 | public void tearDownSuite() { 47 | report.flush(); 48 | } 49 | 50 | @Parameters("url") 51 | @BeforeMethod() 52 | public void setUpMethod(@Optional String url) { 53 | System.out.println("url = " + url); 54 | driver = Driver.getDriver(); 55 | wait = new WebDriverWait(driver, 10); 56 | softAssert = new SoftAssert(); 57 | 58 | if (url == null) { 59 | driver.get(ConfigurationReader.getProperty("vytrack_url")); 60 | } else { 61 | driver.get(url); 62 | } 63 | 64 | loginPage = new LoginPage(); 65 | dashboardPage = new DashboardPage(); 66 | vehiclesPage = new VehiclesPage(); 67 | createCalendarEventsPage = new CreateCalendarEventsPage(); 68 | createContactsPage = new CreateContactsPage(); 69 | } 70 | 71 | @AfterMethod 72 | public void tearDownMethod(ITestResult iTestResult) throws InterruptedException, IOException { 73 | // ITestResult class from testng gives information about current test: name, status 74 | // check if the test failed 75 | if (iTestResult.getStatus() == ITestResult.FAILURE) { 76 | // tell extent report that the test failed 77 | test.fail(iTestResult.getName()); 78 | 79 | // take screen shot of the screen and save location 80 | String screenshot = BrowserUtils.getScreenshot(iTestResult.getName()); 81 | // show path to screenshot 82 | test.addScreenCaptureFromPath(screenshot); 83 | } 84 | 85 | 86 | // Thread.sleep(3000); 87 | Driver.closeDriver(); 88 | softAssert.assertAll(); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/CreateCalendarEventsPage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages; 2 | 3 | import com.cybertek.base.VytrackPageBase; 4 | import com.cybertek.utilities.Driver; 5 | import org.openqa.selenium.WebElement; 6 | import org.openqa.selenium.support.FindBy; 7 | import org.openqa.selenium.support.PageFactory; 8 | 9 | public class CreateCalendarEventsPage extends VytrackPageBase { 10 | public CreateCalendarEventsPage(){ 11 | PageFactory.initElements(Driver.getDriver(), this); 12 | } 13 | 14 | @FindBy(name = "oro_calendar_event_form[allDay]") 15 | public WebElement allDayEventCheckbox; 16 | 17 | @FindBy(css = "input[id^='recurrence-repeat-view']") 18 | public WebElement repeatCheckbox; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/CreateContactsPage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages; 2 | 3 | import com.cybertek.base.VytrackPageBase; 4 | import com.cybertek.utilities.Driver; 5 | import org.openqa.selenium.WebElement; 6 | import org.openqa.selenium.support.FindBy; 7 | import org.openqa.selenium.support.PageFactory; 8 | 9 | public class CreateContactsPage extends VytrackPageBase { 10 | public CreateContactsPage(){ 11 | PageFactory.initElements(Driver.getDriver(), this); 12 | } 13 | 14 | @FindBy(name = "oro_contact_form[firstName]") 15 | public WebElement firstName; 16 | 17 | @FindBy(name = "oro_contact_form[lastName]") 18 | public WebElement lastName; 19 | 20 | @FindBy(name = "oro_contact_form[emails][0][email]") 21 | public WebElement email; 22 | 23 | @FindBy(css = "button[type='submit']") 24 | public WebElement saveAndClose; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/DashboardPage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages; 2 | 3 | import com.cybertek.base.VytrackPageBase; 4 | import com.cybertek.utilities.Driver; 5 | import org.openqa.selenium.support.PageFactory; 6 | 7 | public class DashboardPage extends VytrackPageBase { 8 | public DashboardPage() { 9 | PageFactory.initElements(Driver.getDriver(), this); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/LoginPage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages; 2 | 3 | import com.cybertek.base.VytrackPageBase; 4 | import com.cybertek.utilities.Driver; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.support.FindBy; 8 | import org.openqa.selenium.support.PageFactory; 9 | 10 | public class LoginPage { 11 | public LoginPage() { 12 | // page object classes needs contructor. here we have to call the PageFactory.initElements 13 | // from selenium and pass a webdriver object and this class as param 14 | PageFactory.initElements(Driver.getDriver(), this); 15 | 16 | } 17 | 18 | // FindBy --> we provide the locator for webelement 19 | @FindBy(id = "prependedInput") 20 | public WebElement username; 21 | 22 | @FindBy(id = "prependedInput2") 23 | public WebElement password; 24 | 25 | @FindBy(name = "_submit") 26 | public WebElement logIn; 27 | 28 | @FindBy(css = ".alert-error>div") 29 | public WebElement errorMessage; 30 | 31 | public void login(String username, String password){ 32 | this.username.sendKeys(username); 33 | this.password.sendKeys(password); 34 | logIn.click(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/LoginPageNoPageFactory.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages; 2 | 3 | import com.cybertek.utilities.Driver; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.support.FindBy; 8 | import org.openqa.selenium.support.PageFactory; 9 | 10 | public class LoginPageNoPageFactory { 11 | 12 | private WebDriver driver; 13 | 14 | final By username = By.id("prependedInput"); 15 | final By password = By.id("prependedInput2"); 16 | final By logIn = By.name("_submit"); 17 | 18 | public LoginPageNoPageFactory(WebDriver driver) { 19 | this.driver = driver; 20 | } 21 | 22 | public WebElement getUsername() { 23 | return driver.findElement(username); 24 | } 25 | 26 | public WebElement getPassword() { 27 | return driver.findElement(password); 28 | } 29 | 30 | public WebElement getLoginBtn() { 31 | return driver.findElement(logIn); 32 | } 33 | 34 | public void login(String usernameText, String passwordText) { 35 | getUsername().sendKeys(usernameText); 36 | getPassword().sendKeys(passwordText); 37 | getLoginBtn().click(); 38 | } 39 | 40 | public static void main(String[] args) { 41 | LoginPageNoPageFactory loginPage = new LoginPageNoPageFactory(Driver.getDriver()); 42 | loginPage.login("abc", "abc"); 43 | 44 | loginPage.getUsername().sendKeys("abc"); 45 | loginPage.getPassword().sendKeys("abc"); 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/VehiclesPage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages; 2 | 3 | import com.cybertek.base.VytrackPageBase; 4 | import com.cybertek.utilities.Driver; 5 | import org.openqa.selenium.support.PageFactory; 6 | 7 | public class VehiclesPage extends VytrackPageBase { 8 | 9 | public VehiclesPage() { 10 | PageFactory.initElements(Driver.getDriver(), this); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day10_webelement/CheckboxesTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day10_webelement; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.testng.Assert; 8 | import org.testng.annotations.AfterMethod; 9 | import org.testng.annotations.BeforeMethod; 10 | import org.testng.annotations.Test; 11 | 12 | public class CheckboxesTest { 13 | 14 | WebDriver driver; 15 | 16 | @BeforeMethod 17 | public void beforeMethod() { 18 | driver = WebDriverFactory.getDriver("chrome"); 19 | driver.get("http://practice.cybertekschool.com/checkboxes"); 20 | 21 | } 22 | 23 | @AfterMethod 24 | public void afterTest() { 25 | driver.quit(); 26 | } 27 | 28 | @Test 29 | public void test(){ 30 | WebElement one = driver.findElement(By.xpath("//input[1]")); 31 | WebElement two = driver.findElement(By.xpath("//input[2]")); 32 | // by default one is not checked, two is checked 33 | System.out.println("is one selected: "+ one.isSelected()); 34 | System.out.println("is two selected: "+ two.isSelected()); 35 | 36 | Assert.assertFalse(one.isSelected()); 37 | Assert.assertTrue(two.isSelected()); 38 | 39 | // check the first checkbox 40 | // verify one is selected 41 | // verify two is selected 42 | System.out.println("check the first checkbox"); 43 | one.click(); 44 | System.out.println("is one selected: "+ one.isSelected()); 45 | System.out.println("is two selected: "+ two.isSelected()); 46 | 47 | Assert.assertTrue(one.isSelected()); 48 | Assert.assertTrue(two.isSelected()); 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day10_webelement/DisabledAndDisplayedTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day10_webelement; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.testng.Assert; 8 | import org.testng.annotations.AfterMethod; 9 | import org.testng.annotations.BeforeMethod; 10 | import org.testng.annotations.Test; 11 | 12 | public class DisabledAndDisplayedTests { 13 | 14 | WebDriver driver; 15 | 16 | @BeforeMethod 17 | public void beforeMethod() { 18 | driver = WebDriverFactory.getDriver("chrome"); 19 | driver.get("http://practice.cybertekschool.com/radio_buttons"); 20 | 21 | } 22 | 23 | @AfterMethod 24 | public void afterTest() { 25 | driver.quit(); 26 | } 27 | 28 | /* 29 | go to http://practice.cybertekschool.com/radio_buttons 30 | verify green is disabled 31 | verify black is enabled 32 | */ 33 | 34 | @Test 35 | public void disabledTest() throws InterruptedException { 36 | Thread.sleep(2000); 37 | WebElement green = driver.findElement(By.id("green")); 38 | WebElement black = driver.findElement(By.id("black")); 39 | // isEnabled --> returns true if the element is enabled, active 40 | System.out.println("Is green enabled: "+green.isEnabled()); 41 | System.out.println("Is black enabled: "+black.isEnabled()); 42 | Assert.assertFalse(green.isEnabled()); 43 | Assert.assertTrue(black.isEnabled()); 44 | 45 | } 46 | 47 | 48 | @Test 49 | public void disabledTestWithAttribute() throws InterruptedException { 50 | Thread.sleep(2000); 51 | WebElement green = driver.findElement(By.id("green")); 52 | WebElement black = driver.findElement(By.id("black")); 53 | 54 | 55 | System.out.println("black: "+ black.getAttribute("disabled")); 56 | System.out.println("green: "+ green.getAttribute("disabled")); 57 | 58 | // verify that certain value is equal to null. verify element is enabled 59 | Assert.assertEquals(black.getAttribute("disabled"), null); 60 | // VERIFY THAT VALUE OF black.getAttribute("disabled") IS NULL 61 | Assert.assertNull(black.getAttribute("disabled")); 62 | 63 | // verify that certain value is equal to TRUE. verify element is DISALBED 64 | Assert.assertEquals(green.getAttribute("disabled"), "true"); 65 | Assert.assertTrue(Boolean.parseBoolean(green.getAttribute("disabled"))); 66 | } 67 | 68 | @Test 69 | public void testElementVisible() throws InterruptedException { 70 | driver.get("http://practice.cybertekschool.com/dynamic_loading/1"); 71 | WebElement username = driver.findElement(By.id("username")); 72 | WebElement start = driver.findElement(By.tagName("button")); 73 | 74 | // verify that username is not visible 75 | /// isDisplayed --> returns true element we found in HTML is visible on page 76 | System.out.println("Username is visible: " + username.isDisplayed()); 77 | Assert.assertFalse(username.isDisplayed()); 78 | 79 | System.out.println("click on start"); 80 | start.click(); 81 | 82 | Thread.sleep(7000); 83 | System.out.println("Username is visible: " + username.isDisplayed()); 84 | Assert.assertTrue(username.isDisplayed()); 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day10_webelement/ListOfElementsTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day10_webelement; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.Keys; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | import org.testng.Assert; 9 | import org.testng.annotations.AfterMethod; 10 | import org.testng.annotations.BeforeMethod; 11 | import org.testng.annotations.Test; 12 | 13 | import java.util.List; 14 | import java.util.Random; 15 | 16 | public class ListOfElementsTests { 17 | WebDriver driver; 18 | 19 | @BeforeMethod 20 | public void beforeMethod() { 21 | driver = WebDriverFactory.getDriver("chrome"); 22 | 23 | } 24 | 25 | @AfterMethod 26 | public void afterTest() { 27 | driver.quit(); 28 | } 29 | 30 | /* 31 | go to page radio buttons 32 | verify that none of the sports radio buttons are selected 33 | */ 34 | @Test 35 | public void listOfRadioButtons() throws InterruptedException { 36 | driver.get("http://practice.cybertekschool.com/radio_buttons"); 37 | 38 | // driver.findElements --> returns a LIST of element 39 | // returns all the elements that match the given locator 40 | // if the locator does not match anhytihg, it does not throw exception, it just returns empty list 41 | 42 | List sports = driver.findElements(By.name("sport")); 43 | 44 | System.out.println(sports.size()); 45 | 46 | for (WebElement radioButton : sports) { 47 | Assert.assertFalse(radioButton.isSelected()); 48 | } 49 | } 50 | 51 | /* 52 | go to practice website 53 | get all the links present in the page 54 | print their text 55 | */ 56 | @Test 57 | public void getAllLinksTest() { 58 | driver.get("http://practice.cybertekschool.com"); 59 | 60 | // get all the links in a page 61 | List links = driver.findElements(By.tagName("a")); 62 | System.out.println(links.size()); 63 | // get the text of each link and print 64 | 65 | for (WebElement link : links) { 66 | System.out.println(link.getText()); 67 | } 68 | } 69 | 70 | 71 | /* 72 | go to amazon 73 | search for paper towels 74 | print the number of results 75 | print the first result 76 | print the second result 77 | print the last result 78 | */ 79 | 80 | @Test 81 | public void amazonTest() throws InterruptedException { 82 | driver.get("https://amazon.com"); 83 | WebElement input = driver.findElement(By.id("twotabsearchtextbox")); 84 | input.sendKeys("paper towels" + Keys.ENTER); 85 | 86 | List allResults = driver.findElements(By.cssSelector("span.a-size-base-plus")); 87 | 88 | Thread.sleep(2000); 89 | System.out.println("Number of results: " + allResults.size()); 90 | 91 | System.out.println("First result: " + allResults.get(0).getText()); 92 | System.out.println("Second result: " + allResults.get(1).getText()); 93 | System.out.println("Last result: " + allResults.get(allResults.size() - 1).getText()); 94 | 95 | 96 | } 97 | 98 | /* 99 | go to http://practice.cybertekschool.com/radio_buttons 100 | verify the all sports checkboxes are NOT checked by default 101 | randomly click any sport 102 | verify that that sport is clicked 103 | verify that all others are not clicked 104 | repeat the last step for 5 times 105 | 106 | Amirjon special 107 | */ 108 | 109 | @Test 110 | public void radioTest() throws InterruptedException { 111 | driver.get("http://practice.cybertekschool.com/radio_buttons"); 112 | List list = driver.findElements(By.name("sport")); 113 | 114 | System.out.println("verify none of them selected by default"); 115 | System.out.println(list.size()); 116 | //checking all the sport checkboxes are not checked 117 | for (int i = 0; i < list.size(); i++) { 118 | Assert.assertFalse(list.get(i).isSelected()); 119 | } 120 | 121 | System.out.println("Start randomly selecting radio buttons"); 122 | 123 | //randomly clicking and verifying 124 | 125 | for (int q = 0; q < 5; q++) { 126 | 127 | Thread.sleep(5000); 128 | Random ran = new Random(); 129 | int num = ran.nextInt(4); 130 | list.get(num).click(); 131 | System.out.println("Selecting button number: " + (num + 1)); 132 | 133 | for (int i = 0; i < list.size(); i++) { 134 | if (i == num) { 135 | Assert.assertTrue(list.get(num).isSelected()); 136 | } else { 137 | Assert.assertFalse(list.get(i).isSelected()); 138 | } 139 | } 140 | 141 | } 142 | } 143 | 144 | 145 | } 146 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day10_webelement/OrderOfTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day10_webelement; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | 6 | public class OrderOfTests { 7 | 8 | String title; 9 | 10 | @Test(priority = 0) 11 | public void login() { 12 | System.out.println("opening the browser"); 13 | System.out.println("capturing title"); 14 | title = "cbt"; 15 | // i will make this test fail. Assert.fail() --> is a ready method that makes test fail 16 | Assert.fail(); 17 | } 18 | 19 | @Test(priority = 1, dependsOnMethods = "login") 20 | public void assertTitle() { 21 | System.out.println("verifying the title"); 22 | Assert.assertEquals(title, "cbt"); 23 | } 24 | 25 | @Test(priority = 55) 26 | public void verifyOtherThings() { 27 | System.out.println("verify sth else"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day10_webelement/RadioButtonsTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day10_webelement; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.testng.Assert; 8 | import org.testng.annotations.AfterClass; 9 | import org.testng.annotations.AfterMethod; 10 | import org.testng.annotations.BeforeMethod; 11 | import org.testng.annotations.Test; 12 | 13 | public class RadioButtonsTest { 14 | 15 | WebDriver driver; 16 | 17 | @BeforeMethod 18 | public void beforeMethod() { 19 | driver = WebDriverFactory.getDriver("chrome"); 20 | driver.get("http://practice.cybertekschool.com/radio_buttons"); 21 | 22 | } 23 | 24 | @AfterMethod 25 | public void afterTest() { 26 | driver.quit(); 27 | } 28 | 29 | /* default behavior test 30 | go to http://practice.cybertekschool.com/radio_buttons 31 | verify that blue is selected 32 | verify red is not selected 33 | */ 34 | 35 | @Test 36 | public void test1() { 37 | WebElement blue = driver.findElement(By.id("blue")); 38 | // isSelected --> returns true if element is selected 39 | System.out.println(blue.isSelected()); 40 | 41 | // verify is the radio button is selected 42 | Assert.assertTrue(blue.isSelected()); 43 | 44 | WebElement red = driver.findElement(By.id("red")); 45 | // print red is not selected 46 | System.out.println(red.isSelected()); 47 | 48 | // verifies if the statement it false. if it is false, it passes. if true it fails. 49 | Assert.assertFalse(red.isSelected()); 50 | 51 | } 52 | 53 | /* 54 | go to http://practice.cybertekschool.com/ 55 | click on red 56 | verify that blue is not selected 57 | red is selected 58 | */ 59 | 60 | @Test 61 | public void test2() { 62 | WebElement red = driver.findElement(By.id("red")); 63 | WebElement blue = driver.findElement(By.id("blue")); 64 | red.click(); 65 | Assert.assertFalse(blue.isSelected()); 66 | Assert.assertTrue(red.isSelected()); 67 | 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day11_select_actions/ActionsClassDemo.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day11_select_actions; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.Keys; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | import org.openqa.selenium.interactions.Actions; 9 | import org.testng.annotations.AfterMethod; 10 | import org.testng.annotations.BeforeMethod; 11 | import org.testng.annotations.Test; 12 | 13 | public class ActionsClassDemo { 14 | 15 | WebDriver driver; 16 | Actions actions; 17 | 18 | @BeforeMethod 19 | public void beforeMethod() { 20 | driver = WebDriverFactory.getDriver("firefox"); 21 | actions = new Actions(driver); 22 | } 23 | 24 | @AfterMethod 25 | public void afterTest() { 26 | driver.quit(); 27 | } 28 | 29 | @Test 30 | public void hoverTest() throws InterruptedException { 31 | driver.get("http://practice.cybertekschool.com/hovers"); 32 | Thread.sleep(2000); 33 | WebElement target = driver.findElement(By.tagName("img")); 34 | 35 | // moveToElement --> moves the mouse on top of given web element 36 | actions.moveToElement(target).perform(); 37 | Thread.sleep(3000); 38 | 39 | } 40 | 41 | @Test 42 | public void hover2(){ 43 | driver.get("http://practice.cybertekschool.com/jqueryui/menu"); 44 | WebElement enabled = driver.findElement(By.id("ui-id-3")); 45 | WebElement downloads = driver.findElement(By.id("ui-id-4")); 46 | WebElement pdf = driver.findElement(By.id("ui-id-5")); 47 | 48 | // move the mouse to enabled 49 | // wait 50 | // move the mouse to downloads 51 | // wait 52 | // click on PDF 53 | 54 | actions.moveToElement(enabled). 55 | pause(2000). 56 | moveToElement(downloads). 57 | pause(2000). 58 | click(pdf). 59 | build().perform(); 60 | 61 | } 62 | 63 | @Test 64 | public void dragAndDrop() throws InterruptedException { 65 | driver.get("https://demos.telerik.com/kendo-ui/dragdrop/index"); 66 | 67 | WebElement money = driver.findElement(By.id("draggable")); 68 | WebElement bank = driver.findElement(By.id("droptarget")); 69 | Thread.sleep(2000); 70 | 71 | // scroll 72 | actions.sendKeys(Keys.PAGE_DOWN).perform(); 73 | // actions.sendKeys(Keys.ARROW_DOWN).perform(); 74 | 75 | actions.dragAndDrop(money, bank).perform(); 76 | Thread.sleep(2000); 77 | } 78 | 79 | /* 80 | TASK 81 | do the drag and drop by chaining actions 82 | move mouse to source/money 83 | mouse down 84 | move mouse to target/bank 85 | mouse up 86 | */ 87 | 88 | @Test 89 | public void dragAndDropAgain() throws InterruptedException { 90 | driver.get("https://demos.telerik.com/kendo-ui/dragdrop/index"); 91 | 92 | WebElement money = driver.findElement(By.id("draggable")); 93 | WebElement bank = driver.findElement(By.id("droptarget")); 94 | Thread.sleep(2000); 95 | actions.moveToElement(money).clickAndHold().moveToElement(bank).release().build().perform(); 96 | Thread.sleep(2000); 97 | 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day11_select_actions/JavaScriptExecutorTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day11_select_actions; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.JavascriptExecutor; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | import org.openqa.selenium.interactions.Actions; 9 | import org.testng.annotations.AfterMethod; 10 | import org.testng.annotations.BeforeMethod; 11 | import org.testng.annotations.Test; 12 | 13 | public class JavaScriptExecutorTests { 14 | WebDriver driver; 15 | JavascriptExecutor jse; 16 | 17 | @BeforeMethod 18 | public void beforeMethod() { 19 | driver = WebDriverFactory.getDriver("chrome"); 20 | jse = (JavascriptExecutor) driver; 21 | } 22 | 23 | @AfterMethod 24 | public void afterTest() { 25 | driver.quit(); 26 | } 27 | 28 | @Test 29 | public void scroll() throws InterruptedException { 30 | driver.get("http://practice.cybertekschool.com/"); 31 | 32 | WebElement link = driver.findElement(By.linkText("Cybertek School")); 33 | Thread.sleep(2000); 34 | jse.executeScript("arguments[0].scrollIntoView(true);", link); 35 | 36 | Thread.sleep(2000); 37 | } 38 | 39 | @Test 40 | public void sendKeysWithJS(){ 41 | 42 | driver.get("http://practice.cybertekschool.com/dynamic_controls"); 43 | 44 | WebElement input = driver.findElement(By.cssSelector("input[disabled]")); 45 | 46 | String text = "hi world"; 47 | 48 | jse.executeScript("arguments[0].setAttribute('value', '" + text +"')", input); 49 | 50 | // arguments[0].setAttribute('value', 'HELLO WORLD') 51 | 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day11_select_actions/SelectClassTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day11_select_actions; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.support.ui.Select; 8 | import org.testng.Assert; 9 | import org.testng.annotations.AfterMethod; 10 | import org.testng.annotations.BeforeMethod; 11 | import org.testng.annotations.Test; 12 | 13 | import java.text.SimpleDateFormat; 14 | import java.time.LocalDate; 15 | import java.util.ArrayList; 16 | import java.util.Arrays; 17 | import java.util.Date; 18 | import java.util.List; 19 | 20 | public class SelectClassTests { 21 | WebDriver driver; 22 | 23 | @BeforeMethod 24 | public void beforeMethod() { 25 | driver = WebDriverFactory.getDriver("chrome"); 26 | driver.get("http://practice.cybertekschool.com/dropdown"); 27 | 28 | } 29 | 30 | @AfterMethod 31 | public void afterTest() { 32 | driver.quit(); 33 | } 34 | 35 | @Test 36 | public void getSelectedOption() { 37 | // FIND THE ELEMENT THAT HAS SELECT TAG 38 | WebElement dropdown = driver.findElement(By.id("dropdown")); 39 | 40 | // create a select class using the web element 41 | Select dropdownList = new Select(dropdown); 42 | 43 | // get the selected option 44 | WebElement selectedOption = dropdownList.getFirstSelectedOption(); 45 | System.out.println(selectedOption.getText()); 46 | // verify selected option 47 | Assert.assertEquals(selectedOption.getText(), "Please select an option"); 48 | } 49 | 50 | @Test 51 | public void selectFromList() throws InterruptedException { 52 | // get the element with select tag 53 | WebElement dropdown = driver.findElement(By.id("state")); 54 | // create select class 55 | Select states = new Select(dropdown); 56 | 57 | // TODO selectByVisibleText --> selects by the text of the option 58 | states.selectByVisibleText("Iowa"); 59 | Thread.sleep(1000); 60 | states.selectByVisibleText("Vermont"); 61 | Thread.sleep(1000); 62 | states.selectByVisibleText("Kentucky"); 63 | Thread.sleep(1000); 64 | 65 | // TODO selectByIndex --> selects based on the index of the option, 0 based count 66 | states.selectByIndex(0); 67 | Thread.sleep(1000); 68 | states.selectByIndex(10); 69 | Thread.sleep(1000); 70 | states.selectByIndex(20); 71 | Thread.sleep(1000); 72 | 73 | // TODO selectByValue--> selects based on the value of the value attribute of the option 74 | // TODO selectByValue --> it is not select text 75 | states.selectByValue("VA"); 76 | Thread.sleep(1000); 77 | states.selectByValue("SC"); 78 | Thread.sleep(1000); 79 | states.selectByValue("CO"); 80 | Thread.sleep(1000); 81 | states.selectByValue("NE"); 82 | 83 | } 84 | 85 | @Test 86 | public void getAllAvailableOptions() { 87 | Select monthList = new Select(driver.findElement(By.id("month"))); 88 | 89 | // print the current selection 90 | System.out.println(monthList.getFirstSelectedOption().getText()); 91 | 92 | // TODO getOptions--> returns all of the availabe options from dropdown 93 | List allOptions = monthList.getOptions(); 94 | 95 | System.out.println("Number of months: " + allOptions.size()); 96 | 97 | for (WebElement month : allOptions) { 98 | System.out.println(month.getText()); 99 | } 100 | 101 | // verify that months list always shows the current month as selected 102 | // get the current month 103 | String expected = LocalDate.now().getMonth().name(); 104 | String actual = monthList.getFirstSelectedOption().getText(); 105 | Assert.assertEquals(actual.toLowerCase(), expected.toLowerCase()); 106 | 107 | // verify that months list has following values: January....December 108 | List expectedMonths = Arrays.asList("January", "February", "March", "April", "May", "June", "July", "August", 109 | "September", "October", "November", "December"); 110 | 111 | 112 | // get options gives me list webelements, so allOptions is alist of web elemetns 113 | // but my expected it a list strings. i have to make sure the both list of strings 114 | // i need to get lsit string from list of webeelment 115 | 116 | List actualMonths = new ArrayList<>(); 117 | for (WebElement option : allOptions) { 118 | actualMonths.add(option.getText()); 119 | } 120 | Assert.assertEquals(actualMonths, expectedMonths); 121 | 122 | } 123 | 124 | 125 | @Test 126 | public void verifyOptions(){ 127 | Select list = new Select(driver.findElement(By.id("dropdown"))); 128 | // verify that list has 3 options 129 | int expectedSize = 3; 130 | int actualSize = list.getOptions().size(); 131 | 132 | List expectedValues = Arrays.asList("Please select an option", "Option 1", "Option 2"); 133 | 134 | List actualValues = new ArrayList<>(); 135 | for (WebElement option : list.getOptions()) { 136 | actualValues.add(option.getText()); 137 | } 138 | 139 | Assert.assertEquals(actualValues, expectedValues); 140 | 141 | } // BREAK 2.03 142 | } 143 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day12_pops_tabs_alerts_iframes/IframeExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day12_pops_tabs_alerts_iframes; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.testng.annotations.AfterMethod; 8 | import org.testng.annotations.BeforeMethod; 9 | import org.testng.annotations.Test; 10 | 11 | public class IframeExample { 12 | 13 | 14 | WebDriver driver; 15 | 16 | @BeforeMethod 17 | public void beforeMethod() { 18 | driver = WebDriverFactory.getDriver("chrome"); 19 | } 20 | 21 | @AfterMethod 22 | public void afterTest() { 23 | driver.quit(); 24 | } 25 | 26 | @Test 27 | public void test() throws InterruptedException { 28 | driver.get("http://practice.cybertekschool.com/tinymce"); 29 | 30 | // we will switch to iframe. 31 | // TODO switch by id/name 32 | driver.switchTo().frame("mce_0_ifr"); 33 | 34 | WebElement textBox = driver.findElement(By.id("tinymce")); 35 | textBox.clear(); 36 | textBox.sendKeys("great.thanks"); 37 | 38 | // get out fo the frame 39 | driver.switchTo().defaultContent(); 40 | System.out.println(driver.findElement(By.tagName("h3")).getText()); 41 | 42 | // TODO switch by webelement 43 | WebElement frame = driver.findElement(By.tagName("iframe")); 44 | driver.switchTo().frame(frame); 45 | 46 | textBox = driver.findElement(By.id("tinymce")); 47 | textBox.clear(); 48 | textBox.sendKeys("great.thanks one time"); 49 | 50 | // get out of the frame 51 | driver.switchTo().parentFrame(); 52 | System.out.println(driver.findElement(By.tagName("h3")).getText()); 53 | 54 | // TODO switch by index 55 | driver.switchTo().frame(0); 56 | 57 | textBox = driver.findElement(By.id("tinymce")); 58 | textBox.clear(); 59 | textBox.sendKeys("great.thanks last time"); 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day12_pops_tabs_alerts_iframes/PopupAndAlertsExamples.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day12_pops_tabs_alerts_iframes; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.*; 5 | import org.openqa.selenium.interactions.Actions; 6 | import org.testng.annotations.AfterMethod; 7 | import org.testng.annotations.BeforeMethod; 8 | import org.testng.annotations.Test; 9 | 10 | public class PopupAndAlertsExamples { 11 | 12 | 13 | WebDriver driver; 14 | 15 | @BeforeMethod 16 | public void beforeMethod() { 17 | driver = WebDriverFactory.getDriver("chrome"); 18 | } 19 | 20 | @AfterMethod 21 | public void afterTest() { 22 | driver.quit(); 23 | } 24 | 25 | @Test 26 | public void htmlPopup() throws InterruptedException { 27 | driver.get("https://www.primefaces.org/showcase/ui/overlay/confirmDialog.xhtml"); 28 | WebElement button = driver.findElement(By.xpath("//span[text()='Destroy the World']")); 29 | button.click(); 30 | 31 | Thread.sleep(1000); 32 | WebElement noooo = driver.findElement(By.xpath("//span[.='No']")); 33 | noooo.click(); 34 | Thread.sleep(1000); 35 | } 36 | 37 | @Test 38 | public void jsAlertsAccept() { 39 | driver.get("http://practice.cybertekschool.com/javascript_alerts"); 40 | 41 | WebElement button1 = driver.findElement(By.xpath("//button[1]")); 42 | button1.click(); 43 | 44 | Alert alert = driver.switchTo().alert(); 45 | alert.accept(); 46 | } 47 | 48 | @Test 49 | public void jsAlertsCancel() { 50 | driver.get("http://practice.cybertekschool.com/javascript_alerts"); 51 | 52 | WebElement button2 = driver.findElement(By.xpath("//button[2]")); 53 | button2.click(); 54 | 55 | Alert alert = driver.switchTo().alert(); 56 | alert.dismiss(); 57 | } 58 | 59 | @Test 60 | public void jsAlertsSendkeys() { 61 | driver.get("http://practice.cybertekschool.com/javascript_alerts"); 62 | 63 | WebElement button3 = driver.findElement(By.xpath("//button[3]")); 64 | // button3.click(); 65 | 66 | Alert alert = null; 67 | try { 68 | alert = driver.switchTo().alert(); 69 | alert.sendKeys("Admiral Kunkka"); 70 | alert.accept(); 71 | 72 | } catch (NoAlertPresentException e) { 73 | e.printStackTrace(); 74 | } 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day12_pops_tabs_alerts_iframes/TabsAndWindowsExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day12_pops_tabs_alerts_iframes; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.testng.annotations.AfterMethod; 8 | import org.testng.annotations.BeforeMethod; 9 | import org.testng.annotations.Test; 10 | 11 | import java.util.Set; 12 | 13 | public class TabsAndWindowsExample { 14 | 15 | WebDriver driver; 16 | 17 | @BeforeMethod 18 | public void beforeMethod() { 19 | driver = WebDriverFactory.getDriver("chrome"); 20 | } 21 | 22 | @AfterMethod 23 | public void afterTest() { 24 | // driver.quit(); 25 | } 26 | 27 | @Test 28 | public void test(){ 29 | driver.get("http://practice.cybertekschool.com/windows"); 30 | WebElement link = driver.findElement(By.linkText("Click Here")); 31 | link.click(); 32 | 33 | // get all the available tabs 34 | Set windowHandles = driver.getWindowHandles(); 35 | 36 | // print all the windows handles 37 | for (String windowHandle : windowHandles) { 38 | System.out.println(windowHandle); 39 | } 40 | 41 | // get the id of current window/tab 42 | String currentWindow = driver.getWindowHandle(); 43 | System.out.println("currentWindow = " + currentWindow); 44 | System.out.println("BEFORE SWITCHING"); 45 | System.out.println(driver.getTitle()); 46 | System.out.println(driver.findElement(By.tagName("h3")).getText()); 47 | 48 | for (String windowHandle : windowHandles) { 49 | driver.switchTo().window(windowHandle); 50 | if (driver.getTitle().equals("New Window")) { 51 | break; 52 | } 53 | } 54 | 55 | System.out.println("AFTER SWITCHING"); 56 | System.out.println(driver.getTitle()); 57 | System.out.println(driver.findElement(By.tagName("h3")).getText()); 58 | 59 | 60 | } 61 | 62 | // write a utility that takes a String title, 63 | // changes to tab with given title, 64 | // if such title is not found, go back to original window 65 | 66 | // write a utility that takes a String url, 67 | // changes to tab with given url, 68 | // if such url is not found, go back to original window 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day13_waits_and_synchronization/ExplicitWaitExamples.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day13_waits_and_synchronization; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.ElementClickInterceptedException; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | import org.openqa.selenium.support.ui.ExpectedConditions; 9 | import org.openqa.selenium.support.ui.FluentWait; 10 | import org.openqa.selenium.support.ui.Wait; 11 | import org.openqa.selenium.support.ui.WebDriverWait; 12 | import org.testng.Assert; 13 | import org.testng.annotations.AfterMethod; 14 | import org.testng.annotations.BeforeMethod; 15 | import org.testng.annotations.Test; 16 | 17 | import java.time.Duration; 18 | import java.util.NoSuchElementException; 19 | import java.util.concurrent.TimeUnit; 20 | 21 | public class ExplicitWaitExamples { 22 | 23 | WebDriver driver; 24 | // create web object 25 | WebDriverWait wait; 26 | 27 | @BeforeMethod 28 | public void setUp() { 29 | driver = WebDriverFactory.getDriver("firefox"); 30 | wait = new WebDriverWait(driver, 10); 31 | } 32 | 33 | @AfterMethod 34 | public void tearDown() { 35 | driver.quit(); 36 | } 37 | 38 | @Test 39 | public void test1TitleTest(){ 40 | driver.get("https://google.com"); 41 | 42 | System.out.println(driver.getTitle()); 43 | 44 | driver.get("https://store.steampowered.com/"); 45 | 46 | // wait for the title of the second page 47 | 48 | // start waiting for title contain text 49 | wait.until(ExpectedConditions.titleContains("Steam")); 50 | 51 | System.out.println(driver.getTitle()); 52 | 53 | } 54 | 55 | @Test 56 | public void test2WaitForVisible(){ 57 | driver.get("http://practice.cybertekschool.com/dynamic_loading/1"); 58 | 59 | WebElement button = driver.findElement(By.tagName("button")); 60 | button.click(); 61 | 62 | WebElement username = driver.findElement(By.id("username")); 63 | WebElement password = driver.findElement(By.id("pwd")); 64 | 65 | // waits for given element to be visible on page 66 | wait.until(ExpectedConditions.visibilityOf(username)); 67 | // make sure that username is visible on page 68 | Assert.assertTrue(username.isDisplayed()); 69 | username.sendKeys("johndoe"); 70 | } 71 | 72 | // THIS WILL THROW EXCEPTION 73 | @Test 74 | public void test3WaitForVisibleFail(){ 75 | driver.get("http://practice.cybertekschool.com/dynamic_loading/1"); 76 | 77 | WebElement button = driver.findElement(By.tagName("button")); 78 | button.click(); 79 | 80 | WebElement username = driver.findElement(By.id("username")); 81 | WebElement password = driver.findElement(By.id("pwd")); 82 | 83 | // give no,t enough time. change the wait time 84 | wait.withTimeout(Duration.ofSeconds(2)); 85 | 86 | // waits for given element to be visible on page 87 | wait.until(ExpectedConditions.visibilityOf(username)); 88 | // make sure that username is visible on page 89 | Assert.assertTrue(username.isDisplayed()); 90 | username.sendKeys("johndoe"); 91 | } 92 | 93 | @Test 94 | public void test4WaitForClickable(){ 95 | driver.get("http://practice.cybertekschool.com/dynamic_loading/6"); 96 | 97 | WebElement username = driver.findElement(By.id("username")); 98 | WebElement password = driver.findElement(By.id("pwd")); 99 | WebElement submit = driver.findElement(By.tagName("button")); 100 | 101 | Assert.assertTrue(username.isDisplayed()); 102 | username.sendKeys("tomsmith"); 103 | password.sendKeys("SuperSecretPassword"); 104 | 105 | // wait for element to disappear. 106 | // wait until the overlay element disappears 107 | WebElement overlay = driver.findElement(By.className("loadingoverlay")); 108 | wait.until(ExpectedConditions.invisibilityOf(overlay)); 109 | 110 | // waits for given element to be clickable 111 | wait.until(ExpectedConditions.elementToBeClickable(submit)); 112 | submit.click(); 113 | 114 | } 115 | 116 | @Test 117 | public void test4WaitForInvisible(){ 118 | driver.manage().window().maximize(); 119 | driver.get("http://qa3.vytrack.com"); 120 | WebElement username = driver.findElement(By.id("prependedInput")); 121 | username.sendKeys("salesmanager110"); 122 | WebElement password = driver.findElement(By.id("prependedInput2")); 123 | password.sendKeys("UserUser123"); 124 | password.submit(); 125 | 126 | driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); 127 | 128 | WebElement myCalendar = driver.findElement(By.linkText("My Calendar")); 129 | 130 | // wait until the element with class loader-mask is not visible 131 | 132 | wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".loader-mask"))); 133 | myCalendar.click(); 134 | 135 | } 136 | 137 | 138 | @Test 139 | public void test5Fluent(){ 140 | 141 | driver.get("http://practice.cybertekschool.com/dynamic_loading/6"); 142 | 143 | Wait fluentWait = new FluentWait<>(driver). 144 | withTimeout(Duration.ofSeconds(10)). 145 | pollingEvery(Duration.ofSeconds(5)). 146 | ignoring(NoSuchElementException.class). 147 | ignoring(ElementClickInterceptedException.class); 148 | 149 | 150 | WebElement submitBtn = fluentWait.until(driver -> driver.findElement(By.xpath("//button[text()='Submit']"))); 151 | 152 | driver.findElement(By.name("username")).sendKeys("tomsmith"); 153 | driver.findElement(By.name("password")).sendKeys("SuperSecretPassword"); 154 | 155 | submitBtn.click(); 156 | 157 | } 158 | 159 | } 160 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day13_waits_and_synchronization/ImplicitWaitExamples.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day13_waits_and_synchronization; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.testng.Assert; 8 | import org.testng.annotations.AfterMethod; 9 | import org.testng.annotations.BeforeMethod; 10 | import org.testng.annotations.Test; 11 | 12 | import java.util.concurrent.TimeUnit; 13 | 14 | public class ImplicitWaitExamples { 15 | 16 | WebDriver driver; 17 | 18 | @BeforeMethod 19 | public void setUp() { 20 | driver = WebDriverFactory.getDriver("chrome"); 21 | driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 22 | 23 | } 24 | 25 | @AfterMethod 26 | public void tearDown() { 27 | driver.quit(); 28 | } 29 | 30 | 31 | @Test 32 | public void test1(){ 33 | 34 | driver.get("http://practice.cybertekschool.com/dynamic_loading/4"); 35 | 36 | WebElement message = driver.findElement(By.cssSelector("#finish>h4")); 37 | 38 | Assert.assertTrue(message.isDisplayed()); 39 | System.out.println(message.getText()); 40 | 41 | driver.get("http://practice.cybertekschool.com/dynamic_loading/2"); 42 | WebElement button = driver.findElement(By.tagName("button")); 43 | button.click(); 44 | 45 | message = driver.findElement(By.cssSelector("#finish>h4")); 46 | 47 | Assert.assertTrue(message.isDisplayed()); 48 | System.out.println(message.getText()); 49 | 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day13_waits_and_synchronization/RandomStuff.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day13_waits_and_synchronization; 2 | 3 | import org.openqa.selenium.By; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.support.ui.ExpectedConditions; 6 | import org.openqa.selenium.support.ui.WebDriverWait; 7 | import org.testng.Assert; 8 | import org.testng.annotations.Test; 9 | 10 | public class RandomStuff { 11 | WebDriver driver; 12 | WebDriverWait wait; 13 | 14 | @Test 15 | public void test() { 16 | // wait until title changes 17 | wait.until(ExpectedConditions.titleContains("Steam")); 18 | 19 | // verify the title 20 | Assert.assertTrue(driver.getTitle().contains("Steam")); 21 | 22 | // wait until title changes and get the boolean value at the end. use it in assertion 23 | Assert.assertTrue(wait.until(ExpectedConditions.titleContains("Steam"))); 24 | 25 | Assert.assertTrue(wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id"))).isDisplayed()); 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day13_waits_and_synchronization/ThreadSleepExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day13_waits_and_synchronization; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.testng.Assert; 8 | import org.testng.annotations.AfterMethod; 9 | import org.testng.annotations.BeforeMethod; 10 | import org.testng.annotations.Test; 11 | 12 | public class ThreadSleepExample { 13 | 14 | WebDriver driver; 15 | 16 | @BeforeMethod 17 | public void setUp() { 18 | driver = WebDriverFactory.getDriver("chrome"); 19 | 20 | } 21 | 22 | @AfterMethod 23 | public void tearDown() { 24 | driver.quit(); 25 | } 26 | 27 | @Test 28 | public void test1() throws InterruptedException { 29 | driver.get("http://practice.cybertekschool.com/dynamic_loading/4"); 30 | 31 | Thread.sleep(7000); 32 | 33 | WebElement message = driver.findElement(By.cssSelector("#finish>h4")); 34 | 35 | Assert.assertTrue(message.isDisplayed()); 36 | System.out.println(message.getText()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day13_waits_and_synchronization/VytrachLoginTestWithWait.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day13_waits_and_synchronization; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.testng.Assert; 8 | import org.testng.annotations.AfterMethod; 9 | import org.testng.annotations.BeforeMethod; 10 | import org.testng.annotations.Test; 11 | 12 | import java.util.concurrent.TimeUnit; 13 | 14 | public class VytrachLoginTestWithWait { 15 | WebDriver driver; 16 | 17 | @BeforeMethod 18 | public void setUp() { 19 | driver = WebDriverFactory.getDriver("firefox"); 20 | driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); 21 | 22 | } 23 | 24 | @AfterMethod 25 | public void tearDown() { 26 | driver.quit(); 27 | } 28 | 29 | @Test 30 | public void test() { 31 | driver.get("http://qa3.vytrack.com"); 32 | WebElement username = driver.findElement(By.id("prependedInput")); 33 | username.sendKeys("salesmanager110"); 34 | WebElement password = driver.findElement(By.id("prependedInput2")); 35 | password.sendKeys("UserUser123"); 36 | password.submit(); 37 | 38 | 39 | WebElement pageName = driver.findElement(By.cssSelector(".oro-subtitle")); 40 | Assert.assertEquals(pageName.getText(), "Dashboard"); 41 | 42 | Assert.assertEquals(driver.getTitle(), "Dashboard"); 43 | } 44 | 45 | 46 | @Test 47 | public void test2(){ 48 | driver.get("http://practice.cybertekschool.com/dynamic_loading/3"); 49 | 50 | WebElement input = driver.findElement(By.tagName("input")); 51 | 52 | input.sendKeys("t shirt"); 53 | } 54 | 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day14_test_base_props_driver/FileUploadTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day14_test_base_props_driver; 2 | 3 | import com.cybertek.base.TestBase; 4 | import com.cybertek.utilities.ConfigurationReader; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.WebElement; 7 | import org.testng.Assert; 8 | import org.testng.annotations.Test; 9 | 10 | public class FileUploadTests extends TestBase { 11 | /* 12 | go to practice website 13 | click on file upload link 14 | upload a file 15 | click submit 16 | very file name is displayed in next page 17 | */ 18 | 19 | @Test 20 | public void fileUploadTest() { 21 | String url = ConfigurationReader.getProperty("url"); 22 | driver.get(url); 23 | 24 | WebElement file_upload = driver.findElement(By.linkText("File Upload")); 25 | file_upload.click(); 26 | 27 | WebElement fileInput = driver.findElement(By.id("file-upload")); 28 | 29 | fileInput.sendKeys("/Users/marufjon/Desktop/my_file.txt"); 30 | 31 | WebElement submit = driver.findElement(By.id("file-submit")); 32 | submit.click(); 33 | 34 | WebElement uploadedFile = driver.findElement(By.id("uploaded-files")); 35 | Assert.assertEquals(uploadedFile.getText(), "my_file.txt"); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day14_test_base_props_driver/PropertiesExamples.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day14_test_base_props_driver; 2 | 3 | import com.cybertek.utilities.ConfigurationReader; 4 | import com.cybertek.utilities.WebDriverFactory; 5 | import org.openqa.selenium.WebDriver; 6 | import org.testng.annotations.Test; 7 | 8 | import java.util.Properties; 9 | 10 | public class PropertiesExamples { 11 | 12 | @Test 13 | public void test(){ 14 | 15 | System.out.println(System.getProperty("os.name")); 16 | System.out.println(System.getProperty("os.version")); 17 | System.out.println(System.getProperty("user.home")); 18 | System.out.println(System.getProperty("user.name")); 19 | 20 | // browser url 21 | // Properties --> class from java that saves key value combinations 22 | Properties properties = new Properties(); 23 | properties.setProperty("browser", "chrome"); 24 | properties.setProperty("url", "http://practice.cybertekschool.com"); 25 | 26 | String browser = properties.getProperty("browser"); 27 | System.out.println("browser name= " + browser); 28 | 29 | // i need the browser/url from properties file 30 | 31 | String pBrowser = ConfigurationReader.getProperty("browser"); 32 | System.out.println("pBrowser =" + pBrowser); 33 | 34 | String pUrl = ConfigurationReader.getProperty("url"); 35 | 36 | System.out.println("pUrl = " + pUrl); 37 | 38 | 39 | } 40 | 41 | @Test 42 | public void test2(){ 43 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 44 | 45 | // get the the from props file 46 | String url = ConfigurationReader.getProperty("url"); 47 | driver.get(url); 48 | driver.close(); 49 | String str = Singleton.getInstance().toUpperCase(); 50 | System.out.println(str); 51 | } 52 | 53 | @Test 54 | public void test3(){ 55 | String str = Singleton.getInstance(); 56 | System.out.println(str); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day14_test_base_props_driver/Singleton.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day14_test_base_props_driver; 2 | 3 | public class Singleton { 4 | // make constructor private 5 | private Singleton() { 6 | } 7 | 8 | private static String string; 9 | 10 | public static String getInstance() { 11 | if (string == null) { 12 | string = "chrome"; 13 | } 14 | return string; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day14_test_base_props_driver/TestingTestBaseTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day14_test_base_props_driver; 2 | 3 | import com.cybertek.base.TestBase; 4 | import com.cybertek.utilities.ConfigurationReader; 5 | import org.testng.Assert; 6 | import org.testng.annotations.Test; 7 | 8 | public class TestingTestBaseTests extends TestBase { 9 | 10 | @Test 11 | public void testTitle() { 12 | String url = ConfigurationReader.getProperty("url"); 13 | driver.get(url); 14 | 15 | Assert.assertEquals(driver.getTitle(), "Practice"); 16 | System.out.println(driver.getTitle()); 17 | System.out.println(driver.getCurrentUrl()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day15_webtables/WebTablesTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day15_webtables; 2 | 3 | import com.cybertek.base.TestBase; 4 | import com.cybertek.utilities.BrowserUtils; 5 | import com.cybertek.utilities.ConfigurationReader; 6 | import org.openqa.selenium.By; 7 | import org.openqa.selenium.WebElement; 8 | import org.testng.Assert; 9 | import org.testng.annotations.BeforeMethod; 10 | import org.testng.annotations.Test; 11 | 12 | import java.util.List; 13 | 14 | public class WebTablesTests extends TestBase { 15 | 16 | @BeforeMethod 17 | public void setUpTest() { 18 | String url = ConfigurationReader.getProperty("url"); 19 | driver.get(url); 20 | driver.findElement(By.linkText("Sortable Data Tables")).click(); 21 | 22 | } 23 | 24 | // GET WHOLE TABLE 25 | @Test 26 | public void printTable() { 27 | WebElement myTable = driver.findElement(By.id("table1")); 28 | System.out.println(myTable.getText()); 29 | } 30 | 31 | // GET ALL HEADERS 32 | @Test 33 | public void getHeaders() { 34 | // get all headers in a single element 35 | WebElement header = driver.findElement(By.tagName("thead")); 36 | System.out.println(header.getText()); 37 | 38 | // get all headers in a list 39 | List headers = driver.findElements(By.xpath("//table[@id='table1']//th")); 40 | System.out.println(headers.size()); 41 | // use BrowserUtils to get the list of headers as text and print 42 | System.out.println(BrowserUtils.getElementsText(headers)); 43 | 44 | } 45 | 46 | // GET table size 47 | @Test 48 | public void getTableSize() { 49 | // get number of cols 50 | List headers = driver.findElements(By.xpath("//table[@id='table1']//th")); 51 | System.out.println("Number columns: " + headers.size()); 52 | 53 | // get number of rows including header 54 | List rowsWithHeader = driver.findElements(By.xpath("//table[@id='table1']//tr")); 55 | System.out.println("Number of row with header: " + rowsWithHeader.size()); 56 | 57 | // get number of rows without header 58 | List rowsWithOutHeader = driver.findElements(By.xpath("//table[@id='table1']/tbody/tr")); 59 | System.out.println("Number of row without header: " + rowsWithOutHeader.size()); 60 | 61 | } 62 | 63 | // GET SINGLE ROW BY INDEX 64 | @Test 65 | public void getSingleRowByIndex() { 66 | // get the first row (in the body) 67 | WebElement row = driver.findElement(By.xpath("//table[@id='table1']/tbody/tr[1]")); 68 | System.out.println(row.getText()); 69 | 70 | // get the first row (in the body) dynamic xpath 71 | String xpath = getTableRowXpath(3); 72 | row = driver.findElement(By.xpath(xpath)); 73 | System.out.println(row.getText()); 74 | 75 | } 76 | 77 | // getTableRowXpath based on index 78 | public static String getTableRowXpath(int index) { 79 | String xpath = "//table[@id='table1']/tbody/tr[" + index + "]"; 80 | return xpath; 81 | } 82 | 83 | // GET SINGLE CELL BASED ON INDEX 84 | @Test 85 | public void getSingleBasedByIndex() { 86 | WebElement cell = driver.findElement(By.xpath("//table[@id='table1']/tbody/tr[1]/td[1]")); 87 | System.out.println(cell.getText()); 88 | 89 | String xpath = getCellXpathByIndex(2, 3); 90 | cell = driver.findElement(By.xpath(xpath)); 91 | System.out.println(cell.getText()); 92 | } 93 | 94 | public static String getCellXpathByIndex(int row, int column) { 95 | String xpath = "//table[@id='table1']/tbody/tr[" + row + "]/td[" + column + "]"; 96 | return xpath; 97 | } 98 | 99 | 100 | // GO THROUGH THE TABLE USING LOOPS AND GET ALL VALUES 101 | @Test 102 | public void iterateTheTableUsingLoops() { 103 | // get the number of rows 104 | int rowCount = getRowCount(); 105 | // get the number of cols 106 | int colCount = getColCount(); 107 | 108 | for (int i = 1; i <= rowCount; i++) { 109 | for (int j = 1; j <= colCount; j++) { 110 | String xpath = getCellXpathByIndex(i, j); 111 | WebElement cell = driver.findElement(By.xpath(xpath)); 112 | System.out.println(cell.getText()); 113 | } 114 | } 115 | } 116 | 117 | // returns number of rows excluding the table headers 118 | public int getRowCount() { 119 | return driver.findElements(By.xpath("//table[@id='table1']/tbody/tr")).size(); 120 | } 121 | 122 | // return number of rows 123 | public int getColCount() { 124 | return driver.findElements(By.xpath("//table[@id='table1']//th")).size(); 125 | 126 | } 127 | 128 | // GET CELL IN RELATION TO ANOTHER CELL 129 | // verify that Jason owes me $100.00 130 | @Test 131 | public void verifyCellValueByOtherCell(){ 132 | String firstName = "Jason"; 133 | 134 | String xpath = "//table[@id='table1']//td[2][.='"+firstName+"']/../td[4]"; 135 | WebElement amount = driver.findElement(By.xpath(xpath)); 136 | Assert.assertEquals(amount.getText(), "$100.00"); 137 | } 138 | 139 | // from Kateryna Medvedieva 140 | public String getXpathForValue(String value, String columnIdx){ 141 | String xpath = "/table[@id='table1']//td[.='" + value + "']/../td[" + columnIdx + "]"; 142 | return xpath; 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day16_page_object_model/NegativeLoginTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day16_page_object_model; 2 | 3 | import com.cybertek.base.TestBase; 4 | import com.cybertek.pages.LoginPage; 5 | import com.cybertek.utilities.ConfigurationReader; 6 | import org.testng.Assert; 7 | import org.testng.annotations.BeforeMethod; 8 | import org.testng.annotations.Test; 9 | 10 | public class NegativeLoginTests extends TestBase { 11 | 12 | LoginPage loginPage; 13 | 14 | @BeforeMethod 15 | public void setUpTests() { 16 | driver.get(ConfigurationReader.getProperty("vytrack_url")); 17 | loginPage = new LoginPage(); 18 | 19 | } 20 | 21 | @Test 22 | public void wrongUsernameTest() { 23 | loginPage.username.sendKeys("user30000"); 24 | loginPage.password.sendKeys("UserUser123"); 25 | loginPage.logIn.click(); 26 | 27 | String actual = loginPage.errorMessage.getText(); 28 | 29 | Assert.assertTrue(loginPage.errorMessage.isDisplayed()); 30 | Assert.assertEquals(actual, "Invalid user name or password."); 31 | } 32 | 33 | @Test 34 | public void wrongPasswordTest() { 35 | loginPage.username.sendKeys("SalesManager110"); 36 | loginPage.password.sendKeys("LC"); 37 | loginPage.logIn.click(); 38 | 39 | String actual = loginPage.errorMessage.getText(); 40 | Assert.assertEquals(actual, "Invalid user name or password."); 41 | Assert.assertTrue(loginPage.errorMessage.isDisplayed()); 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day16_page_object_model/PageHeadersTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day16_page_object_model; 2 | 3 | import com.cybertek.base.VytrackTestBase; 4 | import com.cybertek.utilities.ConfigurationReader; 5 | import org.openqa.selenium.support.ui.ExpectedConditions; 6 | import org.testng.annotations.Test; 7 | 8 | import static org.testng.Assert.assertEquals; 9 | 10 | 11 | public class PageHeadersTests extends VytrackTestBase { 12 | // go to vyrack 13 | // login as driver 14 | // verify header is "Quick Launchpad" 15 | 16 | @Test 17 | public void dashboardPageTest(){ 18 | 19 | test = report.createTest("Dashboard page title test"); 20 | 21 | String username = ConfigurationReader.getProperty("driver_username"); 22 | String password = ConfigurationReader.getProperty("driver_password"); 23 | test.info("Logging in to application"); 24 | loginPage.login(username, password); 25 | 26 | wait.until(ExpectedConditions.textToBePresentInElement(dashboardPage.pageHeader, "Quick Launchpad")); 27 | String actual = dashboardPage.pageHeader.getText(); 28 | test.info("Verifying page header text"); 29 | assertEquals(actual, "Quick Launchpad"); 30 | test.pass("PASS: Dashboard page title test"); 31 | 32 | } 33 | 34 | 35 | // go to vyrack 36 | // go to Fleet vehicles 37 | // login as driver 38 | // verify header is "Cars" 39 | 40 | @Test 41 | public void fleetVehiclesTest() throws InterruptedException { 42 | test = report.createTest("Vehicles page title test"); 43 | 44 | // use login to login 45 | String username = ConfigurationReader.getProperty("driver_username"); 46 | String password = ConfigurationReader.getProperty("driver_password"); 47 | test.info("Logging in to application"); 48 | test.info("Username: " + username); 49 | test.info("Password: " + password); 50 | loginPage.login(username, password); 51 | // use dashbaord change page 52 | 53 | test.info("Going to Fleet -> Vehicles"); 54 | wait.until(ExpectedConditions.elementToBeClickable(dashboardPage.fleet)); 55 | dashboardPage.fleet.click(); 56 | wait.until(ExpectedConditions.elementToBeClickable(dashboardPage.vehicles)); 57 | dashboardPage.vehicles.click(); 58 | 59 | // use the fllet / vehicles page to get text 60 | wait.until(ExpectedConditions.textToBePresentInElement(vehiclesPage.pageHeader, "Cars")); 61 | test.info("Verifying page header"); 62 | String actual = vehiclesPage.pageHeader.getText(); 63 | assertEquals(actual, "Carros"); 64 | test.pass("PASS: Vehicles page title test"); 65 | 66 | } 67 | 68 | // go to vyrack 69 | // go to Customer Contacts 70 | // login as driver 71 | // verify header is "Cars" 72 | 73 | @Test 74 | public void customersContacts() throws InterruptedException { 75 | test = report.createTest("Contacts page title test"); 76 | 77 | // use login to login 78 | String username = ConfigurationReader.getProperty("driver_username"); 79 | String password = ConfigurationReader.getProperty("driver_password"); 80 | test.info("Logging in to application"); 81 | test.info("Username: " + username); 82 | test.info("Password: " + password); 83 | loginPage.login(username, password); 84 | // use dashbaord change page 85 | 86 | test.info("Going to Customers -> Contacts"); 87 | dashboardPage.changeMenu("Customers", "Contacts"); 88 | 89 | // use the fllet / vehicles page to get text 90 | wait.until(ExpectedConditions.textToBePresentInElement(vehiclesPage.pageHeader, "Contacts")); 91 | test.info("Verifying page header"); 92 | String actual = vehiclesPage.pageHeader.getText(); 93 | assertEquals(actual, "Contacts"); 94 | test.pass("PASS: Contacts page title test"); 95 | 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day16_page_object_model/PositiveLoginTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day16_page_object_model; 2 | 3 | import com.cybertek.base.TestBase; 4 | import com.cybertek.pages.LoginPage; 5 | import com.cybertek.utilities.ConfigurationReader; 6 | import org.openqa.selenium.support.ui.ExpectedConditions; 7 | import org.openqa.selenium.support.ui.WebDriverWait; 8 | import org.testng.annotations.BeforeMethod; 9 | import org.testng.annotations.Test; 10 | 11 | import static org.testng.Assert.*; 12 | 13 | public class PositiveLoginTests extends TestBase { 14 | 15 | LoginPage loginPage; 16 | WebDriverWait wait; 17 | 18 | @BeforeMethod 19 | public void setUpTests() { 20 | driver.get(ConfigurationReader.getProperty("vytrack_url")); 21 | loginPage = new LoginPage(); 22 | wait = new WebDriverWait(driver, 5); 23 | 24 | } 25 | 26 | @Test 27 | public void loginAsDrivers(){ 28 | String username = ConfigurationReader.getProperty("driver_username"); 29 | String password = ConfigurationReader.getProperty("driver_password"); 30 | loginPage.login(username, password); 31 | wait.until(ExpectedConditions.titleIs("Dashboard")); 32 | String actualTitle = driver.getTitle(); 33 | assertEquals(actualTitle, "Dashboard"); 34 | 35 | } 36 | 37 | @Test 38 | public void loginAsSalesManger(){ 39 | String username = ConfigurationReader.getProperty("sales_manager_username"); 40 | String password = ConfigurationReader.getProperty("sales_manager_password"); 41 | loginPage.login(username, password); 42 | wait.until(ExpectedConditions.titleIs("Dashboard")); 43 | String actualTitle = driver.getTitle(); 44 | assertEquals(actualTitle, "Dashboard"); 45 | 46 | } 47 | 48 | @Test 49 | public void loginAsStoreManager(){ 50 | String username = ConfigurationReader.getProperty("store_manager_username"); 51 | String password = ConfigurationReader.getProperty("store_manager_password"); 52 | loginPage.login(username, password); 53 | 54 | wait.until(ExpectedConditions.titleIs("Dashboard")); 55 | assertEquals(driver.getTitle(), "Dashboard"); 56 | 57 | } 58 | 59 | 60 | 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day17_ddt_dataprovider_pom2/CreateCalendarEventTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day17_ddt_dataprovider_pom2; 2 | 3 | import com.cybertek.base.VytrackTestBase; 4 | import com.cybertek.utilities.ConfigurationReader; 5 | import org.testng.annotations.Test; 6 | 7 | import static org.testng.Assert.assertFalse; 8 | 9 | public class CreateCalendarEventTests extends VytrackTestBase { 10 | 11 | @Test 12 | public void allDayEventCheckBoxTest(){ 13 | loginPage.login(ConfigurationReader.getProperty("driver_username"), 14 | ConfigurationReader.getProperty("driver_password")); 15 | driver.get("https://qa3.vytrack.com/calendar/event/create"); 16 | assertFalse(createCalendarEventsPage.allDayEventCheckbox.isSelected()); 17 | 18 | } 19 | 20 | @Test 21 | public void repeatCheckBoxTest(){ 22 | loginPage.login(ConfigurationReader.getProperty("driver_username"), 23 | ConfigurationReader.getProperty("driver_password")); 24 | driver.get("https://qa3.vytrack.com/calendar/event/create"); 25 | assertFalse(createCalendarEventsPage.repeatCheckbox.isSelected()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day17_ddt_dataprovider_pom2/MenuOptionsTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day17_ddt_dataprovider_pom2; 2 | 3 | import com.cybertek.base.VytrackTestBase; 4 | import com.cybertek.utilities.BrowserUtils; 5 | import com.cybertek.utilities.ConfigurationReader; 6 | import org.openqa.selenium.support.ui.ExpectedConditions; 7 | import org.testng.Assert; 8 | import org.testng.annotations.DataProvider; 9 | import org.testng.annotations.Test; 10 | 11 | import java.util.Arrays; 12 | import java.util.List; 13 | 14 | import static org.testng.Assert.assertEquals; 15 | import static org.testng.Assert.assertTrue; 16 | 17 | public class MenuOptionsTests extends VytrackTestBase { 18 | 19 | 20 | @Test 21 | public void test() { 22 | loginPage.login(ConfigurationReader.getProperty("driver_username"), 23 | ConfigurationReader.getProperty("driver_password")); 24 | dashboardPage.changeMenu("Activities", "Calendar Events"); 25 | wait.until(ExpectedConditions.titleIs("Calendar Events - Activities")); 26 | assertEquals(driver.getTitle(), "Calendar Events - Activities"); 27 | 28 | } 29 | 30 | // DDT test 31 | @Test(dataProvider = "test-data") 32 | public void ddtTest(String menu1, String menu2, String expectedTitle){ 33 | loginPage.login(ConfigurationReader.getProperty("driver_username"), 34 | ConfigurationReader.getProperty("driver_password")); 35 | dashboardPage.changeMenu(menu1, menu2); 36 | wait.until(ExpectedConditions.titleContains(expectedTitle)); 37 | assertTrue(driver.getTitle().contains(expectedTitle)); 38 | 39 | } 40 | 41 | @DataProvider(name = "test-data") 42 | public Object[][] getData(){ 43 | return new Object[][]{ 44 | {"Fleet", "Vehicles", "Car"}, 45 | {"Fleet", "Vehicle Costs", "Vehicle Costs"}, 46 | {"Customers", "Contacts", "Contacts - Customers"}, 47 | {"Activities", "Calendar Events", "Calendar Events - Activities"}, 48 | {"System", "System Calendars", "System Calendars - System"} 49 | }; 50 | } 51 | 52 | // login as driver 53 | // verify that driven can see menu options Fleet, Customers, Activities, System 54 | 55 | @Test 56 | public void testAllOptionsDriver(){ 57 | loginPage.login(ConfigurationReader.getProperty("driver_username"), 58 | ConfigurationReader.getProperty("driver_password")); 59 | List expected = Arrays.asList("Fleet", "Customers", "Activities", "System"); 60 | List actualList = BrowserUtils.getElementsText(dashboardPage.menu1Options); 61 | assertEquals(actualList, expected); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day17_ddt_dataprovider_pom2/UserInfoDataDrivenTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day17_ddt_dataprovider_pom2; 2 | 3 | import org.testng.annotations.DataProvider; 4 | import org.testng.annotations.Test; 5 | 6 | public class UserInfoDataDrivenTests { 7 | 8 | @Test(dataProvider = "users") 9 | public void test(String username, String password, int number) { 10 | System.out.println("opening application"); 11 | System.out.println("login as: " + username); 12 | System.out.println("number is: " + number); 13 | System.out.println("verify info"); 14 | } 15 | 16 | @DataProvider(name = "users") 17 | public Object[][] getUsers() { 18 | return new Object[][] 19 | { 20 | {"user1", "UserUser123", 25}, 21 | {"salesmanager355", "UserUser123", 26}, 22 | {"storemanager355", "UserUser123", 236}, 23 | {"salesmanager4000", "UserUser123", 262}, 24 | }; 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day17_ddt_dataprovider_pom2/UserInfoDataDrivenTests2.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day17_ddt_dataprovider_pom2; 2 | 3 | import com.cybertek.base.VytrackTestBase; 4 | import com.cybertek.pages.LoginPage; 5 | import org.apache.commons.lang3.exception.ExceptionContext; 6 | import org.openqa.selenium.support.ui.ExpectedConditions; 7 | import org.testng.annotations.DataProvider; 8 | import org.testng.annotations.Test; 9 | 10 | import static org.testng.Assert.assertEquals; 11 | 12 | public class UserInfoDataDrivenTests2 extends VytrackTestBase { 13 | 14 | @Test(dataProvider = "usersList") 15 | public void test(String username, String password, String expectedName){ 16 | loginPage.login(username, password); 17 | wait.until(ExpectedConditions.titleIs("Dashboard")); 18 | String actualName = dashboardPage.accountHolderName.getText(); 19 | assertEquals(actualName, expectedName); 20 | 21 | } 22 | 23 | @DataProvider(name = "usersList") 24 | public Object[][] getUsers() { 25 | return new Object[][] 26 | { 27 | {"user1", "UserUser123", "John Doe"}, 28 | {"user2", "UserUser123", "John Doe"}, 29 | {"user3", "UserUser123", "John Doe"}, 30 | {"user4", "UserUser123", "Kyleigh Reichert"}, 31 | {"user5", "UserUser123", "Nona Carroll"}, 32 | {"user6", "UserUser123", "Raphael Gusikowski"}, 33 | {"user7", "UserUser123", "Dominique Deckow"}, 34 | {"user8", "UserUser123", "Valentine Bode"}, 35 | {"user9", "UserUser123", "Deborah Wolf"}, 36 | {"user10", "UserUser123", "Toney Hegmann"}, 37 | }; 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day18_html_report/ExtentReportExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day18_html_report; 2 | 3 | import com.aventstack.extentreports.ExtentReports; 4 | import com.aventstack.extentreports.ExtentTest; 5 | import com.aventstack.extentreports.reporter.ExtentHtmlReporter; 6 | import org.testng.annotations.AfterMethod; 7 | import org.testng.annotations.BeforeMethod; 8 | import org.testng.annotations.Test; 9 | 10 | public class ExtentReportExample { 11 | 12 | // used to set up a new report and build the reports 13 | ExtentReports report; 14 | 15 | // used to create the html report 16 | ExtentHtmlReporter htmlReporter; 17 | 18 | // used to define a test in report, do logging, mark test results 19 | ExtentTest test; 20 | 21 | @BeforeMethod 22 | public void setUp(){ 23 | // initialize the report 24 | report = new ExtentReports(); 25 | 26 | // i need to point to the location where report will be create 27 | // System.getProperty("user.dir") --> gets my current folder 28 | // + "/test-output/report.html" --> create folder test-output and in it create file report.html 29 | String path = System.getProperty("user.dir")+"/test-output/report.html"; 30 | // initialize the html reporter with the given path 31 | htmlReporter = new ExtentHtmlReporter(path); 32 | 33 | // set name for the report 34 | htmlReporter.config().setReportName("Vytrack Automated Tests"); 35 | 36 | // attach the html reporter to the report object 37 | report.attachReporter(htmlReporter); 38 | 39 | // set environment information 40 | report.setSystemInfo("Environment", "QA"); 41 | report.setSystemInfo("Browser", "Chrome"); 42 | 43 | } 44 | 45 | @Test 46 | public void test(){ 47 | // we have to create a test for every test case 48 | test = report.createTest("VYT-123 Title verification test"); 49 | test.info("Opening browser"); 50 | // driver = new Chromedriver 51 | test.info("going to website"); 52 | // driver.get(goole.com) 53 | test.info("verifying title"); 54 | // assertEquals(google, google) 55 | test.pass("VYT-123 Title verification test"); 56 | 57 | } 58 | 59 | @AfterMethod 60 | public void tearDown(){ 61 | // the report will be created when we call this line. 62 | // if we dont call flush method it will not be generated. 63 | // we do this at the end of everything. 64 | report.flush(); 65 | } 66 | 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day19_excel_io/ExcelUtilityDemo.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day19_excel_io; 2 | 3 | 4 | import com.cybertek.utilities.ExcelUtil; 5 | import org.testng.annotations.Test; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class ExcelUtilityDemo { 11 | private String filePath = "src/test/resources/Vytrack testusers.xlsx"; 12 | private String sheetName = "QA3-short"; 13 | @Test 14 | public void test() { 15 | 16 | ExcelUtil qa3Short = new ExcelUtil(filePath, sheetName); 17 | System.out.println(qa3Short.getColumnsNames()); 18 | 19 | String data [][] = qa3Short.getDataArray(); 20 | List> dataList = qa3Short.getDataList(); 21 | System.out.println(dataList); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day19_excel_io/ExcelWriteExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day19_excel_io; 2 | 3 | import org.apache.poi.ss.usermodel.Row; 4 | import org.apache.poi.ss.usermodel.Sheet; 5 | import org.apache.poi.ss.usermodel.Workbook; 6 | import org.apache.poi.ss.usermodel.WorkbookFactory; 7 | import org.testng.annotations.AfterMethod; 8 | import org.testng.annotations.BeforeMethod; 9 | import org.testng.annotations.Test; 10 | 11 | import java.io.FileInputStream; 12 | import java.io.FileNotFoundException; 13 | import java.io.FileOutputStream; 14 | import java.io.IOException; 15 | 16 | public class ExcelWriteExample { 17 | 18 | // path to the location of the excel file. 19 | private String filePath = "src/test/resources/Vytrack testusers.xlsx"; 20 | 21 | // creates connection between jvm and the file. 22 | private FileInputStream fileInputStream; 23 | 24 | // represents the excel file 25 | private Workbook workbook; 26 | 27 | // represents the sheet that contains the actual data 28 | private Sheet workSheet; 29 | 30 | @BeforeMethod 31 | public void setUp() throws IOException { 32 | // initialize the input stream by giving the file location. this is for reading the file. 33 | fileInputStream = new FileInputStream(filePath); 34 | 35 | // create the workbook the input stream 36 | // WorkbookFactory.create --> this is used to create workbook from inputstream 37 | workbook = WorkbookFactory.create(fileInputStream); 38 | 39 | // workbook.getSheetAt --> get the sheet from excel based on 0 based count 40 | // workSheet = workbook.getSheetAt(5); 41 | 42 | // workbook.getSheet --> get sheet using name 43 | workSheet = workbook.getSheet("QA3-short"); 44 | } 45 | 46 | 47 | @AfterMethod 48 | public void tearDown() throws IOException { 49 | workbook.close(); 50 | fileInputStream.close(); 51 | } 52 | 53 | 54 | @Test 55 | public void readAndWrite() throws IOException { 56 | // iterate get all the rows 57 | for (int i = 1; i < workSheet.getPhysicalNumberOfRows(); i++) { 58 | Row currentRow = workSheet.getRow(i); 59 | String username = currentRow.getCell(0).toString(); 60 | String password = currentRow.getCell(1).toString(); 61 | String firstname = currentRow.getCell(2).toString(); 62 | String lastname = currentRow.getCell(3).toString(); 63 | String result = currentRow.getCell(4).toString(); 64 | System.out.println("ROW " + i); 65 | System.out.println("username = " + username); 66 | System.out.println("password = " + password); 67 | System.out.println("firstname = " + firstname); 68 | System.out.println("lastname = " + lastname); 69 | System.out.println("result = " + result); 70 | // did some test, now want to write result back to excel 71 | // setCellValue --> enter the given text to cell 72 | currentRow.getCell(4).setCellValue("PASS"); 73 | // get the updated value 74 | result = currentRow.getCell(4).toString(); 75 | System.out.println("new result = " + result); 76 | 77 | } 78 | // FileOutputStream --> writes to files 79 | FileOutputStream fileOutputStream = new FileOutputStream("src/test/resources/Vytrack testusers2.xlsx"); 80 | // write the workbook into file 81 | workbook.write(fileOutputStream); 82 | 83 | // close the output stream 84 | fileOutputStream.close(); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day19_excel_io/ReadExcelExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day19_excel_io; 2 | 3 | import org.apache.poi.ss.usermodel.*; 4 | import org.testng.annotations.AfterMethod; 5 | import org.testng.annotations.BeforeMethod; 6 | import org.testng.annotations.Test; 7 | 8 | import java.io.FileInputStream; 9 | import java.io.IOException; 10 | 11 | public class ReadExcelExample { 12 | // path to the location of the excel file. 13 | private String filePath = "src/test/resources/Vytrack testusers.xlsx"; 14 | 15 | // creates connection between jvm and the file. 16 | private FileInputStream fileInputStream; 17 | 18 | // represents the excel file 19 | private Workbook workbook; 20 | 21 | // represents the sheet that contains the actual data 22 | private Sheet workSheet; 23 | 24 | @BeforeMethod 25 | public void setUp() throws IOException { 26 | // initialize the input stream by giving the file location 27 | fileInputStream = new FileInputStream(filePath); 28 | 29 | // create the workbook the input stream 30 | // WorkbookFactory.create --> this is used to create workbook from inputstream 31 | workbook = WorkbookFactory.create(fileInputStream); 32 | 33 | // workbook.getSheetAt --> get the sheet from excel based on 0 based count 34 | // workSheet = workbook.getSheetAt(5); 35 | 36 | // workbook.getSheet --> get sheet using name 37 | workSheet = workbook.getSheet("QA3-short"); 38 | } 39 | 40 | @Test 41 | public void rowAndColumnCount() { 42 | System.out.println(workSheet.getSheetName()); 43 | 44 | // returns the last row num based on 0 count 45 | int lastRownIndex = workSheet.getLastRowNum(); 46 | System.out.println("last row index = " + lastRownIndex); 47 | 48 | // gives us the number of rows 49 | int rowCount = workSheet.getPhysicalNumberOfRows(); 50 | System.out.println("rowCount = " + rowCount); 51 | 52 | // ther is no direct way to get the number of cols. 53 | // workSheet.getRow(0) --> we will get the first row and 54 | // getLastCellNum(); --> get number cells in that row 55 | 56 | int colCount = workSheet.getRow(0).getLastCellNum(); 57 | System.out.println("colCount = " + colCount); 58 | } 59 | 60 | 61 | @AfterMethod 62 | public void tearDown() throws IOException { 63 | workbook.close(); 64 | fileInputStream.close(); 65 | } 66 | 67 | 68 | @Test 69 | public void readSingleCell() { 70 | // to read data from cell: 71 | // workSheet.getRow(7)--> get the row using 0 based index 72 | // represents a row in worksheet 73 | Row row = workSheet.getRow(11); 74 | // row.getCell(2); --> get specific cell from that row, 0 based count 75 | // Cell --> represents a cell from a row 76 | Cell cell = row.getCell(2); 77 | // get data from the cell 78 | String value = cell.toString(); 79 | 80 | System.out.println("value = " + value); 81 | } 82 | 83 | @Test 84 | public void printWholeRow(){ 85 | // get the row 86 | Row row = workSheet.getRow(0); 87 | int colCount = row.getLastCellNum(); 88 | System.out.println("colCount = " + colCount); 89 | 90 | for (int i = 0; i < colCount; i++) { 91 | Cell cell = row.getCell(i); 92 | System.out.println("cell "+i+": = " + cell.toString()); 93 | 94 | } 95 | } 96 | 97 | @Test 98 | public void readWholeSheet(){ 99 | // i use nested for loop to get all excel data. outer loops gets the rows, inner loop get cells from specific row 100 | int rowCount = workSheet.getPhysicalNumberOfRows(); 101 | int colCount = workSheet.getRow(0).getLastCellNum(); 102 | System.out.println("rowCount = " + rowCount); 103 | System.out.println("colCount = " + colCount); 104 | 105 | // iterate through the table 106 | for (int i = 0; i < rowCount; i++) { 107 | // get row with current index 108 | Row currentRow = workSheet.getRow(i); 109 | // iterate through the row 110 | for (int j = 0; j < colCount; j++) { 111 | // get current cell 112 | Cell cell = currentRow.getCell(j); 113 | // get cell value 114 | String value = cell.toString(); 115 | System.out.print("row "+i+ ", col: "+ j+": " + value+"\t\t\t"); 116 | } 117 | System.out.println(); 118 | } 119 | } 120 | 121 | } 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day19_excel_io/VytrackExcelDDTTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day19_excel_io; 2 | 3 | import com.cybertek.base.VytrackTestBase; 4 | import org.apache.poi.ss.usermodel.*; 5 | import org.openqa.selenium.support.ui.ExpectedConditions; 6 | import org.testng.annotations.DataProvider; 7 | import org.testng.annotations.Test; 8 | 9 | import java.io.FileInputStream; 10 | import java.io.FileNotFoundException; 11 | import java.io.IOException; 12 | 13 | import static org.testng.Assert.assertEquals; 14 | 15 | public class VytrackExcelDDTTests extends VytrackTestBase { 16 | 17 | // this test will get test data from a data provider getUserData 18 | @Test(dataProvider = "getUserData") 19 | public void userDetailsTest(String username, String password, String firstname, String lastname) { 20 | test = report.createTest("User details test for "+username); 21 | test.info("login to vytrack"); 22 | loginPage.login(username, password); 23 | wait.until(ExpectedConditions.titleIs("Dashboard")); 24 | test.info("Get expected value"); 25 | String actualName = dashboardPage.accountHolderName.getText(); 26 | test.info("Verify username"); 27 | assertEquals(actualName, firstname + " " + lastname); 28 | test.pass("pass user details test for "+username); 29 | } 30 | 31 | @DataProvider(name = "getUserData") 32 | public Object[][] getData() throws IOException { 33 | // DataProvider has a return type 2d array 34 | // we have to read the excel file, put its contents into 2d array and return 35 | 36 | FileInputStream file = new FileInputStream("src/test/resources/Vytrack testusers.xlsx"); 37 | Workbook workbook = WorkbookFactory.create(file); 38 | Sheet workSheet = workbook.getSheet("QA3-short"); 39 | 40 | int rowCount = workSheet.getPhysicalNumberOfRows() - 1; 41 | int colCount = workSheet.getRow(0).getLastCellNum() - 1; 42 | // 2d array that willl contain the excel data 43 | Object[][] data = new Object[rowCount][colCount]; 44 | // iterate the worksheet. 45 | // i =1 --> start with second row 46 | // i <= rowCount --> including the last row 47 | for (int i = 1; i <= rowCount; i++) { 48 | // get the row current index 49 | Row row = workSheet.getRow(i); 50 | // iterate the inner loop 51 | for (int j = 0; j < colCount; j++) { 52 | // get each cell from the row 53 | Cell cell = row.getCell(j); 54 | data[i - 1][j] = cell.toString(); 55 | } 56 | } 57 | workbook.close(); 58 | file.close(); 59 | return data; // BREAK 2.05 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day1_Navigation/BookitTitleVerify.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day1_Navigation; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.chrome.ChromeDriver; 6 | 7 | public class BookitTitleVerify { 8 | 9 | public static void main(String[] args) { 10 | 11 | /* 12 | Task 1: 13 | 1. Go to Bookit login page 14 | https://cybertek-reservation-qa.herokuapp.com/sign-in 15 | 2. Verify the title of the page 16 | 17 | */ 18 | 19 | WebDriverManager.chromedriver().setup(); 20 | WebDriver driver = new ChromeDriver(); 21 | 22 | driver.get("https://cybertek-reservation-qa.herokuapp.com/sign-in"); 23 | 24 | driver.manage().window().maximize(); 25 | 26 | //expected vs actual 27 | 28 | String expectedTitle = "bookit"; 29 | String actualTitle = driver.getTitle(); 30 | 31 | if (expectedTitle.equals(actualTitle)){ 32 | System.out.println("Pass"); 33 | }else{ 34 | System.out.println("Fail"); 35 | System.out.println("I expect to see " + expectedTitle); 36 | System.out.println("The driver get " +actualTitle); 37 | } 38 | 39 | driver.close(); 40 | 41 | 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day1_Navigation/EtsyTitleVerify.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day1_Navigation; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.chrome.ChromeDriver; 6 | 7 | public class EtsyTitleVerify { 8 | 9 | public static void main(String[] args) { 10 | 11 | WebDriverManager.chromedriver().setup(); 12 | WebDriver driver = new ChromeDriver(); 13 | 14 | //go to etsy --> data URL : https://www.etsy.com/ 15 | 16 | driver.get("https://www.etsy.com/"); 17 | 18 | //verify title 19 | //expected vs actual 20 | 21 | String expectedTitle = "etsy - Shop for handmade, vintage, custom, and unique gifts for everyone"; 22 | 23 | String actualTitle = driver.getTitle(); 24 | 25 | if(expectedTitle.equalsIgnoreCase(actualTitle)){ 26 | System.out.println("The test is Pass"); 27 | }else { 28 | System.out.println("The test is Failed"); 29 | System.out.println(expectedTitle + " vs " + actualTitle); 30 | } 31 | 32 | driver.close(); 33 | 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day1_Navigation/FirstClass.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day1_Navigation; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.chrome.ChromeDriver; 6 | 7 | 8 | public class FirstClass { 9 | 10 | public static void main(String[] args) throws InterruptedException { 11 | //binary the driver and browsers 12 | WebDriverManager.chromedriver().setup(); 13 | 14 | //WebDriver object --> Interface 15 | //I have a driver 16 | WebDriver driver = new ChromeDriver(); 17 | 18 | //I want to open Google home page 19 | 20 | //how do you launch / open a web page? 21 | //by using get() --> url as String 22 | driver.get("https://www.google.com"); 23 | 24 | //Navigations 25 | //navigate().to() --> open a web page 26 | 27 | /// driver.navigate().to("https://www.google.com"); 28 | 29 | 30 | //get() vs navigate().to() 31 | //get --> wait to load the page 32 | //to() --> does not wait 33 | 34 | //nagivate().back() --> 35 | //1. go to google 2. go to cybertek practice webstite 36 | 37 | driver.get("https://www.google.com"); 38 | Thread.sleep(3000); 39 | driver.navigate().to("http://practice.cybertekschool.com/"); 40 | Thread.sleep(3000); 41 | driver.navigate().back(); 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day1_Navigation/Navigations.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day1_Navigation; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.chrome.ChromeDriver; 6 | 7 | public class Navigations { 8 | 9 | public static void main(String[] args) throws InterruptedException { 10 | /* 11 | Navigation: 12 | driver.navigate().to("URL") 13 | driver.navigate().back() 14 | driver.navigate().forward() 15 | driver.navigate().refresh() 16 | */ 17 | 18 | 19 | // go to practice --> go to google --> back to practice 20 | // --> forward to google 21 | 22 | WebDriverManager.chromedriver().setup(); 23 | 24 | WebDriver driver = new ChromeDriver(); 25 | 26 | ChromeDriver driver1 = new ChromeDriver(); 27 | 28 | 29 | 30 | 31 | String practiceWebURL = "http://practice.cybertekschool.com/"; 32 | // go to practice 33 | driver.get(practiceWebURL); 34 | 35 | //I want to see the full window 36 | // driver.manage().window().fullscreen(); 37 | driver.manage().window().maximize(); 38 | 39 | 40 | Thread.sleep(3000); 41 | 42 | // go to google 43 | String gglURL = "https://www.google.com"; 44 | driver.navigate().to(gglURL); 45 | Thread.sleep(3000); 46 | //back to practice 47 | driver.navigate().back(); 48 | 49 | Thread.sleep(3000); 50 | 51 | driver.navigate().forward(); 52 | 53 | driver.navigate().refresh(); 54 | 55 | 56 | //close drive 57 | //close the current web browser ONLY 58 | driver.close(); 59 | 60 | //close down all the windows in a browser 61 | driver.quit(); 62 | 63 | 64 | 65 | //come back at 1:50 pm 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day1_Navigation/VerifyBookItURL.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day1_Navigation; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.chrome.ChromeDriver; 6 | 7 | public class VerifyBookItURL { 8 | 9 | public static void main(String[] args) { 10 | /* 11 | Task 2: 12 | 2. Go to Bookit login page 13 | https://cybertek-reservation-qa.herokuapp.com/sign-in 14 | 2. Verify that URL contains “cybertek-reservation” 15 | */ 16 | 17 | 18 | WebDriverManager.chromedriver().setup(); 19 | WebDriver driver = new ChromeDriver(); 20 | 21 | driver.get("https://cybertek-reservation-qa.herokuapp.com/sign-in"); 22 | 23 | driver.manage().window().maximize(); 24 | 25 | String expectedPartialURL = "cybertek-reservation"; 26 | String actualURL = driver.getCurrentUrl(); 27 | //https://cybertek-reservation-qa.herokuapp.com/sign-in 28 | 29 | if(actualURL.contains(expectedPartialURL)){ 30 | System.out.println("Pass"); 31 | }else{ 32 | System.out.println("Fail"); 33 | System.out.println("expectedPartialURL: " + expectedPartialURL); 34 | System.out.println("Actual URL: " + actualURL); 35 | } 36 | 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day1_Navigation/VerifyTitle.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day1_Navigation; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.chrome.ChromeDriver; 6 | 7 | public class VerifyTitle { 8 | 9 | public static void main(String[] args) { 10 | /* 11 | 1. Go to cybertek practice web site 12 | 2. Verify Title expected title:Practice 13 | 14 | Actual Title? --> 15 | 16 | http://practice.cybertekschool.com/ 17 | */ 18 | 19 | //connect browser and driver 20 | //setup browser 21 | WebDriverManager.chromedriver().setup(); 22 | 23 | WebDriver driver = new ChromeDriver(); 24 | 25 | driver.get("http://practice.cybertekschool.com/"); 26 | 27 | driver.manage().window().maximize(); 28 | 29 | String expectedTitle = "practic"; 30 | 31 | String actualTitle = driver.getTitle(); 32 | 33 | if(expectedTitle.equals(actualTitle)){ 34 | System.out.println("PASS"); 35 | }else { 36 | System.out.println("FAIL"); 37 | System.out.println("I expected " + expectedTitle); 38 | System.out.println("The Actual title is " + actualTitle); 39 | } 40 | 41 | 42 | driver.close(); 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day1_Navigation/VerifyURL.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day1_Navigation; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.chrome.ChromeDriver; 6 | 7 | public class VerifyURL { 8 | 9 | /* 10 | 1. go to Etsy https://www.etsy.com/ 11 | 2. Verify URL 12 | 13 | */ 14 | 15 | public static void main(String[] args) { 16 | 17 | WebDriverManager.chromedriver().setup(); 18 | WebDriver driver = new ChromeDriver(); 19 | 20 | driver.get("https://www.etsy.com/"); 21 | driver.manage().window().maximize(); 22 | 23 | //for verify title --> getTitle() 24 | //for verify URL --> 25 | 26 | String expectedURL = "https://www.etsy.c/"; 27 | 28 | String actualURL = driver.getCurrentUrl(); 29 | 30 | if(expectedURL.equals(actualURL)){ 31 | System.out.println("pass"); 32 | }else { 33 | System.out.println("FAIL"); 34 | System.out.println("I expected " + expectedURL); 35 | System.out.println("The actual URL is: " + actualURL ); 36 | } 37 | 38 | driver.close(); 39 | 40 | 41 | 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day1_Navigation/VrifyURLOfPracticeWeb.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day1_Navigation; 2 | 3 | public class VrifyURLOfPracticeWeb { 4 | 5 | public static void main(String[] args) { 6 | /* 7 | 1. go to cybertek practice website 8 | http://practice.cybertekschool.com/ 9 | 2. verify the URL 10 | */ 11 | 12 | 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day1_Navigation/task1.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day1_Navigation; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.chrome.ChromeDriver; 6 | 7 | public class task1 { 8 | /* 9 | 1. Go to google webstite 10 | 2. save the title in a string variable 11 | 3. go to Etsy 12 | 4. save the Etst Title in a String 13 | 5. Navigate back to previouse page 14 | 6. Verify the title is same as step 2 15 | 7. Navigate forward to previoud page 16 | 8.Verify the title is same as step 4 17 | 18 | */ 19 | 20 | 21 | public static void main(String[] args) throws InterruptedException { 22 | WebDriverManager.chromedriver().setup(); 23 | 24 | WebDriver driver = new ChromeDriver(); 25 | 26 | //1. Go to google webstite 27 | driver.get("https://www.google.com"); 28 | 29 | //full screen 30 | driver.manage().window().maximize(); 31 | 32 | String gglexpectedTitle = "Google"; 33 | 34 | Thread.sleep(3000); 35 | driver.navigate().to("https://www.etsy.com/"); 36 | 37 | String etsyExpectedTitle = "Etsy - Shop for handmade, vintage, custom, and unique gifts for everyone"; 38 | 39 | Thread.sleep(3000); 40 | driver.navigate().back(); //google 41 | 42 | String actualGoogleTile = driver.getTitle(); 43 | 44 | if(gglexpectedTitle.equals(actualGoogleTile)){ 45 | System.out.println("pass"); 46 | }else { 47 | System.out.println("FAIL"); 48 | System.out.println("I expected title " + gglexpectedTitle); 49 | System.out.println("The actual URL is: " + actualGoogleTile ); 50 | } 51 | 52 | driver.navigate().forward(); //etsy 53 | 54 | String etsyActualTitile = driver.getTitle(); 55 | 56 | if(etsyExpectedTitle.equals(etsyActualTitile)){ 57 | System.out.println("pass"); 58 | }else { 59 | System.out.println("FAIL"); 60 | System.out.println("I expected Title" + etsyExpectedTitle); 61 | System.out.println("The actual URL is: " + etsyActualTitile ); 62 | } 63 | 64 | driver.close(); 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day20_jdbc/MySQLJDBCConnectionDemo.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day20_jdbc; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | import java.sql.*; 6 | 7 | public class MySQLJDBCConnectionDemo { 8 | /** 9 | * Vytrack Database connection information 10 | * Username cybertek_user 11 | * Password cybertek_user 12 | * qa3 url 107.23.27.171 13 | * port number 3306 14 | * sid bitnami_orocrm 15 | * 16 | * ME ---> WAITER ---> RESTAURANT KITCHEN 17 | * JAVA CODE USING SELENIUM ---> CHROME DRIVER --> CHROME BROWSER 18 | * JAVA CODE USING JDBC ---> DB DRIVER ---> DATABASE 19 | * 20 | * jbcs URLs formula "jdbc:database_type:@ip_address:port:sid" 21 | */ 22 | 23 | @Test 24 | public void test() throws SQLException { 25 | String url = "jdbc:mysql://107.23.27.171:3306/bitnami_orocrm"; 26 | String username = "cybertek_user"; 27 | String password = "cybertek_user"; 28 | 29 | // helps connect to the database 30 | Connection connection = DriverManager.getConnection(url, username, password); 31 | 32 | // helps write queries and execute them 33 | Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 34 | ResultSet.CONCUR_READ_ONLY); 35 | String query = "select first_name, last_name, description from orocrm_contact"; 36 | 37 | // stores the result of the query 38 | ResultSet resultSet = statement.executeQuery(query); 39 | 40 | while (resultSet.next()) { 41 | int colCount = resultSet.getMetaData().getColumnCount(); 42 | for (int i = 1; i <= colCount; i++) { 43 | String cellValue = resultSet.getString(i); 44 | System.out.print(cellValue+ "\t"); 45 | } 46 | System.out.println(); 47 | } 48 | 49 | // connection must be closed 50 | resultSet.close(); 51 | statement.close(); 52 | connection.close(); 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day20_jdbc/OracleJDBCConnectionDemo.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day20_jdbc; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | import java.sql.*; 6 | 7 | public class OracleJDBCConnectionDemo { 8 | /** 9 | * JDBC --> java api for connecting to database and manage connections, send queries etc 10 | * // when connecting to any database we need drivers specific to the database we want to connect to 11 | * // to make jdbc connection first we need to add the driver to the pom file 12 | * // in my project we use ORACLE so i have ojdbc8 dependency in my pom file 13 | * // in my project we use MYSQL so i have mysql-connector dependency in my pom file 14 | * // we need following database related information: 15 | * type of the database --> oracle 16 | * ip address of the database --> 54.226.100.111 17 | * post number of the data base --> 1521 18 | * SID (service name) or name of the database --> xe 19 | * these 4 pieces of information will be used to create 20 | * the connection URL 21 | * 22 | * we also need the username and password to login to the database. 23 | * jbcs URLs formula "jdbc:database_type:@ip_address:port:sid" 24 | * 25 | * 26 | **/ 27 | @Test 28 | public void test() throws SQLException { 29 | String url = "jdbc:oracle:thin:@54.226.100.111:1521:xe"; 30 | String username = "hr"; 31 | String password = "hr"; 32 | 33 | // DriverManager.getConnection --> this method is used to create connection 34 | // using url, username and password information 35 | // Connection --> class that represents the connection, helps connect to db 36 | Connection connection = DriverManager.getConnection(url, username, password); 37 | 38 | // Statement --> helps write sql queries and executes 39 | Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 40 | ResultSet.CONCUR_READ_ONLY); 41 | 42 | // the data that is returned as a result of query is stored in resultset 43 | // statement.executeQuery --> executed the query and returns the result in resultset object 44 | ResultSet resultSet = statement.executeQuery("select * from employees"); 45 | 46 | // metadata about the connection 47 | DatabaseMetaData dmetaData = connection.getMetaData(); 48 | System.out.println(dmetaData.getDatabaseProductName()); 49 | System.out.println(dmetaData.getDatabaseProductVersion()); 50 | System.out.println(dmetaData.getDriverName()); 51 | 52 | // metadata about the result 53 | ResultSetMetaData rmetaData = resultSet.getMetaData(); 54 | System.out.println(rmetaData.getColumnCount()); 55 | // get the name of the column, 1 based count 56 | System.out.println(rmetaData.getColumnName(1)); 57 | // get data type of the column 58 | System.out.println(rmetaData.getColumnTypeName(1)); 59 | 60 | // print names of all columns 61 | int numberOfColumns = rmetaData.getColumnCount(); 62 | for (int i = 1; i <= numberOfColumns; i++) { 63 | System.out.println(rmetaData.getColumnName(i)); 64 | } 65 | // absolute --> jumps to given row 66 | resultSet.absolute(1); 67 | // getObject --> returns the value of the cell under given column 68 | System.out.println(resultSet.getObject("first_name")); 69 | 70 | // get the name of the last person 71 | resultSet.last(); 72 | System.out.println(resultSet.getObject("first_name")); 73 | 74 | // getrow returns the current row number 75 | System.out.println("number of rows = " + resultSet.getRow()); 76 | 77 | // go back to first row 78 | resultSet.beforeFirst(); 79 | 80 | // iterate through the results 81 | // while loop will iterate through the rows of the result table 82 | while (resultSet.next()) { 83 | // for loop is for iterating the cells in the row 84 | for (int i = 1; i <= numberOfColumns; i++) { 85 | System.out.print(resultSet.getString(i)+"\t"); 86 | } 87 | System.out.println(); 88 | } 89 | 90 | // Make another call to db and get other result 91 | resultSet = statement.executeQuery("select distinct salary from employees e1 where 2 = (select count(distinct salary) from employees e2 where e1.salary <= e2.salary)"); 92 | 93 | resultSet.next(); 94 | System.out.println(resultSet.getString("salary")); 95 | } 96 | 97 | @Test 98 | public void updateAndDelete() throws SQLException { 99 | String url = "jdbc:oracle:thin:@18.232.121.19:1521:xe"; 100 | String username = "hr"; 101 | String password = "hr"; 102 | 103 | Connection connection = DriverManager.getConnection(url, username, password); 104 | 105 | Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 106 | ResultSet.CONCUR_READ_ONLY); 107 | 108 | ResultSet resultSet = statement.executeQuery("delete * from employees where first_name = 'Steven'"); 109 | resultSet = statement.executeQuery("UPDATE * from employees where first_name = 'Steven'"); 110 | 111 | } 112 | 113 | 114 | } 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day21_db_testing/CreateNewContactDBTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day21_db_testing; 2 | 3 | import com.cybertek.base.VytrackPageBase; 4 | import com.cybertek.base.VytrackTestBase; 5 | import com.cybertek.utilities.BrowserUtils; 6 | import com.cybertek.utilities.ConfigurationReader; 7 | import com.cybertek.utilities.DBUtils; 8 | import com.github.javafaker.Faker; 9 | import org.testng.annotations.BeforeMethod; 10 | import org.testng.annotations.Test; 11 | 12 | import java.util.Map; 13 | 14 | import static org.testng.Assert.assertEquals; 15 | 16 | public class CreateNewContactDBTest extends VytrackTestBase { 17 | 18 | @BeforeMethod 19 | public void setUp() { 20 | // create db connection 21 | String URL = "jdbc:mysql://" + ConfigurationReader.getProperty("qa3_db_host") + 22 | ":" + ConfigurationReader.getProperty("qa3_db_port") + 23 | "/" + ConfigurationReader.getProperty("qa3_db_name"); 24 | String username = ConfigurationReader.getProperty("qa3_db_username"); 25 | String password = ConfigurationReader.getProperty("qa3_db_password"); 26 | DBUtils.createConnection(URL, username, password); 27 | } 28 | 29 | @Test 30 | public void createContactTests() { 31 | 32 | test = report.createTest("Create contact db validatoin"); 33 | loginPage.login(ConfigurationReader.getProperty("sales_manager_username"), 34 | ConfigurationReader.getProperty("sales_manager_password")); 35 | driver.get("https://qa3.vytrack.com/contact/create"); 36 | // generate test data for creating new user 37 | Faker faker = new Faker(); 38 | String eFirstName = faker.name().firstName(); 39 | String eLastName = faker.name().lastName(); 40 | String company = faker.company().url().substring(4); 41 | String eEmail = eFirstName.toLowerCase() + eLastName.toLowerCase() + "@" + company; 42 | System.out.println("eEmail = " + eEmail); 43 | BrowserUtils.wait(3); 44 | // create new user with the given test data 45 | createContactsPage.firstName.sendKeys(eFirstName); 46 | createContactsPage.lastName.sendKeys(eLastName); 47 | createContactsPage.email.sendKeys(eEmail); 48 | createContactsPage.saveAndClose.click(); 49 | BrowserUtils.wait(3); 50 | 51 | // get the new user information: first name, last name, email from database based on email 52 | // first name, last name --. in the contact 53 | // email --. email 54 | // we have to use inner join to join the contact table and email table based on the id of the contact 55 | // use email in where of query to filter the results 56 | 57 | String sql = "select orocrm_contact.first_name, orocrm_contact.last_name, orocrm_contact_email.email \n" + 58 | "from orocrm_contact\n" + 59 | "join orocrm_contact_email\n" + 60 | "on orocrm_contact.id =orocrm_contact_email.owner_id\n" + 61 | "where orocrm_contact_email.email = '" + eEmail + "';\n"; 62 | System.out.println("sql = " + sql); 63 | 64 | Map dbData = DBUtils.getRowMap(sql); 65 | System.out.println(dbData); 66 | 67 | // extract the actual from the db onfp 68 | String actualFirstName = (String) dbData.get("first_name"); 69 | String actualLastName = (String) dbData.get("last_name"); 70 | String actualEmail = (String) dbData.get("email"); 71 | 72 | // verify 73 | assertEquals(actualFirstName, eFirstName, "First name did not match"); 74 | assertEquals(actualLastName, eLastName, "Last name did not match"); 75 | assertEquals(actualEmail, eEmail, "Email did not match"); 76 | 77 | test.pass("Create contact db validation passed"); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day21_db_testing/DbUtilityDemo.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day21_db_testing; 2 | 3 | import com.cybertek.utilities.DBUtils; 4 | import org.testng.annotations.Test; 5 | 6 | public class DbUtilityDemo { 7 | 8 | @Test 9 | public void test1() throws Exception { 10 | // "jdbc:database_type:@ip_address:port:sid/db-name" 11 | String url = "jdbc:mysql://107.23.27.171:3306/bitnami_orocrm"; 12 | String username = "qa_user"; 13 | String password = "qa_user"; 14 | 15 | DBUtils.createConnection(url, username, password); 16 | 17 | String sql = "select orocrm_contact.first_name, orocrm_contact.last_name, orocrm_contact_email.email \n" + 18 | "from orocrm_contact\n" + 19 | "join orocrm_contact_email\n" + 20 | "on orocrm_contact.id =orocrm_contact_email.owner_id\n" ; 21 | 22 | System.out.println(DBUtils.getQueryResultList(sql)); 23 | System.out.println(DBUtils.getColumnNames(sql)); 24 | System.out.println(DBUtils.getColumnData(sql, "first_name")); 25 | 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day2_Locators/EbaySearch.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day2_Locators; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.Keys; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | import org.openqa.selenium.chrome.ChromeDriver; 9 | 10 | public class EbaySearch { 11 | 12 | /* 13 | Task: 14 | Go to amazon https://www.amazon.com/ 15 | then Go to Ebay https://www.ebay.com/ 16 | Enter a search term 17 | Click on search button 18 | Verify title contains search term 19 | */ 20 | 21 | public static void main(String[] args) throws InterruptedException { 22 | //locaotors --> ID, name, classname, 23 | /* 24 | If class attribute's value has a space or spaces, 25 | driver cannot locate the element. 26 | */ 27 | 28 | WebDriverManager.chromedriver().setup(); 29 | WebDriver driver = new ChromeDriver(); 30 | 31 | driver.get("https://www.amazon.com/"); 32 | driver.navigate().to("https://www.ebay.com/"); 33 | 34 | //I used name here just to practice 35 | WebElement searchBox = driver.findElement(By.name("_nkw")); 36 | 37 | Thread.sleep(4000); 38 | // Keys.ENTER --> Click the Enter key 39 | searchBox.sendKeys("shoes" + Keys.ENTER); 40 | 41 | // WebElement searchBttn = driver.findElement(By.id("gh-btn")); 42 | // searchBox.click(); 43 | 44 | // Verify title contains search term 45 | //expected vs actual 46 | Thread.sleep(4000); 47 | String expectedPartialTitle = "shoes"; 48 | String actual = driver.getTitle(); 49 | 50 | if(actual.contains(expectedPartialTitle)){ 51 | System.out.println("pass"); 52 | }else { 53 | System.out.println("fail"); 54 | } 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day2_Locators/FindElemet.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day2_Locators; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.chrome.ChromeDriver; 8 | 9 | public class FindElemet { 10 | 11 | public static void main(String[] args) throws InterruptedException { 12 | 13 | //Locator 1. ID 14 | 15 | //task 16 | // go to cybertek okta login page 17 | //write email to the text box 18 | 19 | WebDriverManager.chromedriver().setup(); 20 | WebDriver driver = new ChromeDriver(); 21 | driver.get("https://cybertekschool.okta.com/"); 22 | driver.manage().window().maximize(); 23 | 24 | //write email to the text box 25 | /* 26 | 1. Find the text box first --> findElemet() from WebDriver 27 | 28 | */ 29 | 30 | Thread.sleep(5000); 31 | WebElement emailBox = driver.findElement(By.id("okta-signin-username")); 32 | 33 | emailBox.sendKeys("asiya@gmail.com"); 34 | 35 | //write your password to the password text box 36 | 37 | Thread.sleep(5000); 38 | driver.findElement(By.id("okta-signin-password")).sendKeys("123abc"); 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day2_Locators/login.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day2_Locators; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.chrome.ChromeDriver; 8 | 9 | public class login { 10 | 11 | /* 12 | User story: As a user, I should be able to login VyTrack app. 13 | 14 | test case1: login successfully 15 | 1. go to VyTrack login page 16 | 2. write username data: storemanager52 17 | 3.write password UserUser123 18 | 4. click login button 19 | 5.Verify that the user is on the homepage 20 | 21 | test cases2: login invalid cridential 22 | 1. go to login page 23 | 2.write invalid usr name 24 | 3.write invalid password 25 | 4. click login bttn 26 | 5.verify that user see error message "Invalid user name or password." 27 | */ 28 | public static void main(String[] args) { 29 | 30 | 31 | WebDriverManager.chromedriver().setup(); 32 | WebDriver driver = new ChromeDriver(); 33 | driver.get("https://app.vytrack.com/user/login"); 34 | driver.manage().window().maximize(); 35 | 36 | driver.findElement(By.id("prependedInput")).sendKeys("storemanager52"); 37 | driver.findElement(By.id("prependedInput2")).sendKeys("UserUser123"); 38 | 39 | //find login bttn, and then click 40 | WebElement loginBttn = driver.findElement(By.id("_submit")); 41 | loginBttn.click(); 42 | 43 | 44 | // login button can be found and clicked diractly 45 | // driver.findElement(By.id("_submit")).click(); 46 | 47 | /* 48 | Verify that you are in the home page 49 | */ 50 | 51 | String expectedTitle = "Dashboard"; 52 | String actulTitle = driver.getTitle(); 53 | 54 | if(expectedTitle.equalsIgnoreCase(actulTitle)){ 55 | System.out.println("Pass"); 56 | }else { 57 | System.out.println("Fail"); 58 | } 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | } 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day3_locators2/FakerPractice.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day3_locators2; 2 | 3 | import com.github.javafaker.Faker; 4 | 5 | public class FakerPractice { 6 | 7 | public static void main(String[] args) { 8 | 9 | //create Faker object 10 | 11 | Faker fakeData = new Faker(); 12 | 13 | //I need firstname 14 | 15 | String name = fakeData.name().firstName(); 16 | System.out.println(name); 17 | 18 | 19 | 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day3_locators2/GetAttributeValue.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day3_locators2; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.chrome.ChromeDriver; 8 | 9 | public class GetAttributeValue { 10 | 11 | public static void main(String[] args) { 12 | 13 | WebDriverManager.chromedriver().setup(); 14 | WebDriver driver = new ChromeDriver(); 15 | 16 | driver.get("http://practice.cybertekschool.com/login"); 17 | driver.manage().window().maximize(); 18 | 19 | //I want to get the value of type attribute 20 | // type="text" -> getAttribute("attribute name") 21 | 22 | 23 | //locate username box 24 | WebElement unername =driver.findElement(By.name("username")); 25 | 26 | // 27 | 28 | String velueOfType = unername.getAttribute("type"); 29 | 30 | System.out.println("Velue of type is: " + velueOfType); 31 | 32 | 33 | 34 | // 35 | 36 | WebElement loginbttn = driver.findElement(By.id("wooden_spoon")); 37 | 38 | //i want to print class attributes velue 39 | 40 | System.out.println(loginbttn.getAttribute("class")); 41 | 42 | //getText vs getAttribute 43 | 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day3_locators2/LinkText.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day3_locators2; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.chrome.ChromeDriver; 8 | 9 | public class LinkText { 10 | 11 | public static void main(String[] args) { 12 | 13 | //ID, name, tagname, class , linkText 14 | //Locator --> LinkText 15 | // a tag is link . in this situation, we will use linkText locator 16 | //to locate the element 17 | 18 | WebDriverManager.chromedriver().setup(); 19 | WebDriver driver = new ChromeDriver(); 20 | 21 | driver.get("http://practice.cybertekschool.com/dynamic_loading"); 22 | driver.manage().window().maximize(); 23 | 24 | WebElement example3 = driver.findElement(By.linkText("Example 3: Element on page that is hidden and become visible after 5 seconds")); 25 | 26 | String textVersionOfExample3 = example3.getText(); 27 | 28 | System.out.println(textVersionOfExample3); 29 | 30 | //linkText vs partialLinkText 31 | 32 | //I want to locate Example3 with only a part of it 33 | 34 | WebElement example3_2 = driver.findElement(By.partialLinkText("Example 3:")); 35 | 36 | String text = example3_2.getText(); 37 | 38 | System.out.println(text); 39 | 40 | 41 | //locate Cybertek_School 42 | WebElement cybertekSchool = driver.findElement(By.linkText("Cybertek School")); 43 | 44 | //I can not print the above variable cybertekschool 45 | //because it is a webElement 46 | 47 | //in order to print, I need getText() 48 | 49 | String textVersion = cybertekSchool.getText(); 50 | System.out.println(textVersion); 51 | 52 | //locate the element : Home 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day3_locators2/VerifyErrorMassage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day3_locators2; 2 | 3 | import com.github.javafaker.Faker; 4 | import io.github.bonigarcia.wdm.WebDriverManager; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.chrome.ChromeDriver; 8 | 9 | public class VerifyErrorMassage { 10 | 11 | /* 12 | 1. go to login page http://practice.cybertekschool.com/login 13 | 2. enter invalid username 14 | 3. enter invalid password 15 | 16 | */ 17 | 18 | //testers will gather test data in excell sheet 19 | //1. generate data from dummy data website 20 | //java faker 21 | 22 | public static void main(String[] args) { 23 | 24 | WebDriverManager.chromedriver().setup(); 25 | WebDriver driver = new ChromeDriver(); 26 | 27 | driver.get("http://practice.cybertekschool.com/login"); 28 | driver.manage().window().maximize(); 29 | 30 | Faker faker = new Faker(); 31 | String username = faker.name().fullName(); 32 | String password = faker.app().author(); 33 | 34 | driver.findElement(By.name("username")).sendKeys(username); 35 | driver.findElement(By.name("password")).sendKeys(password); 36 | 37 | driver.findElement(By.id("wooden_spoon")).click(); 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | } 46 | 47 | 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day3_locators2/VerifyLogin.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day3_locators2; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.chrome.ChromeDriver; 8 | 9 | public class VerifyLogin { 10 | 11 | /* 12 | go to login page 13 | enter username 14 | enter password 15 | click login button 16 | 17 | Verift the welcome massage "Welcome to the Secure Area. When you are done click logout below." 18 | */ 19 | public static void main(String[] args) { 20 | WebDriverManager.chromedriver().setup(); 21 | WebDriver driver = new ChromeDriver(); 22 | 23 | driver.get("http://practice.cybertekschool.com/login"); 24 | driver.manage().window().maximize(); 25 | 26 | driver.findElement(By.name("username")).sendKeys("tomsmith"); 27 | driver.findElement(By.name("password")).sendKeys("SuperSecretPassword"); 28 | 29 | driver.findElement(By.id("wooden_spoon")).click(); 30 | 31 | //locating the welcome massage with tagname 32 | 33 | WebElement welcomeMassage = driver.findElement(By.tagName("h4")); 34 | 35 | // Verify the welcome massage 36 | //expected vs actual 37 | String expectedMassage = "Welcome to the Secure Area. When you are done click logout below."; 38 | 39 | // String vs WebElement 40 | //getText() --> convert webElement to String 41 | // 42 | String actualWelcomeMassage = welcomeMassage.getText(); 43 | 44 | if (expectedMassage.equalsIgnoreCase(actualWelcomeMassage)){ 45 | System.out.println("PASSS"); 46 | }else { 47 | System.out.println("Fail"); 48 | } 49 | 50 | // driver.close(); 51 | 52 | 53 | 54 | 55 | } 56 | 57 | 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day4_xpath/ClicikvsSubmit.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day4_xpath; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.chrome.ChromeDriver; 8 | 9 | public class ClicikvsSubmit { 10 | 11 | public static void main(String[] args) { 12 | /* 13 | Click() va Submit() 14 | 15 | task: 16 | 1. go to forgot password web page 17 | http://practice.cybertekschool.com/forgot_password 18 | 2. enter any email 19 | 3. click "retrieve password" bttb 20 | 21 | 4. verify the URL is: 22 | http://practice.cybertekschool.com/email_sent 23 | 24 | */ 25 | 26 | WebDriverManager.chromedriver().setup(); 27 | WebDriver driver = new ChromeDriver(); 28 | 29 | //go to forgot password web page 30 | driver.get("http://practice.cybertekschool.com/forgot_password"); 31 | driver.manage().window().maximize(); 32 | 33 | // enter any email 34 | //locate the email box first 35 | WebElement emailbox = driver.findElement(By.name("email")); 36 | //enter email --< sendKeys() 37 | emailbox.sendKeys("abc@gamil.com"); 38 | 39 | // click "retrieve password" bttb 40 | //locate the bttn first 41 | WebElement submitBttn = driver.findElement(By.id("form_submit")); 42 | //submit email by clicking the "retrive password" 43 | submitBttn.submit(); 44 | 45 | // Verify --> Expected result vs Actual result 46 | 47 | String expectedURL = "http://practice.cybertekschool.com/email_sent"; 48 | String actualURL = driver.getCurrentUrl(); 49 | 50 | if(expectedURL.equals(actualURL)){ 51 | System.out.println("test is pass"); 52 | }else { 53 | System.out.println("test is failed"); 54 | } 55 | 56 | 57 | 58 | 59 | 60 | driver.close(); 61 | 62 | } 63 | 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day4_xpath/GetAttribute.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day4_xpath; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.chrome.ChromeDriver; 8 | 9 | public class GetAttribute { 10 | 11 | public static void main(String[] args) { 12 | 13 | /* 14 | go to forgot password page' 15 | locate retrive password bttn 16 | 17 | print out submit value 18 | type='submit' 19 | */ 20 | 21 | WebDriverManager.chromedriver().setup(); 22 | WebDriver driver = new ChromeDriver(); 23 | 24 | driver.get("http://practice.cybertekschool.com/forgot_password"); 25 | 26 | WebElement retreivePasswrodBttn = driver.findElement(By.id("form_submit")); 27 | 28 | 29 | // 30 | 31 | System.out.println(retreivePasswrodBttn.getAttribute("type")); //submit 32 | 33 | System.out.println(retreivePasswrodBttn.getAttribute("class")); //readuis 34 | 35 | System.out.println(retreivePasswrodBttn.getAttribute("id")); //for_submit 36 | 37 | 38 | 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day4_xpath/PracticeFactory.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day4_xpath; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import io.github.bonigarcia.wdm.WebDriverManager; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.chrome.ChromeDriver; 7 | 8 | public class PracticeFactory { 9 | 10 | public static void main(String[] args) { 11 | //go to google 12 | 13 | // WebDriverManager.chromedriver().setup(); 14 | // WebDriver driver = new ChromeDriver(); 15 | 16 | 17 | WebDriver driver = WebDriverFactory.getDriver("Chrome"); 18 | driver.get("https://google.com"); 19 | 20 | 21 | 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day4_xpath/XpathPractice.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day4_xpath; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | 8 | public class XpathPractice { 9 | 10 | public static void main(String[] args) { 11 | 12 | //go to practice login page 13 | //locate username box with absolute xpath 14 | //locate username box with relative xpath 15 | 16 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 17 | 18 | //absoloute 19 | WebElement userNameBox = driver.findElement(By.xpath("/html/body/div/div[2]/div/div/form/div/div/input")); 20 | userNameBox.sendKeys("tom"); 21 | 22 | // //tagname[@attribute='value'] 23 | 24 | // 25 | 26 | //relative 27 | driver.findElement(By.xpath("//input[@type='text']")); 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day4_xpath/getAttribute2.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day4_xpath; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.chrome.ChromeDriver; 8 | 9 | public class getAttribute2 { 10 | 11 | /* 12 | go to http://practice.cybertekschool.com/dynamic_loading 13 | 14 | locate: Example 1: Element on page that is hidden and become visible after trigger 15 | 16 | print out href attribute's value 17 | 18 | */ 19 | 20 | public static void main(String[] args) { 21 | 22 | 23 | WebDriverManager.chromedriver().setup(); 24 | WebDriver driver = new ChromeDriver(); 25 | 26 | driver.get("http://practice.cybertekschool.com/dynamic_loading"); 27 | // TODO linktext 28 | //locate Example 1 29 | WebElement exemple1 = driver.findElement(By.linkText("Example 1: Element on page that is hidden and become visible after trigger")); 30 | 31 | // System.out.println(exemple1.getAttribute("href")); 32 | 33 | // TODO partiallinktext 34 | WebElement example2 = driver.findElement(By.partialLinkText("2:")); 35 | System.out.println(example2.getText()); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day4_xpath/getText.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day4_xpath; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.chrome.ChromeDriver; 8 | 9 | import java.util.jar.JarOutputStream; 10 | 11 | public class getText { 12 | public static void main(String[] args) { 13 | WebDriverManager.chromedriver().setup(); 14 | WebDriver driver = new ChromeDriver(); 15 | 16 | //go to forgot password web page 17 | driver.get("http://practice.cybertekschool.com/forgot_password"); 18 | driver.manage().window().maximize(); 19 | 20 | /* 21 | Task 22 | go to the forgot password page 23 | enter any email 24 | click retrieve password bttn 25 | 26 | verify that the confirmation text "Your e-mail's been sent!" 27 | 28 | */ 29 | WebElement emailbox = driver.findElement(By.name("email")); 30 | //enter email --< sendKeys() 31 | emailbox.sendKeys("abc@gamil.com"); 32 | 33 | // click "retrieve password" bttb 34 | //locate the bttn first 35 | WebElement submitBttn = driver.findElement(By.id("form_submit")); 36 | //submit email by clicking the "retrive password" 37 | submitBttn.submit(); 38 | 39 | // verify that the confirmation text "Your e-mail's been sent!" 40 | String expectedText = "Your e-mail's been sent!"; 41 | 42 | WebElement message = driver.findElement(By.name("confirmation_message")); 43 | 44 | //getText() --> 45 | String ActualText = message.getText(); // 46 | 47 | if (expectedText.equals(ActualText)){ 48 | System.out.println("pass"); 49 | }else { 50 | System.out.println("fail"); 51 | } 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day4_xpath/textMethodOfXpath.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day4_xpath; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | 8 | public class textMethodOfXpath { 9 | 10 | public static void main(String[] args) { 11 | /* 12 | go to http://practice.cybertekschool.com/context_menu 13 | verify Context Menu is on the page 14 | 15 | //tagName[text()='exact Text'] 16 | */ 17 | 18 | WebDriver driver = WebDriverFactory.getDriver("Chrome"); 19 | 20 | //locate the element Context Menu 21 | 22 | WebElement text = driver.findElement(By.xpath("//h3[text()='Context Menu']")); 23 | 24 | //Verify --> expect vs actual 25 | 26 | String expectedText = "Context Menu"; 27 | 28 | String actualText = text.getText(); 29 | 30 | if(expectedText.equals(actualText)){ 31 | System.out.println("pass"); 32 | }else { 33 | System.out.println("fail"); 34 | } 35 | 36 | 37 | 38 | 39 | 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day5_more_xpath/ClassNameExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day5_more_xpath; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | 8 | public class ClassNameExample { 9 | public static void main(String[] args) { 10 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 11 | driver.get("http://practice.cybertekschool.com/login"); 12 | 13 | WebElement link = driver.findElement(By.className("nav-link")); 14 | System.out.println(link.getText()); 15 | 16 | // class name does not work if the value of the class attribute has a space 17 | // WebElement loginBtn = driver.findElement(By.className("btn btn-primary")); 18 | // loginBtn.click(); '' 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day5_more_xpath/XpathDemo.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day5_more_xpath; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | 8 | public class XpathDemo { 9 | 10 | public static void main(String[] args) { 11 | 12 | // get chrome 13 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 14 | 15 | // open browser 16 | driver.get("http://practice.cybertekschool.com/multiple_buttons"); 17 | 18 | 19 | // represent an element from page 20 | // where the elements come from? 21 | // form the finELement methods 22 | // how finELement finds elements? 23 | // using locators 24 | 25 | WebElement buttonOne = driver.findElement(By.xpath("//button[@onclick='button1()']")); 26 | // start interacting with the element 27 | String txt = buttonOne.getText(); 28 | System.out.println(txt); 29 | 30 | WebElement buttonTwo = driver.findElement(By.xpath("//h3/following-sibling::button[2]")); 31 | System.out.println(buttonTwo.getText()); 32 | 33 | System.out.println(driver.findElement(By.xpath("//button[3]")).getText()); 34 | 35 | WebElement buttonFour = driver.findElement(By.xpath("//div/button[4]")); 36 | System.out.println(buttonFour.getText()); 37 | 38 | WebElement buttonFive = driver.findElement(By.xpath("//button[.='Button 5']")); 39 | System.out.println(buttonFive.getText()); 40 | 41 | WebElement buttonSix= driver.findElement(By.xpath("//button[@id='disappearing_button']")); 42 | // element.getAttribute("value") --. method to get text form element, used with input boxes alot 43 | // get text of the element 44 | System.out.println(buttonSix.getAttribute("innerHTML")); 45 | 46 | // if none of the works use outerHTML 47 | System.out.println(buttonSix.getAttribute("outerHTML")); 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day6_css/CssExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day6_css; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | 8 | public class CssExample { 9 | 10 | public static void main(String[] args) throws InterruptedException { 11 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 12 | driver.get("http://practice.cybertekschool.com/multiple_buttons"); 13 | 14 | WebElement button = driver.findElement(By.cssSelector("button[onclick='button2()']")); 15 | System.out.println(button.getText()); 16 | 17 | Thread.sleep(2000); 18 | driver.quit(); 19 | } 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day7_review/AmazonCssExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day7_review; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | 8 | public class AmazonCssExample { 9 | public static void main(String[] args) { 10 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 11 | driver.get("https://amazon.com"); 12 | WebElement todaysDeals = driver.findElement(By.cssSelector("a[tabindex='47']")); 13 | todaysDeals.click(); 14 | 15 | String expected = "Today's Deals"; 16 | WebElement topHeader = driver.findElement(By.cssSelector(".nav-a-content")); 17 | System.out.println(topHeader.getText()); 18 | 19 | if (expected.equals(topHeader.getText())) { 20 | System.out.println("PASS"); 21 | } else { 22 | System.out.println("FAIL"); 23 | System.out.println("expected = " + expected); 24 | System.out.println("actual " + topHeader.getText()); 25 | } 26 | 27 | WebElement bottomHeader = driver.findElement(By.cssSelector("h1>div:nth-of-type(1)")); 28 | System.out.println(bottomHeader.getText()); 29 | 30 | if (expected.equals(bottomHeader.getText())) { 31 | System.out.println("PASS"); 32 | } else { 33 | System.out.println("FAIL"); 34 | System.out.println("expected = " + expected); 35 | System.out.println("actual = " + bottomHeader.getText()); 36 | } 37 | 38 | driver.close(); 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day7_review/AmazonTestWithText.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day7_review; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.Keys; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | 9 | public class AmazonTestWithText { 10 | /** 11 | * 1.open browser 12 | * 2.go to amazon 13 | * 3.search for 'selenium cookbook' 14 | * 4. verify that there is result with text 'Selenium Testing Tools Cookbook - Second Edition' 15 | */ 16 | public static void main(String[] args) throws InterruptedException { 17 | //span[.='Selenium Testing Tools Cookbook - Second Edition'] 18 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 19 | driver.get("https://amazon.com"); 20 | WebElement searchInput = driver.findElement(By.xpath("/html/body/div/header/div/div/div/div/form/div[3]/div/input")); 21 | searchInput.sendKeys("selenium cookbook edition" + Keys.ENTER); 22 | 23 | Thread.sleep(2000); 24 | WebElement result = driver.findElement(By.xpath("//span[.='Selenium Testing Tools Cookbook - Second Edition']")); 25 | System.out.println(result.getText()); 26 | 27 | driver.close(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day7_review/AmazonTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day7_review; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.Keys; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | 9 | // TODO THIS SPECIFIC AMAZON TEST WILL THROW EXCEPTION 10 | public class AmazonTests { 11 | // main method to invoke the tests 12 | public static void main(String[] args) throws InterruptedException { 13 | nameMatchTest(); 14 | secondNameMatchTest(); 15 | 16 | } 17 | 18 | // each test will be a separate method 19 | 20 | /** 21 | * open browser 22 | * go to amazon 23 | * search for any item 24 | * remember the name of the second result 25 | * click on the second result 26 | * verify that product name is same in the product page 27 | */ 28 | private static void secondNameMatchTest() throws InterruptedException { 29 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 30 | driver.get("https://amazon.com"); 31 | 32 | String searchTerm = "disinfectant wipes"; 33 | WebElement searchInput = driver.findElement(By.id("twotabsearchtextbox")); 34 | // OPTION 1: enter search term and hit ENTER button 35 | // searchInput.sendKeys(searchTerm + Keys.ENTER); 36 | // OPTION 2: Enter search term and click the search button 37 | searchInput.sendKeys(searchTerm); 38 | WebElement searchBtn = driver.findElement(By.className("nav-input")); 39 | searchBtn.click(); 40 | 41 | Thread.sleep(2000); 42 | // write xpath that captures second result 43 | // CHANGE XPATH 44 | WebElement secondResult = driver.findElement(By.xpath("(//span[@class='a-size-base-plus a-color-base a-text-normal'])[2]")); 45 | // it is prting the value 46 | System.out.println(secondResult.getText()); 47 | // get the name of the second result 48 | String expectedName = secondResult.getText(); 49 | // click on the second result 50 | secondResult.click(); 51 | // creating a new variable 52 | Thread.sleep(2000); 53 | WebElement productName = driver.findElement(By.id("productTitle")); 54 | String actualName = productName.getText(); 55 | 56 | System.out.println(actualName); 57 | 58 | if (expectedName.equals(actualName)) { 59 | System.out.println("PASS"); 60 | } else { 61 | System.out.println("FAIL"); 62 | System.out.println("expectedName = " + expectedName); 63 | System.out.println("actualName = " + actualName); 64 | } 65 | driver.quit(); 66 | } 67 | 68 | // each test will be a separate method 69 | 70 | /** 71 | * open browser 72 | * go to amazon 73 | * search for any item 74 | * remember the name of the first result 75 | * click on the first result 76 | * verify that product name is same in the product page 77 | */ 78 | private static void nameMatchTest() throws InterruptedException { 79 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 80 | driver.get("https://amazon.com"); 81 | 82 | String searchTerm = "disinfectant wipes"; 83 | WebElement searchInput = driver.findElement(By.id("twotabsearchtextbox")); 84 | // OPTION 1: enter search term and hit ENTER button 85 | // searchInput.sendKeys(searchTerm + Keys.ENTER); 86 | // OPTION 2: Enter search term and click the search button 87 | searchInput.sendKeys(searchTerm); 88 | WebElement searchBtn = driver.findElement(By.className("nav-input")); 89 | searchBtn.click(); 90 | 91 | Thread.sleep(2000); 92 | // write xpath that captures first result 93 | WebElement firstResult = driver.findElement(By.xpath("//span[@class='a-size-base-plus a-color-base a-text-normal']")); 94 | // it is prting the value 95 | System.out.println(firstResult.getText()); 96 | // get the name of the first result 97 | String expectedName = firstResult.getText(); 98 | // click on the first result 99 | firstResult.click(); 100 | // creating a new variable 101 | WebElement productName = driver.findElement(By.id("productTitle")); 102 | String actualName = productName.getText(); 103 | 104 | System.out.println(actualName); 105 | 106 | if (expectedName.equals(actualName)) { 107 | System.out.println("PASS"); 108 | } else { 109 | System.out.println("FAIL"); 110 | System.out.println("expectedName = " + expectedName); 111 | System.out.println("actualName = " + actualName); 112 | } 113 | driver.quit(); 114 | } 115 | 116 | 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day7_review/StaleElementExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day7_review; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | 8 | public class StaleElementExample { 9 | public static void main(String[] args) throws InterruptedException { 10 | //main method to invoke thee tests 11 | nameMatchTest(); 12 | } 13 | // each test will be a separate method 14 | /* 15 | 1.open browser 16 | 2.go to amazon 17 | 3.search for any item 18 | 4.remember the name of the first result 19 | 5.click on the first result 20 | 6.verify that product name is same in the product result 21 | */ 22 | private static void nameMatchTest() throws InterruptedException { 23 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 24 | driver.get("https:/www.amazon.com"); 25 | String searchTerm = "disinfectant wipes"; 26 | WebElement searchBox = driver.findElement(By.id("twotabsearchtextbox")); 27 | searchBox.sendKeys(searchTerm); 28 | 29 | WebElement searchButton = driver.findElement(By.className("nav-input")); 30 | searchButton.click(); 31 | Thread.sleep(2000); 32 | 33 | // FIND THE FIRST RESULT 34 | WebElement firstResult = driver.findElement(By.xpath("//span[@class='a-size-base-plus a-color-base a-text-normal']")); 35 | System.out.println(firstResult.getText()); 36 | 37 | // CLICK ON THE FIRST RESULT 38 | firstResult.click(); // PRODUCT PAGE OPENS 39 | Thread.sleep(4000); 40 | 41 | // GET THE TEXT OF THE FIRST RESULT 42 | String expectedName = firstResult.getText(); // TRYING TO INTERACT WITH ELEMENT FROM PREVIOUS PAGE 43 | Thread.sleep(2000); 44 | 45 | 46 | WebElement productName = driver.findElement(By.id("productTitle")); 47 | Thread.sleep(2000); 48 | String actualName = productName.getText(); 49 | 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day7_review/SystemPropertiesExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day7_review; 2 | 3 | public class SystemPropertiesExample { 4 | 5 | public static void main(String[] args) { 6 | String property = System.getProperty("os.name"); 7 | 8 | System.out.println(property); 9 | 10 | System.out.println("OS: " + System.getProperty("os.name") + "; Version: " + System.getProperty("os.version")); 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day8_review_2/EbaySearchTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day8_review_2; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.Keys; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | 9 | public class EbaySearchTest { 10 | /* 11 | Open browser 12 | 2. Go to https://ebay.com 13 | 3. Search for wooden spoon 14 | 4. Save the total number of results 15 | 5. Click on link All under the categories on the left menu 16 | 6. Verify that number of results is bigger than the number in step 4 17 | 7. Navigate back to previous research results page 18 | 8. Verify that wooden spoon is still displayed in the search box 19 | 9. Navigate back to home page 20 | 10. Verify that search box is blank 21 | */ 22 | public static void main(String[] args) throws InterruptedException { 23 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 24 | driver.get("https://ebay.com"); 25 | WebElement input = driver.findElement(By.id("gh-ac")); 26 | input.sendKeys("wooden spoon" + Keys.ENTER); 27 | Thread.sleep(2000); 28 | WebElement countEl = driver.findElement(By.cssSelector("h1>span")); 29 | String count = countEl.getText(); 30 | System.out.println(count); 31 | 32 | int countOne = Integer.parseInt(count.replace(",", "")); 33 | System.out.println(countOne); 34 | 35 | WebElement all = driver.findElement(By.linkText("All")); 36 | all.click(); 37 | Thread.sleep(2000); 38 | 39 | // re initialize the element that is throwing the stateelementexception 40 | countEl = driver.findElement(By.cssSelector("h1>span")); 41 | count = countEl.getText(); 42 | System.out.println(count); 43 | 44 | int countTwo = Integer.parseInt(count.replace(",", "")); 45 | System.out.println(countTwo); 46 | 47 | if (countOne < countTwo) { 48 | System.out.println("PASS"); 49 | } else { 50 | System.out.println("FAIL"); 51 | System.out.println("countOne = " + countOne); 52 | System.out.println("countTwo = " + countTwo); 53 | } 54 | 55 | driver.navigate().back(); 56 | 57 | input = driver.findElement(By.id("gh-ac")); 58 | String woodenSpoon = input.getAttribute("value"); 59 | System.out.println(woodenSpoon); 60 | 61 | if (woodenSpoon.equals("wooden spoon")) { 62 | System.out.println("PASS"); 63 | } else { 64 | System.out.println("FAIL"); 65 | System.out.println("Expected: " + "woodenSpoon"); 66 | System.out.println("Actual: " + woodenSpoon); 67 | } 68 | driver.navigate().back(); 69 | 70 | Thread.sleep(2000); 71 | input = driver.findElement(By.id("gh-ac")); 72 | woodenSpoon = input.getAttribute("value"); 73 | System.out.println("woodenSpoon = " + woodenSpoon); 74 | 75 | if (woodenSpoon.isEmpty()) { 76 | System.out.println("PASS"); 77 | } else { 78 | System.out.println("FAIL"); 79 | System.out.println("Expected a blank value"); 80 | System.out.println("Actual: " + woodenSpoon); 81 | } 82 | 83 | driver.quit(); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day8_review_2/GetAttributeExamples.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day8_review_2; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | 8 | public class GetAttributeExamples { 9 | 10 | public static void main(String[] args) { 11 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 12 | driver.get("https://ebay.com"); 13 | 14 | // get title 15 | System.out.println(driver.getTitle()); 16 | 17 | // get current url 18 | System.out.println(driver.getCurrentUrl()); 19 | 20 | // get page source 21 | System.out.println(driver.getPageSource()); 22 | 23 | WebElement myEbayLink = driver.findElement(By.linkText("My eBay")); 24 | 25 | // get certain values of attributes of the webelement 26 | String classValue = myEbayLink.getAttribute("class"); 27 | System.out.println(classValue); 28 | String href = myEbayLink.getAttribute("href"); 29 | System.out.println(href); 30 | // get test of the web element 31 | System.out.println(myEbayLink.getText()); 32 | 33 | WebElement input = driver.findElement(By.id("gh-ac")); 34 | 35 | input.sendKeys("wooden spoon"); 36 | System.out.println(input.getAttribute("value")); 37 | 38 | // .getAttribute("innterHTML") --> returns text of the element 39 | System.out.println(myEbayLink.getAttribute("innerHTML")); 40 | 41 | // getAttribute("outerHTML")) --> returns html information of element 42 | System.out.println(myEbayLink.getAttribute("outerHTML")); 43 | System.out.println(input.getAttribute("outerHTML")); 44 | 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day8_review_2/VytrackTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day8_review_2; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | 8 | public class VytrackTests { 9 | 10 | public static void main(String[] args) throws InterruptedException { 11 | // titleTest(); 12 | shortcutTest(); 13 | 14 | } 15 | /* 16 | Open browser 17 | 2. Go to Vytrack login page 18 | 3. Login as a sales manager 19 | 4. Verify Dashboard page is open 20 | 5. Click on Shortcuts icon 21 | 6. Click on link See full list 22 | 7. Click on link Opportunities 23 | 8. Verify Open opportunities page is open 24 | 9. Click on Shortcuts icon 25 | 10. Click on link See full list 26 | 11. Click on link Vehicle Service Logs 27 | 12. Verify error message text is You do not have 28 | permission to perform this action. 29 | 13. Verify Shortcut Actions List page is still open 30 | 31 | */ 32 | private static void shortcutTest() throws InterruptedException { 33 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 34 | driver.get("http://qa3.vytrack.com"); 35 | WebElement username = driver.findElement(By.id("prependedInput")); 36 | username.sendKeys("salesmanager110"); 37 | WebElement password = driver.findElement(By.id("prependedInput2")); 38 | password.sendKeys("UserUser123"); 39 | password.submit(); 40 | 41 | Thread.sleep(2000); 42 | String expectedTitle = "Dashboard"; 43 | String actualTitle = driver.getTitle(); 44 | 45 | verifyStartsWith(expectedTitle, actualTitle); 46 | 47 | WebElement shortcutIcon = driver.findElement(By.cssSelector("a[title='Shortcuts']")); 48 | shortcutIcon.click(); 49 | 50 | WebElement allLinks = driver.findElement(By.linkText("See full list")); 51 | allLinks.click(); 52 | 53 | Thread.sleep(2000); 54 | WebElement opportunities = driver.findElement(By.linkText("Opportunities")); 55 | opportunities.click(); 56 | 57 | Thread.sleep(2000); 58 | verifyStartsWith("Open Opportunities", driver.getTitle()); 59 | 60 | shortcutIcon.click(); 61 | allLinks.click(); 62 | 63 | Thread.sleep(2000); 64 | WebElement vehicleServiceLogs = driver.findElement(By.linkText("Vehicle Services Logs")); 65 | vehicleServiceLogs.click(); 66 | 67 | Thread.sleep(1000); 68 | WebElement errorMessage = driver.findElement(By.cssSelector(".message")); 69 | 70 | verifyStartsWith("You do not have permission to perform this action.", errorMessage.getText()); 71 | 72 | verifyStartsWith("Shortcut Actions List", driver.getTitle()); 73 | driver.quit(); 74 | 75 | } 76 | 77 | private static void verifyStartsWith(String expectedTitle, String actualTitle) { 78 | if (actualTitle.startsWith(expectedTitle)) { 79 | System.out.println("PASS"); 80 | }else { 81 | System.out.println("FAIL"); 82 | System.out.println("expectedTitle = " + expectedTitle); 83 | System.out.println("actualTitle = " + actualTitle); 84 | } 85 | } 86 | 87 | /* 88 | 1. Open browser 89 | 2. Go to Vytrack login page 90 | 3. Login as any user 91 | 4. Click on your name on top right 92 | 5. Click on My Configuration 93 | 6. Verify that page title starts with the same name on top 94 | right 95 | */ 96 | private static void titleTest() throws InterruptedException { 97 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 98 | driver.get("http://qa3.vytrack.com"); 99 | WebElement username = driver.findElement(By.id("prependedInput")); 100 | username.sendKeys("salesmanager110"); 101 | WebElement password = driver.findElement(By.id("prependedInput2")); 102 | password.sendKeys("UserUser123"); 103 | password.submit(); 104 | 105 | WebElement profileName = driver.findElement(By.cssSelector("a[href='javascript: void(0);']")); 106 | 107 | Thread.sleep(2000); 108 | profileName.click(); 109 | 110 | Thread.sleep(1000); 111 | WebElement myConfiguration = driver.findElement(By.cssSelector("ul.dropdown-menu>li>a[href='/config/user/profile']")); 112 | myConfiguration.click(); 113 | 114 | Thread.sleep(2000); 115 | String expected = profileName.getText(); 116 | String actual = driver.getTitle(); 117 | 118 | if (actual.startsWith(expected)) { 119 | System.out.println("PASS"); 120 | } else { 121 | System.out.println("FAIL"); 122 | System.out.println("expected = " + expected); 123 | System.out.println("actual = " + actual); 124 | } 125 | driver.quit(); 126 | } 127 | 128 | 129 | /* 130 | write a method that takes 2 strings, verifies if string 1 starts with string 2 131 | 132 | */ 133 | 134 | } 135 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day9_testng_intro/BeforeAndAfterTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day9_testng_intro; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.*; 5 | 6 | public class BeforeAndAfterTest { 7 | 8 | @BeforeClass 9 | public void beforeClass(){ 10 | System.out.println("\tBEFORE CLASS"); 11 | } 12 | 13 | @AfterClass 14 | public void afterClass(){ 15 | System.out.println("\tAFTER CLASS"); 16 | 17 | } 18 | 19 | @BeforeMethod 20 | public void beforeMethod(){ 21 | System.out.println("\tBEFORE METHOD"); 22 | } 23 | 24 | @AfterMethod 25 | public void afterMethod(){ 26 | System.out.println("\tAFTER METHOD"); 27 | } 28 | 29 | @Test 30 | public void test1(){ 31 | System.out.println("this is test one"); 32 | // Assert.assertEquals(true, false); 33 | } 34 | 35 | 36 | @Test 37 | public void test2(){ 38 | System.out.println("this is test two"); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day9_testng_intro/FirstTestNGTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day9_testng_intro; 2 | 3 | import org.testng.annotations.Ignore; 4 | import org.testng.annotations.Test; 5 | 6 | public class FirstTestNGTest { 7 | 8 | @Test 9 | public void test1(){ 10 | System.out.println("test one"); 11 | } 12 | 13 | @Ignore 14 | @Test 15 | public void test2(){ 16 | System.out.println("test two"); 17 | } 18 | 19 | @Test 20 | public void test3(){ 21 | System.out.println("test three"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day9_testng_intro/TestNGAssertionsTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day9_testng_intro; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | 6 | public class TestNGAssertionsTest { 7 | 8 | @Test 9 | public void test1(){ 10 | String expected = "one"; 11 | String actual = "one"; 12 | 13 | Assert.assertEquals(actual, expected); 14 | Assert.assertEquals(1, 1); 15 | Assert.assertEquals(true, true); 16 | 17 | System.out.println("test 1 complete"); 18 | 19 | } 20 | 21 | @Test 22 | public void test2(){ 23 | String expected = "one"; 24 | String actual = "two"; 25 | 26 | System.out.println("starting to compare"); 27 | 28 | Assert.assertEquals(actual, expected); 29 | 30 | System.out.println("test 2 complete"); 31 | } 32 | 33 | @Test 34 | public void test3(){ 35 | String expected = "one"; 36 | String actual = "two"; 37 | Assert.assertNotEquals(expected, actual); 38 | Assert.assertNotEquals(1, 2); 39 | 40 | } 41 | 42 | @Test 43 | public void test4(){ 44 | String expected = "one"; 45 | String actual = "one"; 46 | 47 | Assert.assertTrue(expected.equals(actual)); 48 | 49 | int e =100; 50 | int a = 200; 51 | Assert.assertTrue(a>e); 52 | } 53 | 54 | 55 | @Test 56 | public void test5(){ 57 | // verify that url is EQUAL to https://www.google.com/ 58 | 59 | String expected = "https://www.google.com/"; 60 | String actual = "https://www.google.com/"; 61 | Assert.assertEquals(expected, actual); 62 | 63 | // verify that title starts with java 64 | String expected1 = "java"; 65 | String actual1 = "java - Google Search"; 66 | 67 | Assert.assertTrue(actual1.startsWith(expected1)); 68 | 69 | } 70 | 71 | 72 | @Test 73 | public void fromHamid (){ 74 | int a =100; 75 | int b = 200; 76 | Assert.assertTrue(b>a); // this line is true but 77 | Assert.assertTrue(a>b); /// false 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/office_hours1/GoogleSearchTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.office_hours1; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.Keys; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | 9 | import java.util.Arrays; 10 | import java.util.List; 11 | 12 | public class GoogleSearchTest { 13 | /* 14 | Open browser 15 | 2. Go to https://google.com 16 | 3. Search for one of the strings the list searchStrs given below 17 | 4. In the results pages, capture the url right above the first result 18 | 5. Click on the first result 19 | 6. Verify that url is equal to the value from step 4 20 | 7. Navigate back 21 | 8. Repeat the same steps for all search items in the list 22 | Note: Do this exercise using a for loop. Here is the list that was mentioned step 3: 23 | List searchStrs = Arrays.asList("Java", "cucumber bdd", “Selenium web browser automation" ); 24 | */ 25 | 26 | public static void main(String[] args) { 27 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 28 | driver.get("https://google.com"); 29 | 30 | List searchStrs = Arrays.asList("Java", "cucumber bdd", "Selenium web browser automation" ); 31 | // List searchStrs = Arrays.asList("Java"); 32 | 33 | for (String searchStr : searchStrs) { 34 | WebElement searchInput = driver.findElement(By.name("q")); 35 | // this is for setting up the 2 and 3 rd loop 36 | searchInput.clear(); 37 | searchInput.sendKeys(searchStr + Keys.ENTER); 38 | 39 | WebElement url = driver.findElement(By.cssSelector(".iUh30.tjvcx")); 40 | String expectedUrl = url.getText(); 41 | System.out.println(expectedUrl); 42 | 43 | WebElement link = driver.findElement(By.cssSelector("div.r>a>h3")); 44 | link.click(); 45 | 46 | if (expectedUrl.equals(driver.getCurrentUrl())) { 47 | System.out.println("PASS"); 48 | } else { 49 | System.out.println("FAIL"); 50 | System.out.println("Expected = " + expectedUrl); 51 | System.out.println("Actual = " + driver.getCurrentUrl()); 52 | } 53 | 54 | driver.navigate().back(); 55 | 56 | } 57 | driver.quit(); 58 | 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/office_hours2/GoogleHoverTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.office_hours2; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.interactions.Actions; 8 | import org.testng.Assert; 9 | import org.testng.annotations.AfterMethod; 10 | import org.testng.annotations.BeforeMethod; 11 | import org.testng.annotations.Test; 12 | 13 | public class GoogleHoverTest { 14 | 15 | WebDriver driver; 16 | 17 | @BeforeMethod 18 | public void setUp() { 19 | driver = WebDriverFactory.getDriver("chrome"); 20 | driver.get("https://google.com"); 21 | } 22 | 23 | @AfterMethod 24 | public void tearDown() { 25 | driver.quit(); 26 | } 27 | /** 28 | * Go to google.com 29 | * Move your mouse on top of I am feeling lucky 30 | * Verify that button now has a different text 31 | * Move the mouse away 32 | * Do this many times 33 | * When you get “I am feeling stellar” 3 times, print “Deal with it” in console and exit the program 34 | */ 35 | 36 | @Test 37 | public void test(){ 38 | Actions actions = new Actions(driver); 39 | WebElement button = driver.findElement(By.id("gbqfbb")); 40 | 41 | actions. 42 | pause(1000).moveToElement(button).pause(1000). 43 | build().perform(); 44 | String notUnExpected = "I'm Feeling Lucky"; 45 | 46 | String actual = button.getAttribute("value"); 47 | System.out.println("Actual: "+actual); 48 | Assert.assertNotEquals(actual,notUnExpected); 49 | 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/office_hours2/SelectClassPracticeTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.office_hours2; 2 | 3 | import com.cybertek.utilities.BrowserUtils; 4 | import com.cybertek.utilities.WebDriverFactory; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | import org.openqa.selenium.support.ui.Select; 9 | import org.testng.Assert; 10 | import org.testng.annotations.AfterMethod; 11 | import org.testng.annotations.BeforeMethod; 12 | import org.testng.annotations.Test; 13 | 14 | import java.util.ArrayList; 15 | import java.util.Arrays; 16 | import java.util.Collections; 17 | import java.util.List; 18 | 19 | public class SelectClassPracticeTests { 20 | 21 | WebDriver driver; 22 | 23 | @BeforeMethod 24 | public void setUp() { 25 | driver = WebDriverFactory.getDriver("chrome"); 26 | } 27 | 28 | @AfterMethod 29 | public void tearDown() { 30 | driver.quit(); 31 | } 32 | 33 | /* 34 | go to http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellTable 35 | verify that table has dropdown with values Family, Friends, Coworkers, Businesses, Contacts 36 | 37 | */ 38 | @Test 39 | public void test() throws InterruptedException { 40 | driver.get("http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellTable"); 41 | Thread.sleep(2000); 42 | Select categories = new Select(driver.findElement(By.cssSelector("select[tabindex='-1']"))); 43 | 44 | // getOptions --> gives all available options as a list of web elements 45 | List allOptionsEl = categories.getOptions(); 46 | 47 | System.out.println("Number of options: " + allOptionsEl.size()); 48 | 49 | List expectedOptions = Arrays.asList("Family", "Friends", "Coworkers", "Businesses", "Contacts"); 50 | 51 | // given a list web elements, extract the text of the elements into new list of strings 52 | List allOptionsStr = BrowserUtils.getElementsText(allOptionsEl); 53 | 54 | Assert.assertEquals(allOptionsStr, expectedOptions); 55 | 56 | } 57 | 58 | /* 59 | go to http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellTable 60 | select option Coworkers 61 | verify that that Coworkers is now selected 62 | select options Contacts 63 | verify that contacts is selected 64 | */ 65 | @Test 66 | public void test2() throws InterruptedException { 67 | driver.get("http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellTable"); 68 | Thread.sleep(2000); 69 | Select categories = new Select(driver.findElement(By.cssSelector("select[tabindex='-1']"))); 70 | // select option Coworkers 71 | categories.selectByVisibleText("Coworkers"); 72 | // verify that that Coworkers is now selected 73 | // getFirstSelectedOption --> returns the currently selected option as Web element 74 | categories = new Select(driver.findElement(By.cssSelector("select[tabindex='-1']"))); 75 | String actual = categories.getFirstSelectedOption().getText(); 76 | Assert.assertEquals(actual, "Coworkers"); 77 | categories = new Select(driver.findElement(By.cssSelector("select[tabindex='-1']"))); 78 | categories.selectByVisibleText("Contacts"); 79 | 80 | // 81 | categories = new Select(driver.findElement(By.cssSelector("select[tabindex='-1']"))); 82 | String actual1 = categories.getFirstSelectedOption().getText(); 83 | 84 | Assert.assertEquals(actual1, "Contacts"); 85 | } 86 | 87 | /** 88 | * go to http://practice.cybertekschool.com/dropdown 89 | * verify taht days table has days sorted in ascending order 90 | */ 91 | @Test 92 | public void test3(){ 93 | driver.get("http://practice.cybertekschool.com/dropdown"); 94 | Select days = new Select(driver.findElement(By.id("day"))); 95 | List options = days.getOptions(); 96 | System.out.println("Number of options: " + options.size()); 97 | 98 | // i have a list of web elements, i need to verify if the values (numbers) are sorted in ascending order 99 | // list of web element to list of string 100 | List stringList = BrowserUtils.getElementsText(options); 101 | 102 | // list of string to list of ints 103 | List ints = new ArrayList<>(); 104 | for (String string : stringList) { 105 | ints.add(Integer.parseInt(string)); 106 | } 107 | 108 | System.out.println(ints); 109 | 110 | // verify list of ints is sorted 111 | 112 | // create new class with values of the given list 113 | List intsCopy = new ArrayList<>(ints); 114 | // sorting the copy 115 | Collections.sort(intsCopy); 116 | // finally compare 117 | Assert.assertEquals(ints, intsCopy); 118 | 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/office_hours3/DifferentBrowsers.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.office_hours3; 2 | 3 | import com.cybertek.base.TestBase; 4 | import com.cybertek.utilities.ConfigurationReader; 5 | import org.openqa.selenium.chrome.ChromeDriver; 6 | import org.openqa.selenium.chrome.ChromeOptions; 7 | import org.openqa.selenium.firefox.FirefoxDriver; 8 | import org.testng.annotations.Test; 9 | 10 | public class DifferentBrowsers extends TestBase { 11 | 12 | 13 | @Test 14 | public void test() { 15 | // WHICH BROWSER AM I USING RIGHT NOW 16 | // get the value from propetries file 17 | System.out.println("OPTION 1"); 18 | System.out.println(ConfigurationReader.getProperty("browser")); 19 | // get the value from the webdriver tostring 20 | System.out.println("OPTION 2"); 21 | System.out.println(driver); 22 | if (driver.toString().contains("FirefoxDriver")) { 23 | System.out.println("this is firefox"); 24 | } else if (driver.toString().contains("ChromeDriver")) { 25 | System.out.println("this is chrome"); 26 | } 27 | // use the instance of keyword 28 | System.out.println("OPTION 3"); 29 | 30 | if (driver instanceof FirefoxDriver) { 31 | System.out.println("This is firefoooooox"); 32 | } else if (driver instanceof ChromeDriver) { 33 | System.out.println("This is chrome"); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/office_hours3/EtsyTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.office_hours3; 2 | 3 | import com.cybertek.base.TestBase; 4 | import com.cybertek.utilities.BrowserUtils; 5 | import com.cybertek.utilities.Driver; 6 | import com.cybertek.utilities.WebDriverFactory; 7 | import io.github.bonigarcia.wdm.WebDriverManager; 8 | import org.openqa.selenium.*; 9 | import org.openqa.selenium.support.ui.ExpectedCondition; 10 | import org.openqa.selenium.support.ui.ExpectedConditions; 11 | import org.openqa.selenium.support.ui.Select; 12 | import org.openqa.selenium.support.ui.WebDriverWait; 13 | import org.testng.Assert; 14 | import org.testng.annotations.Test; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.concurrent.TimeUnit; 20 | 21 | public class EtsyTests extends TestBase { 22 | /* 23 | search for wooden spoon on etsy 24 | verify title contains the searchterm 25 | verify that default shipt to location is United States 26 | verify Ship to countries include Australia 27 | */ 28 | 29 | @Test 30 | public void verifyCountryList() throws InterruptedException { 31 | WebDriverWait wait = new WebDriverWait(driver, 10); 32 | 33 | driver.get("https://etsy.com"); 34 | // for chrome users, wait until page loads 35 | waitForPageToLoad(5000); 36 | 37 | WebElement input = driver.findElement(By.id("global-enhancements-search-query")); 38 | 39 | 40 | input.sendKeys("wooden spoon"+ Keys.ENTER); 41 | 42 | // VERIFY TITLE 43 | String expectedTitle = "Wooden spoon | Etsy"; 44 | 45 | // wait a little until title changes to right one 46 | 47 | // using explicit wait to wait until title contains Wooden spoon | Etsy 48 | wait.until(ExpectedConditions.titleIs(expectedTitle)); 49 | 50 | Assert.assertEquals(driver.getTitle(), expectedTitle); 51 | 52 | // VERIFY SHIP TO LOCATION 53 | 54 | // wait until element is FOUND in html 55 | driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); 56 | Select shipToList = new Select(driver.findElement(By.name("ship_to"))); 57 | 58 | String expectedDefaultCountry = "United States"; 59 | // get the selected element and get its text 60 | String actualDefaultCountry =shipToList.getFirstSelectedOption().getText().trim(); 61 | Assert.assertEquals(actualDefaultCountry, expectedDefaultCountry); 62 | 63 | // VERIFY THAT Ship to countries include Australia 64 | 65 | // get all options is a list of strings 66 | List options = BrowserUtils.getElementsText(shipToList.getOptions()); 67 | 68 | for (String option : options) { 69 | // option.trim().equals("Austalia") 70 | } 71 | 72 | 73 | Assert.assertTrue(options.contains("Australia")); 74 | 75 | // VERIFY FREE SHIPPING IS NOT CLICKED 76 | WebElement freeeShipping = driver.findElement(By.name("free_shipping")); 77 | Assert.assertFalse(freeeShipping.isSelected()); 78 | 79 | // VERIFY URL CHANGES WHEN FREE SHIPPING IS CLICKED 80 | // click using JS 81 | WebElement freeeShippingLabel = driver.findElement(By.xpath("//label[.='FREE shipping']")); 82 | freeeShippingLabel.click(); 83 | 84 | String expectedUrl = "free_shipping=true"; 85 | Assert.assertTrue(driver.getCurrentUrl().endsWith(expectedUrl)); 86 | 87 | 88 | } 89 | 90 | public static void waitForPageToLoad(long timeOutInSeconds) { 91 | ExpectedCondition expectation = new ExpectedCondition() { 92 | public Boolean apply(WebDriver driver) { 93 | return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete"); 94 | } 95 | }; 96 | try { 97 | WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeOutInSeconds); 98 | wait.until(expectation); 99 | } catch (Throwable error) { 100 | error.printStackTrace(); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/office_hours4/ChangeMenuSoftAssertTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.office_hours4; 2 | 3 | import com.cybertek.base.VytrackTestBase; 4 | import com.cybertek.utilities.ConfigurationReader; 5 | import org.testng.annotations.Test; 6 | import org.testng.asserts.SoftAssert; 7 | 8 | import static org.testng.Assert.assertNotEquals; 9 | 10 | public class ChangeMenuSoftAssertTest extends VytrackTestBase { 11 | // go to vyrack 12 | //verify we are logged in 13 | // change menu to vehicles and verify title 14 | // change menu to customers and verify title 15 | 16 | @Test 17 | public void testMenuOptions() throws InterruptedException { 18 | loginPage.login(ConfigurationReader.getProperty("driver_username"), 19 | ConfigurationReader.getProperty("driver_password")); 20 | assertNotEquals(driver.getCurrentUrl(), "https://qa3.vytrack.com/user/login", "URL did not match"); 21 | 22 | dashboardPage.changeMenu("Fleet", "Vehicles"); 23 | Thread.sleep(2000); 24 | softAssert.assertTrue(driver.getTitle().contains("my Jeep car"), "Vehicles page title did not match"); 25 | 26 | dashboardPage.changeMenu("Customers", "Accounts"); 27 | Thread.sleep(2000); 28 | softAssert.assertTrue(driver.getTitle().contains("Accounts"), "Accounts page title did not match"); 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/office_hours4/CookiesExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.office_hours4; 2 | 3 | import com.cybertek.base.TestBase; 4 | import com.cybertek.utilities.Driver; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.Cookie; 7 | import org.openqa.selenium.Keys; 8 | import org.testng.annotations.Test; 9 | 10 | import java.util.Set; 11 | 12 | public class CookiesExample extends TestBase { 13 | 14 | @Test 15 | public void test(){ 16 | // PRINT SOME COOKIES 17 | driver.get("http://a.testaddressbook.com/addresses"); 18 | driver.findElement(By.id("session_email")).sendKeys("kexesobepu@zsero.com"); 19 | driver.findElement(By.id("session_password")).sendKeys("password"+ Keys.ENTER); 20 | 21 | System.out.println(driver.getCurrentUrl()); 22 | // get all cookies 23 | Set cookies = driver.manage().getCookies(); 24 | System.out.println("cookies.size() = " + cookies.size()); 25 | for (Cookie cookie : cookies) { 26 | System.out.println(cookie.toString()); 27 | } 28 | 29 | // delete all cookies 30 | driver.manage().deleteAllCookies(); 31 | driver.navigate().refresh(); 32 | System.out.println(driver.getCurrentUrl()); 33 | 34 | // PRINT COOKIES AFTER DELETION 35 | Set cookies1 = driver.manage().getCookies(); 36 | System.out.println("cookies1.size() = " + cookies1.size()); 37 | 38 | // ADD COOKIE 39 | Driver.closeDriver(); 40 | driver = Driver.getDriver(); 41 | driver.get("http://a.testaddressbook.com/addresses"); 42 | 43 | for (Cookie cookie : cookies) { 44 | driver.manage().addCookie(cookie); 45 | } 46 | driver.navigate().refresh(); 47 | System.out.println(driver.getCurrentUrl()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/office_hours4/CountryInformationDDT.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.office_hours4; 2 | 3 | import com.cybertek.utilities.Driver; 4 | import org.apache.poi.ss.usermodel.Row; 5 | import org.apache.poi.ss.usermodel.Sheet; 6 | import org.apache.poi.ss.usermodel.Workbook; 7 | import org.apache.poi.ss.usermodel.WorkbookFactory; 8 | import org.openqa.selenium.By; 9 | import org.openqa.selenium.Keys; 10 | import org.openqa.selenium.WebDriver; 11 | import org.testng.annotations.AfterMethod; 12 | import org.testng.annotations.BeforeMethod; 13 | import org.testng.annotations.Test; 14 | import org.testng.asserts.SoftAssert; 15 | 16 | import java.io.FileInputStream; 17 | import java.io.FileNotFoundException; 18 | import java.io.FileOutputStream; 19 | import java.io.IOException; 20 | import java.util.concurrent.TimeUnit; 21 | 22 | import static org.testng.Assert.assertEquals; 23 | import static org.testng.Assert.assertTrue; 24 | 25 | public class CountryInformationDDT { 26 | 27 | WebDriver driver; 28 | Workbook workbook; 29 | Sheet workSheet; 30 | FileInputStream fileInputStream; 31 | FileOutputStream fileOutputStream; 32 | 33 | 34 | @BeforeMethod 35 | public void setUp() throws IOException { 36 | driver = Driver.getDriver(); 37 | driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); 38 | fileInputStream = new FileInputStream("src/test/resources/Countries.xlsx"); 39 | workbook = WorkbookFactory.create(fileInputStream); 40 | workSheet = workbook.getSheet("Countries"); 41 | } 42 | 43 | @Test 44 | public void test() { 45 | int count = workSheet.getPhysicalNumberOfRows(); 46 | System.out.println("count = " + count); 47 | boolean match =true; 48 | for (int i = 1; i < count; i++) { 49 | Row currentRow = workSheet.getRow(i); 50 | String execute = currentRow.getCell(0).toString(); 51 | System.out.println("execute = " + execute); 52 | if (execute.equals("y")) { 53 | // execute the test 54 | String country = currentRow.getCell(1).toString(); 55 | String capital = currentRow.getCell(2).toString(); 56 | driver.get("https://wikipedia.org"); 57 | driver.findElement(By.id("searchInput")).sendKeys(country + Keys.ENTER); 58 | String actual = driver.findElement(By.xpath("//th[starts-with(text(), 'Capital')]/following-sibling::td//a")).getText(); 59 | if (actual.equals(capital)) { 60 | currentRow.getCell(3).setCellValue("PASS"); 61 | } else { 62 | currentRow.getCell(3).setCellValue("FAIL"); 63 | // create 64 | currentRow.createCell(4); 65 | currentRow.getCell(4).setCellValue(actual); 66 | match=false; 67 | } 68 | 69 | } else { 70 | // skip 71 | currentRow.getCell(3).setCellValue("SKIP"); 72 | continue; 73 | } 74 | 75 | } 76 | 77 | assertTrue(match); 78 | } 79 | 80 | @AfterMethod 81 | public void tearDown() throws IOException { 82 | Driver.closeDriver(); 83 | fileOutputStream = new FileOutputStream("src/test/resources/Countries.xlsx"); 84 | workbook.write(fileOutputStream); 85 | 86 | 87 | fileOutputStream.close(); 88 | fileInputStream.close(); 89 | workbook.close(); 90 | } 91 | } 92 | /* 93 | //th[starts-with(text(), 'Capital')] --> gibe me a th element that starts with text Capital 94 | //th[starts-with(text(), 'Capital')]/../td -> find the th element that starts with text Capital 95 | find its parent 96 | find its other child named td 97 | 98 | //th[starts-with(text(), 'Capital')]/following-sibling::td/a -> find the th element that starts with text Capital 99 | find its next sibling td 100 | */ -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/office_hours4/IframesExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.office_hours4; 2 | 3 | import com.cybertek.base.TestBase; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebElement; 6 | import org.testng.annotations.Test; 7 | 8 | public class IframesExample extends TestBase { 9 | @Test 10 | public void test(){ 11 | driver.get("https://www.w3schools.com/html/tryit.asp?filename=tryhtml_iframe_height_width"); 12 | // switch iframe using id 13 | driver.switchTo().frame("iframeResult"); 14 | System.out.println(driver.findElement(By.tagName("h2")).getText()); 15 | 16 | // switch to iframe using webelement 17 | WebElement innerFrame = driver.findElement(By.cssSelector("iframe[src='demo_iframe.htm']")); 18 | driver.switchTo().frame(innerFrame); 19 | System.out.println(driver.findElement(By.tagName("h1")).getText()); 20 | 21 | // change back to default content 22 | driver.switchTo().defaultContent(); 23 | System.out.println(driver.findElement(By.cssSelector(".cm-m-xml.cm-meta")).getText()); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/office_hours4/JavaScriptExecutorExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.office_hours4; 2 | 3 | import com.cybertek.base.TestBase; 4 | import com.cybertek.utilities.ConfigurationReader; 5 | import com.cybertek.utilities.Driver; 6 | import org.openqa.selenium.By; 7 | import org.openqa.selenium.JavascriptExecutor; 8 | import org.openqa.selenium.WebElement; 9 | import org.testng.annotations.Test; 10 | 11 | import java.util.List; 12 | 13 | public class JavaScriptExecutorExample extends TestBase { 14 | 15 | @Test 16 | public void type() { 17 | driver.get(ConfigurationReader.getProperty("url")); 18 | driver.findElement(By.linkText("Dynamic Controls")).click(); 19 | 20 | // inputField = driver.findElement(webdriver.By.id('gbqfq')); 21 | // driver.executeScript("arguments[0].setAttribute('value', '" + longstring +"')", inputField); 22 | 23 | WebElement webElement = driver.findElement(By.cssSelector("#input-example>input")); 24 | 25 | JavascriptExecutor jse = (JavascriptExecutor) driver; 26 | String text = "hello"; 27 | 28 | jse.executeScript("arguments[0].setAttribute('value', '" + text + "')", webElement); 29 | 30 | } 31 | 32 | @Test 33 | public void highlight() throws InterruptedException { 34 | driver.get(ConfigurationReader.getProperty("url")); 35 | Thread.sleep(1000); 36 | WebElement text = driver.findElement(By.tagName("h1")); 37 | 38 | highlight(text); 39 | 40 | List list = driver.findElements(By.cssSelector("li>a")); 41 | for (WebElement link : list) { 42 | highlight(link); 43 | } 44 | 45 | } 46 | 47 | 48 | public static void highlight(WebElement element) throws InterruptedException { 49 | JavascriptExecutor jse = (JavascriptExecutor) Driver.getDriver(); 50 | jse.executeScript("arguments[0].setAttribute('style', 'background: yellow; border: 2px solid red;');", element); 51 | Thread.sleep(200); 52 | jse.executeScript("arguments[0].removeAttribute('style', 'background: yellow; border: 2px solid red;');", element); 53 | Thread.sleep(200); 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/office_hours4/SoftAssertionsExamples.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.office_hours4; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | import org.testng.asserts.SoftAssert; 6 | 7 | public class SoftAssertionsExamples { 8 | 9 | @Test 10 | public void test() { 11 | 12 | Assert.assertEquals(11, 1, "first assertion failed"); 13 | 14 | Assert.assertEquals(2, 2, "second assertion failed"); 15 | 16 | } 17 | 18 | @Test 19 | public void test2() { 20 | 21 | SoftAssert softAssert = new SoftAssert(); 22 | 23 | softAssert.assertEquals(11, 1, "first assertion failed"); 24 | softAssert.assertEquals(1, 1, "second assertion failed"); 25 | softAssert.assertEquals(22, 2, "third assertion failed"); 26 | 27 | softAssert.assertAll(); 28 | } 29 | 30 | @Test 31 | public void test3() { 32 | SoftAssert softAssert = new SoftAssert(); 33 | 34 | softAssert.assertTrue(true, "first assertion"); 35 | System.out.println("first assertion done"); 36 | 37 | Assert.assertTrue(true, "second assertion"); 38 | System.out.println("second assertion done"); 39 | 40 | Assert.assertTrue(true, "third assertion"); 41 | System.out.println("third assertion done"); 42 | 43 | softAssert.assertTrue(true, "fourth assertion"); 44 | System.out.println("fourth assertion done"); 45 | 46 | // report all of the soft asserts, if any of the soft asserts ever failed, throws assertion error 47 | softAssert.assertAll(); 48 | 49 | Assert.assertTrue(true, "fifth assertion"); 50 | System.out.println("fifth assertion done"); 51 | 52 | } 53 | 54 | 55 | } 56 | 57 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/office_hours4/WebTablesPractice.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.office_hours4; 2 | 3 | import com.cybertek.base.TestBase; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebElement; 6 | import org.testng.Assert; 7 | import org.testng.annotations.BeforeMethod; 8 | import org.testng.annotations.Test; 9 | 10 | import java.util.List; 11 | import java.util.concurrent.TimeUnit; 12 | 13 | public class WebTablesPractice extends TestBase { 14 | 15 | @BeforeMethod 16 | public void setUpTests() { 17 | driver.get("https://www.mockaroo.com/"); 18 | driver.findElement(By.id("num_rows")).clear(); 19 | driver.findElement(By.id("num_rows")).sendKeys("10"); 20 | driver.findElement(By.id("preview")).click(); 21 | driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); 22 | driver.switchTo().frame("preview_iframe"); 23 | 24 | } 25 | 26 | @Test 27 | public void testHeaderCount() { 28 | 29 | WebElement table = driver.findElement(By.xpath("//table")); 30 | System.out.println(table.getText()); 31 | // get all the in the table 32 | List headers = driver.findElements(By.xpath("//table[@style]//th")); 33 | Assert.assertEquals(headers.size(), 6); 34 | } 35 | 36 | /* 37 | verify that value of each entry under gender column is equal to Male or Female 38 | */ 39 | 40 | @Test 41 | public void verifyGender(){ 42 | List allGenders = driver.findElements(By.xpath("//table[@style]/tbody/tr/td[5]")); 43 | System.out.println(allGenders.size()); 44 | 45 | // go through the list 46 | // verify that values is either Male or Female 47 | for (WebElement gender : allGenders) { 48 | String actual = gender.getText(); 49 | Assert.assertTrue(actual.equals("Male") || actual.equals("Female")); 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/utilities/BrowserUtils.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.utilities; 2 | 3 | import com.cybertek.utilities.Driver; 4 | import org.apache.commons.io.FileUtils; 5 | import org.openqa.selenium.JavascriptExecutor; 6 | import org.openqa.selenium.OutputType; 7 | import org.openqa.selenium.TakesScreenshot; 8 | import org.openqa.selenium.WebElement; 9 | import org.openqa.selenium.support.ui.ExpectedCondition; 10 | import org.openqa.selenium.support.ui.WebDriverWait; 11 | 12 | import java.io.File; 13 | import java.io.IOException; 14 | import java.text.SimpleDateFormat; 15 | import java.time.LocalDateTime; 16 | import java.util.ArrayList; 17 | import java.util.Date; 18 | import java.util.List; 19 | 20 | public class BrowserUtils { 21 | 22 | /** 23 | * Pause test for some time 24 | * 25 | * @param seconds 26 | */ 27 | public static void wait(int seconds) { 28 | try { 29 | Thread.sleep(1000 * seconds); 30 | } catch (InterruptedException e) { 31 | e.printStackTrace(); 32 | } 33 | } 34 | 35 | /** 36 | * @param elements represents collection of WebElements 37 | * @return collection of strings 38 | */ 39 | public static List getElementsText(List elements) { 40 | List textValues = new ArrayList<>(); 41 | for (WebElement element : elements) { 42 | if (!element.getText().isEmpty()) { 43 | textValues.add(element.getText()); 44 | } 45 | } 46 | return textValues; 47 | } 48 | 49 | /** 50 | * waits for backgrounds processes on the browser to complete 51 | * 52 | * @param timeOutInSeconds 53 | */ 54 | public static void waitForPageToLoad(long timeOutInSeconds) { 55 | ExpectedCondition expectation = driver -> ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete"); 56 | try { 57 | WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeOutInSeconds); 58 | wait.until(expectation); 59 | } catch (Throwable error) { 60 | error.printStackTrace(); 61 | } 62 | } 63 | 64 | /** 65 | * Clicks on an element using JavaScript 66 | * 67 | * @param element 68 | */ 69 | public static void clickWithJS(WebElement element) { 70 | ((JavascriptExecutor) Driver.getDriver()).executeScript("arguments[0].scrollIntoView(true);", element); 71 | ((JavascriptExecutor) Driver.getDriver()).executeScript("arguments[0].click();", element); 72 | } 73 | 74 | /** 75 | * Scroll to element using JavaScript 76 | * 77 | * @param element 78 | */ 79 | public static void scrollTo(WebElement element) { 80 | ((JavascriptExecutor) Driver.getDriver()).executeScript("arguments[0].scrollIntoView(true);", element); 81 | } 82 | 83 | /* 84 | * takes screenshot 85 | * @param name 86 | * take a name of a test and returns a path to screenshot takes 87 | */ 88 | public static String getScreenshot(String name) throws IOException { 89 | // name the screenshot with the current date time to avoid duplicate name 90 | String date = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()); 91 | // TakesScreenshot ---> interface from selenium which takes screenshots 92 | TakesScreenshot ts = (TakesScreenshot) Driver.getDriver(); 93 | File source = ts.getScreenshotAs(OutputType.FILE); 94 | // full path to the screenshot location 95 | String target = System.getProperty("user.dir") + "/test-output/Screenshots/" + name + date + ".png"; 96 | File finalDestination = new File(target); 97 | // save the screenshot to the path given 98 | FileUtils.copyFile(source, finalDestination); 99 | return target; 100 | } 101 | } -------------------------------------------------------------------------------- /src/test/java/com/cybertek/utilities/ConfigurationReader.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.utilities; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.IOException; 5 | import java.util.Properties; 6 | 7 | public class ConfigurationReader { 8 | 9 | private static Properties properties = new Properties(); 10 | 11 | static { 12 | 13 | try { 14 | // reads file in java. we neeed to pass the path of the file 15 | FileInputStream fileInputStream = new FileInputStream("configuration.properties"); 16 | // load contents of the file the properties object. 17 | properties.load(fileInputStream); 18 | fileInputStream.close(); 19 | 20 | } catch (IOException e) { 21 | e.printStackTrace(); 22 | } 23 | } 24 | 25 | public static String getProperty(String key){ 26 | return properties.getProperty(key); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/utilities/Driver.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.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.opera.OperaDriver; 13 | import org.openqa.selenium.safari.SafariDriver; 14 | 15 | public class Driver { 16 | 17 | private Driver(){} 18 | 19 | private static WebDriver driver; 20 | 21 | public static WebDriver getDriver(){ 22 | // check if the driver has value, if not assign a value 23 | if (driver == null) { 24 | // get the driver type from properties file 25 | String browser = ConfigurationReader.getProperty("browser"); 26 | 27 | switch (browser){ 28 | case "chrome": 29 | WebDriverManager.chromedriver().setup(); 30 | driver = new ChromeDriver(new ChromeOptions().addArguments("disable-extensions")); 31 | break; 32 | case "chrome-headless": 33 | WebDriverManager.chromedriver().setup(); 34 | driver = new ChromeDriver(new ChromeOptions().setHeadless(true)); 35 | break; 36 | case "firefox": 37 | WebDriverManager.firefoxdriver().setup(); 38 | driver = new FirefoxDriver(); 39 | break; 40 | case "firefox-headless": 41 | WebDriverManager.firefoxdriver().setup(); 42 | driver = new FirefoxDriver(new FirefoxOptions().setHeadless(true)); 43 | break; 44 | case "ie": 45 | if (!System.getProperty("os.name").toLowerCase().contains("windows")) 46 | throw new WebDriverException("Your OS doesn't support Internet Explorer"); 47 | WebDriverManager.iedriver().setup(); 48 | driver = new InternetExplorerDriver(); 49 | break; 50 | 51 | case "edge": 52 | if (!System.getProperty("os.name").toLowerCase().contains("windows")) 53 | throw new WebDriverException("Your OS doesn't support Edge"); 54 | WebDriverManager.edgedriver().setup(); 55 | driver = new EdgeDriver(); 56 | break; 57 | 58 | case "safari": 59 | if (!System.getProperty("os.name").toLowerCase().contains("mac")) 60 | throw new WebDriverException("Your OS doesn't support Safari"); 61 | WebDriverManager.getInstance(SafariDriver.class).setup(); 62 | driver = new SafariDriver(); 63 | break; 64 | case "opera": 65 | WebDriverManager.operadriver().setup(); 66 | driver = new OperaDriver(); 67 | break; 68 | 69 | } 70 | } 71 | return driver; 72 | 73 | } 74 | 75 | public static void closeDriver(){ 76 | // close the driver 77 | driver.quit(); 78 | // then make the object null value 79 | driver = null; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/utilities/ExcelUtil.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.utilities; 2 | 3 | 4 | import java.io.FileInputStream; 5 | import java.io.FileOutputStream; 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | import org.apache.poi.ss.usermodel.*; 12 | import org.testng.Assert; 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 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/utilities/WebDriverFactory.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.utilities; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.chrome.ChromeDriver; 6 | import org.openqa.selenium.firefox.FirefoxDriver; 7 | 8 | public class WebDriverFactory { 9 | 10 | //write a static return method which returns WebDriver 11 | //name : getDriver 12 | //it takes a String as a parameter --> browser type 13 | //returns ChromeDriver and FirefoxDriver 14 | 15 | public static WebDriver getDriver(String browserType){ 16 | //local veriables 17 | WebDriver driver = null; 18 | 19 | switch (browserType.toLowerCase()){ 20 | case "chrome" : 21 | WebDriverManager.chromedriver().setup(); 22 | driver = new ChromeDriver(); 23 | break; 24 | case "firefox": 25 | WebDriverManager.firefoxdriver().setup(); 26 | driver = new FirefoxDriver(); 27 | } 28 | return driver; 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/resources/Countries.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybertek-B15Local/fall-2019-selenium-project/b72fdb4c71f43dfe16ab58e453f27e1ee878cd03/src/test/resources/Countries.xlsx -------------------------------------------------------------------------------- /src/test/resources/Vytrack testusers.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybertek-B15Local/fall-2019-selenium-project/b72fdb4c71f43dfe16ab58e453f27e1ee878cd03/src/test/resources/Vytrack testusers.xlsx -------------------------------------------------------------------------------- /testng_runner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | --------------------------------------------------------------------------------