├── .gitignore ├── configuration.properties ├── configurationTwo.properties ├── pom.xml ├── smoke_test_runner.xml ├── src └── test │ ├── java │ └── com │ │ └── cybertek │ │ ├── pages │ │ ├── BasePage.java │ │ ├── CalendarEventsPage.java │ │ ├── ContactInfoPage.java │ │ ├── ContactsPage.java │ │ ├── CreateCalendarEventsPage.java │ │ ├── DashboardPage.java │ │ ├── LoginPage.java │ │ └── adidasPages │ │ │ ├── BasePageForAdidas.java │ │ │ ├── CartPage.java │ │ │ └── ProductPage.java │ │ ├── tests │ │ ├── TestBase.java │ │ ├── TestBaseTwo.java │ │ ├── day10_actions_js │ │ │ ├── ActionsTest.java │ │ │ ├── HoverTest.java │ │ │ └── JavaScriptExecutorDemo.java │ │ ├── day10_file_upload │ │ │ ├── FilePathExample.java │ │ │ └── FileUploadTest.java │ │ ├── day11_webtables │ │ │ └── WebTablesExample.java │ │ ├── day12_properties_driver_tests │ │ │ ├── AnotherLoginTest.java │ │ │ ├── LoginTest.java │ │ │ ├── PropertiesTest.java │ │ │ ├── Singleton.java │ │ │ └── SingletonTest.java │ │ ├── day13_pom │ │ │ ├── NegativeLoginTest.java │ │ │ ├── PageSubtitleTest.java │ │ │ ├── PositiveLoginTest.java │ │ │ └── RepeatOptionsTests.java │ │ ├── day14_extent_reports │ │ │ ├── ExtentDemoTest.java │ │ │ └── NegativeLoginTestWithReport.java │ │ ├── day15_review │ │ │ └── verifyContactInfoTest.java │ │ ├── day16_ddf │ │ │ ├── DDFLoginTest.java │ │ │ ├── DDFWithDataProvider.java │ │ │ └── ExcelUtilsDemo.java │ │ ├── day1_intro │ │ │ └── OpenBrowser.java │ │ ├── day2_webdriver_basics │ │ │ ├── CallWebDriverFactory.java │ │ │ ├── CloseAndQuit.java │ │ │ ├── GetTitleAndUrl.java │ │ │ └── NavigationDemo.java │ │ ├── day3_webelement_intro │ │ │ ├── verifyConfirmationMessage.java │ │ │ ├── verifyURLchanged.java │ │ │ └── verifyURLnotChanged.java │ │ ├── day4_basic_locators │ │ │ ├── IDLocatorTest.java │ │ │ ├── classNameTest.java │ │ │ ├── linkTextandPartialLinkText.java │ │ │ ├── nameLocatorTest.java │ │ │ └── tagNameLocator.java │ │ ├── day5_xpath │ │ │ ├── AmazonTest.java │ │ │ └── xPathLocator.java │ │ ├── day6_css │ │ │ └── cssLocator.java │ │ ├── day7_testng │ │ │ ├── BeforeAfterMethod.java │ │ │ ├── FirstTestNGTest.java │ │ │ └── TestNGAssertionsDemo.java │ │ ├── day7_types_of_elements │ │ │ ├── AttributeTest.java │ │ │ ├── CheckboxDemo.java │ │ │ ├── DisabledElements.java │ │ │ ├── DisplayedDemo.java │ │ │ └── RadioButtonTest.java │ │ ├── day8_types_of_elements_2 │ │ │ ├── ListOfElements.java │ │ │ ├── NoSelectDropdown.java │ │ │ └── SelectDropdownTest.java │ │ ├── day9_popups_tabs_frames │ │ │ ├── MultipleWindows.java │ │ │ ├── PopupsAndAlerts.java │ │ │ └── iframeTest.java │ │ ├── day9_waits │ │ │ ├── ExplicitWaitExample.java │ │ │ ├── ImplicitWaitExample.java │ │ │ └── ThreadSleepExample.java │ │ └── reviews │ │ │ ├── week01 │ │ │ ├── NotesOfTheWeek │ │ │ ├── T01_YahooPractice.java │ │ │ └── T02_CybertekUrlTask.java │ │ │ ├── week02 │ │ │ ├── LocatorHWTest.java │ │ │ ├── Notes.txt │ │ │ └── Task2.java │ │ │ ├── week03 │ │ │ ├── CheckBoxHW.java │ │ │ └── Notes.txt │ │ │ ├── week04 │ │ │ ├── ChercherTest.java │ │ │ └── DropdownTest.java │ │ │ ├── week5 │ │ │ ├── ActionsandIframeTest.java │ │ │ ├── AdidasTask.java │ │ │ └── ScrollingTest.java │ │ │ ├── week6 │ │ │ └── AdidasTaskWithPOM.java │ │ │ └── week7 │ │ │ ├── DataProviderExample.java │ │ │ ├── ExcelDDFTest.java │ │ │ ├── ExelTestExamples.java │ │ │ ├── HWTests.java │ │ │ ├── Notes.txt │ │ │ └── TestBaseForHW.java │ │ └── utilities │ │ ├── BrowserUtils.java │ │ ├── ConfigurationReader.java │ │ ├── ConfigurationReaderTwo.java │ │ ├── Driver.java │ │ ├── ExcelUtil.java │ │ └── WebDriverFactory.java │ └── resources │ ├── StatusCodes.xlsx │ ├── Vytracktestdata.xlsx │ └── textfile.txt └── testng_runner.xml /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.idea/ 3 | -------------------------------------------------------------------------------- /configuration.properties: -------------------------------------------------------------------------------- 1 | browser=chrome 2 | url=https://qa1.vytrack.com 3 | qa1_url=https://qa1.vytrack.com 4 | qa2_url=https://qa2.vytrack.com 5 | qa3_url=https://qa3.vytrack.com 6 | driver_username=user1 7 | driver_password=UserUser123 8 | salesmanager_username=salesmanager120 9 | salesmanager_password=UserUser123 10 | storemanager_username=storemanager85 11 | storemanager_password=UserUser123 12 | 13 | -------------------------------------------------------------------------------- /configurationTwo.properties: -------------------------------------------------------------------------------- 1 | browser=chrome 2 | demoblaze.url=https://www.demoblaze.com/index.html -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | EU7TestNGSelenium 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 1.8 13 | 1.8 14 | 15 | 16 | 17 | 18 | com.github.javafaker 19 | javafaker 20 | 1.0.2 21 | 22 | 23 | 24 | 25 | org.seleniumhq.selenium 26 | selenium-java 27 | 3.141.59 28 | 29 | 30 | 31 | 32 | io.github.bonigarcia 33 | webdrivermanager 34 | 5.0.3 35 | 36 | 37 | org.testng 38 | testng 39 | 7.1.0 40 | test 41 | 42 | 43 | 44 | com.aventstack 45 | extentreports 46 | 4.0.9 47 | 48 | 49 | 50 | 51 | org.apache.poi 52 | poi 53 | 4.1.2 54 | 55 | 56 | 57 | 58 | org.apache.poi 59 | poi-ooxml 60 | 4.1.2 61 | 62 | 63 | org.projectlombok 64 | lombok 65 | RELEASE 66 | test 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /smoke_test_runner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/BasePage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages; 2 | 3 | import com.cybertek.utilities.BrowserUtils; 4 | import com.cybertek.utilities.Driver; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.interactions.Actions; 8 | import org.openqa.selenium.support.CacheLookup; 9 | import org.openqa.selenium.support.FindBy; 10 | import org.openqa.selenium.support.PageFactory; 11 | import org.openqa.selenium.support.ui.ExpectedConditions; 12 | import org.openqa.selenium.support.ui.WebDriverWait; 13 | 14 | public abstract class BasePage { 15 | 16 | @FindBy(css = "div[class='loader-mask shown']") 17 | @CacheLookup 18 | protected WebElement loaderMask; 19 | 20 | @FindBy(css = "h1[class='oro-subtitle']") 21 | public WebElement pageSubTitle; 22 | 23 | @FindBy(css = "#user-menu > a") 24 | public WebElement userName; 25 | 26 | @FindBy(linkText = "Logout") 27 | public WebElement logOutLink; 28 | 29 | @FindBy(linkText = "My User") 30 | public WebElement myUser; 31 | 32 | public BasePage() { 33 | PageFactory.initElements(Driver.get(), this); 34 | } 35 | 36 | 37 | /** 38 | * @return page name, for example: Dashboard 39 | */ 40 | public String getPageSubTitle() { 41 | //ant time we are verifying page name, or page subtitle, loader mask appears 42 | waitUntilLoaderScreenDisappear(); 43 | // BrowserUtils.waitForStaleElement(pageSubTitle); 44 | return pageSubTitle.getText(); 45 | } 46 | 47 | 48 | /** 49 | * Waits until loader screen present. If loader screen will not pop up at all, 50 | * NoSuchElementException will be handled bu try/catch block 51 | * Thus, we can continue in any case. 52 | */ 53 | public void waitUntilLoaderScreenDisappear() { 54 | try { 55 | WebDriverWait wait = new WebDriverWait(Driver.get(), 5); 56 | wait.until(ExpectedConditions.invisibilityOf(loaderMask)); 57 | } catch (Exception e) { 58 | e.printStackTrace(); 59 | } 60 | 61 | } 62 | 63 | public String getUserName(){ 64 | waitUntilLoaderScreenDisappear(); 65 | BrowserUtils.waitForVisibility(userName, 5); 66 | return userName.getText(); 67 | } 68 | 69 | 70 | 71 | public void logOut(){ 72 | BrowserUtils.waitFor(2); 73 | BrowserUtils.clickWithJS(userName); 74 | BrowserUtils.clickWithJS(logOutLink); 75 | } 76 | public void goToMyUser(){ 77 | waitUntilLoaderScreenDisappear(); 78 | BrowserUtils.waitForClickablility(userName, 5).click(); 79 | BrowserUtils.waitForClickablility(myUser, 5).click(); 80 | 81 | } 82 | 83 | /** 84 | * This method will navigate user to the specific module in vytrack application. 85 | * For example: if tab is equals to Activities, and module equals to Calls, 86 | * Then method will navigate user to this page: http://qa2.vytrack.com/call/ 87 | * 88 | * @param tab 89 | * @param module 90 | */ 91 | public void navigateToModule(String tab, String module) { 92 | String tabLocator = "//span[normalize-space()='" + tab + "' and contains(@class, 'title title-level-1')]"; 93 | // String moduleLocator2 = "//span[@class='title title-level-1' and contains(text(),'"+ module + "')]"; 94 | 95 | String moduleLocator = "//span[normalize-space()='" + module + "' and contains(@class, 'title title-level-2')]"; 96 | // String moduleLocator2 = "//span[@class='title title-level-2' and contains(text(),'"+ module + "')]"; 97 | try { 98 | BrowserUtils.waitForClickablility(By.xpath(tabLocator), 5); 99 | WebElement tabElement = Driver.get().findElement(By.xpath(tabLocator)); 100 | new Actions(Driver.get()).moveToElement(tabElement).pause(200).doubleClick(tabElement).build().perform(); 101 | } catch (Exception e) { 102 | BrowserUtils.clickWithWait(By.xpath(tabLocator), 5); 103 | } 104 | try { 105 | BrowserUtils.waitForPresenceOfElement(By.xpath(moduleLocator), 5); 106 | BrowserUtils.waitForVisibility(By.xpath(moduleLocator), 5); 107 | BrowserUtils.scrollToElement(Driver.get().findElement(By.xpath(moduleLocator))); 108 | Driver.get().findElement(By.xpath(moduleLocator)).click(); 109 | } catch (Exception e) { 110 | BrowserUtils.clickWithTimeOut(Driver.get().findElement(By.xpath(moduleLocator)), 5); 111 | 112 | } 113 | } 114 | 115 | } -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/CalendarEventsPage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages; 2 | 3 | import com.cybertek.utilities.Driver; 4 | import org.openqa.selenium.WebElement; 5 | import org.openqa.selenium.support.FindBy; 6 | import org.openqa.selenium.support.PageFactory; 7 | 8 | public class CalendarEventsPage extends BasePage { 9 | 10 | public CalendarEventsPage() { 11 | PageFactory.initElements(Driver.get(), this); 12 | } 13 | 14 | @FindBy(css = "[title='Create Calendar event']") 15 | public WebElement createCalendarEvent; 16 | 17 | @FindBy(css = "div[class='btn btn-link dropdown-toggle']") 18 | public WebElement optionsLink; 19 | 20 | @FindBy(css = "input[type='number']") 21 | public WebElement pageNumber; 22 | 23 | @FindBy(css = "button[class='btn dropdown-toggle ']") 24 | public WebElement viewPerPage; 25 | 26 | 27 | } -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/ContactInfoPage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages; 2 | 3 | import org.openqa.selenium.WebElement; 4 | import org.openqa.selenium.support.FindBy; 5 | 6 | public class ContactInfoPage extends BasePage{ 7 | 8 | @FindBy(css = "div.pull-left>h1.user-name") 9 | public WebElement fullName; 10 | 11 | @FindBy(css = "a.phone") 12 | public WebElement phone; 13 | 14 | @FindBy(css = "a.email") 15 | public WebElement email; 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/ContactsPage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages; 2 | 3 | import com.cybertek.utilities.Driver; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebElement; 6 | 7 | public class ContactsPage extends BasePage{ 8 | 9 | //since we are extending BasePage we do not need explicit constructor for this class 10 | 11 | // @FindBy(xpath = "//td[contains(text(),'mbrackstone9@example.com')][@data-column-label='Email']") 12 | // public WebElement email; 13 | 14 | public WebElement getContactEmail(String email){ 15 | String xpath ="//td[contains(text(),'"+email+"')][@data-column-label='Email']"; 16 | return Driver.get().findElement(By.xpath(xpath)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/CreateCalendarEventsPage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages; 2 | 3 | 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 | import org.openqa.selenium.support.ui.Select; 9 | 10 | public class CreateCalendarEventsPage extends BasePage { 11 | 12 | public CreateCalendarEventsPage(){ 13 | PageFactory.initElements(Driver.get(), this); 14 | } 15 | 16 | @FindBy(css = "[id^='recurrence-repeat-view']") 17 | public WebElement repeat; 18 | 19 | @FindBy(css = "[id^='recurrence-repeats-view']") 20 | public WebElement repeatOptions; 21 | 22 | @FindBy(className = "select2-chosen") 23 | public WebElement selectedOwner; 24 | 25 | @FindBy(css = "input[id^='oro_calendar_event_form_title-']") 26 | public WebElement title; 27 | 28 | @FindBy(css = "[id^='date_selector_oro_calendar_event_form_start']") 29 | public WebElement startDate; 30 | @FindBy(css = "[id^='date_selector_oro_calendar_event_form_end']") 31 | public WebElement endDate; 32 | 33 | @FindBy(css = "[id^='time_selector_oro_calendar_event_form_start']") 34 | public WebElement startTime; 35 | 36 | @FindBy(css = "[id^='time_selector_oro_calendar_event_form_end']") 37 | public WebElement endTime; 38 | 39 | @FindBy(xpath = "(//input[@type='radio'])[1]") 40 | public WebElement days; 41 | 42 | @FindBy(xpath = "(//input[@type='radio'])[2]") 43 | public WebElement weekday; 44 | 45 | @FindBy(xpath = "(//input[@type='radio'])[3]") 46 | public WebElement never; 47 | 48 | @FindBy(xpath = "(//input[@type='radio'])[4]") 49 | public WebElement after; 50 | 51 | @FindBy(xpath = "(//input[@type='radio'])[5]") 52 | public WebElement by; 53 | 54 | 55 | 56 | public Select repeatOptionsList(){ 57 | return new Select(repeatOptions); 58 | } 59 | 60 | 61 | 62 | } -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/DashboardPage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages; 2 | 3 | public class DashboardPage extends BasePage{ 4 | 5 | //no need to explicitly write constructor, because it will use its parents constructor 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/LoginPage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages; 2 | 3 | import com.cybertek.utilities.ConfigurationReader; 4 | import com.cybertek.utilities.Driver; 5 | import org.openqa.selenium.WebElement; 6 | import org.openqa.selenium.support.FindAll; 7 | import org.openqa.selenium.support.FindBy; 8 | import org.openqa.selenium.support.PageFactory; 9 | 10 | public class LoginPage { 11 | 12 | public LoginPage(){ 13 | PageFactory.initElements(Driver.get(),this); 14 | } 15 | 16 | //driver.findElement(By.id("prependedInput")); 17 | @FindAll({ 18 | @FindBy(id = "prependedInput"), 19 | @FindBy(name ="_username") 20 | }) 21 | public WebElement usernameInput; 22 | 23 | @FindBy(id = "prependedInput2") 24 | public WebElement passwordInput; 25 | 26 | //driver.findElement(By.id("_submit")); 27 | @FindBy(id = "_submit") 28 | public WebElement loginBtn; 29 | 30 | 31 | 32 | public void login(String username,String password){ 33 | usernameInput.sendKeys(username); 34 | passwordInput.sendKeys(password); 35 | loginBtn.click(); 36 | } 37 | 38 | public void loginAsStoreManager(){ 39 | 40 | String username = ConfigurationReader.get("storemanager_username"); 41 | String password = ConfigurationReader.get("storemanager_password"); 42 | 43 | usernameInput.sendKeys(username); 44 | passwordInput.sendKeys(password); 45 | loginBtn.click(); 46 | } 47 | 48 | public void loginAsDriver(){ 49 | 50 | String username = ConfigurationReader.get("driver_username"); 51 | String password = ConfigurationReader.get("driver_password"); 52 | 53 | usernameInput.sendKeys(username); 54 | passwordInput.sendKeys(password); 55 | loginBtn.click(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/adidasPages/BasePageForAdidas.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages.adidasPages; 2 | 3 | import com.cybertek.utilities.BrowserUtils; 4 | import com.cybertek.utilities.Driver; 5 | import org.openqa.selenium.Alert; 6 | import org.openqa.selenium.By; 7 | import org.openqa.selenium.WebElement; 8 | import org.openqa.selenium.support.PageFactory; 9 | import org.openqa.selenium.support.ui.ExpectedConditions; 10 | import org.openqa.selenium.support.ui.WebDriverWait; 11 | 12 | public abstract class BasePageForAdidas { 13 | 14 | public BasePageForAdidas(){ 15 | PageFactory.initElements(Driver.get(),this); 16 | } 17 | 18 | public void navigateTo(String str){ 19 | Driver.get().findElement(By.partialLinkText(str)).click(); 20 | } 21 | 22 | public int productAdder(String category, String product){ 23 | navigateTo(category); 24 | navigateTo(product); 25 | // I want to get my expected price for that product 26 | WebDriverWait wait = new WebDriverWait(Driver.get(),10); 27 | wait.until(ExpectedConditions.visibilityOfElementLocated(By.tagName("h3"))); 28 | WebElement priceElement = Driver.get().findElement(By.tagName("h3")); 29 | String priceWholeText = priceElement.getText(); 30 | String[] arr = priceWholeText.split(" "); 31 | int listPrice = Integer.parseInt(arr[0].substring(1)); 32 | 33 | navigateTo("Add to cart"); 34 | // handle pop up 35 | wait.until(ExpectedConditions.alertIsPresent()); 36 | Alert alert = Driver.get().switchTo().alert(); 37 | alert.accept(); 38 | navigateTo("Home"); 39 | return listPrice; 40 | } 41 | 42 | public int productRemover(String product) { 43 | // locator //tr[contains(.,'Sony vaio i5')]/td[4]/a 44 | // locator for price text : //tr[contains(.,'Sony vaio i5')]/td[3] 45 | navigateTo("Cart"); 46 | WebElement priceElement = Driver.get().findElement(By.xpath("//tr[contains(.,'"+product+"')]/td[3]")); 47 | int price = Integer.parseInt(priceElement.getText()); 48 | WebElement deleteButton = Driver.get().findElement(By.xpath("//tr[contains(.,'"+product+"')]/td[4]/a")); 49 | deleteButton.click(); 50 | BrowserUtils.waitFor(3); 51 | 52 | return price; 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/adidasPages/CartPage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages.adidasPages; 2 | 3 | import com.github.javafaker.Faker; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebElement; 6 | import org.openqa.selenium.support.FindBy; 7 | 8 | public class CartPage extends BasePageForAdidas{ 9 | // public CartPage(){ 10 | // super(); 11 | // } No need to call parent constructor, because it is already called 12 | 13 | @FindBy(css = "button[class='btn btn-success']") 14 | public WebElement placeOrderButton; 15 | @FindBy(id = "name") 16 | public WebElement nameFake; 17 | @FindBy(id = "country") 18 | public WebElement country; 19 | @FindBy(id = "city") 20 | public WebElement city; 21 | @FindBy(id = "card") 22 | public WebElement card; 23 | @FindBy(id = "month") 24 | public WebElement month; 25 | @FindBy(id = "year") 26 | public WebElement year; 27 | 28 | 29 | 30 | public void fillForm(){ 31 | Faker faker = new Faker(); 32 | nameFake.sendKeys(faker.name().fullName()); 33 | country.sendKeys(faker.country().name()); 34 | city.sendKeys(faker.country().capital()); 35 | card.sendKeys(faker.finance().creditCard()); 36 | month.sendKeys(""+faker.number().numberBetween(1,12)); 37 | year.sendKeys(""+faker.number().numberBetween(2022,2025)); 38 | 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/pages/adidasPages/ProductPage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.pages.adidasPages; 2 | 3 | import org.openqa.selenium.WebElement; 4 | import org.openqa.selenium.support.FindBy; 5 | 6 | public class ProductPage extends BasePageForAdidas{ 7 | 8 | @FindBy(tagName = "h2") 9 | public WebElement productName; 10 | 11 | @FindBy(tagName = "h3") 12 | public WebElement priceElement; 13 | 14 | @FindBy(xpath = "(//p)[4]") 15 | public WebElement productDescription; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/TestBase.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests; 2 | 3 | import com.aventstack.extentreports.ExtentReports; 4 | import com.aventstack.extentreports.ExtentTest; 5 | import com.aventstack.extentreports.reporter.ExtentHtmlReporter; 6 | import com.cybertek.utilities.BrowserUtils; 7 | import com.cybertek.utilities.ConfigurationReader; 8 | import com.cybertek.utilities.Driver; 9 | import org.openqa.selenium.WebDriver; 10 | import org.openqa.selenium.interactions.Actions; 11 | import org.openqa.selenium.support.ui.WebDriverWait; 12 | import org.testng.ITestResult; 13 | import org.testng.annotations.*; 14 | 15 | import java.io.IOException; 16 | import java.util.concurrent.TimeUnit; 17 | 18 | public class TestBase { 19 | protected WebDriver driver; 20 | protected Actions actions; 21 | protected WebDriverWait wait; 22 | //this class is used for starting and building reports 23 | protected static ExtentReports report; 24 | //this class is used to create HTML report file 25 | protected static ExtentHtmlReporter htmlReporter; 26 | //this will define a test, enables adding logs, authors, test steps 27 | protected static ExtentTest extentLogger; 28 | 29 | //env set up 30 | protected String url; 31 | 32 | @BeforeTest 33 | public void setUpTest(){ 34 | //initialize the class 35 | report = new ExtentReports(); 36 | 37 | //create a report path 38 | String projectPath = System.getProperty("user.dir"); 39 | String path = projectPath + "/test-output/report.html"; 40 | 41 | //initialize the html reporter with the report path 42 | htmlReporter = new ExtentHtmlReporter(path); 43 | 44 | //attach the html report to report object 45 | report.attachReporter(htmlReporter); 46 | 47 | //title in report 48 | htmlReporter.config().setReportName("Vytrack Smoke Test"); 49 | 50 | //set environment information 51 | report.setSystemInfo("Environment","QA"); 52 | report.setSystemInfo("Browser", ConfigurationReader.get("browser")); 53 | report.setSystemInfo("OS",System.getProperty("os.name")); 54 | 55 | } 56 | 57 | @BeforeMethod 58 | @Parameters("env") 59 | public void setUp(@Optional String env){ 60 | 61 | System.out.println("env== " + env); 62 | if (env==null){ 63 | url =ConfigurationReader.get("url"); 64 | }else{ 65 | 66 | url = ConfigurationReader.get(env+"_url"); 67 | } 68 | driver = Driver.get(); 69 | driver.manage().window().maximize(); 70 | driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 71 | actions = new Actions(driver); 72 | wait = new WebDriverWait(driver,10); 73 | driver.get(url); 74 | 75 | } 76 | //ITestResult class describes the result of a test in TestNG 77 | @AfterMethod 78 | public void tearDown(ITestResult result) throws InterruptedException, IOException { 79 | //if test fails 80 | if(result.getStatus()==ITestResult.FAILURE){ 81 | //record the name of failed test case 82 | extentLogger.fail(result.getName()); 83 | 84 | //take the screenshot and return location of screenshot 85 | String screenShotPath = BrowserUtils.getScreenshot(result.getName()); 86 | 87 | //add your screenshot to your report 88 | extentLogger.addScreenCaptureFromPath(screenShotPath); 89 | 90 | //capture the exception and put inside the report 91 | extentLogger.fail(result.getThrowable()); 92 | 93 | } 94 | Thread.sleep(2000); 95 | Driver.closeDriver(); 96 | } 97 | 98 | @AfterTest 99 | public void tearDownTest(){ 100 | //this is when the report is actually created 101 | report.flush(); 102 | 103 | } 104 | 105 | 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/TestBaseTwo.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests; 2 | 3 | import com.cybertek.utilities.ConfigurationReader; 4 | import com.cybertek.utilities.ConfigurationReaderTwo; 5 | import com.cybertek.utilities.Driver; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.interactions.Actions; 8 | import org.openqa.selenium.support.ui.WebDriverWait; 9 | import org.testng.annotations.AfterMethod; 10 | import org.testng.annotations.BeforeMethod; 11 | 12 | import java.util.concurrent.TimeUnit; 13 | 14 | public class TestBaseTwo { 15 | protected WebDriver driver; 16 | protected Actions actions; 17 | protected WebDriverWait wait; 18 | 19 | @BeforeMethod 20 | public void setUp(){ 21 | driver = Driver.get(); // statically calling object 22 | driver.manage().window().maximize(); 23 | driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 24 | actions = new Actions(driver); 25 | wait = new WebDriverWait(driver,10); 26 | driver.get(ConfigurationReaderTwo.get("demoblaze.url")); 27 | 28 | } 29 | 30 | @AfterMethod 31 | public void tearDown() throws InterruptedException { 32 | Thread.sleep(2000); 33 | Driver.closeDriver(); 34 | // driver.quit(); NEVER NEVER use this statement again 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day10_actions_js/ActionsTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day10_actions_js; 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 | import java.util.List; 14 | 15 | public class ActionsTest { 16 | 17 | 18 | WebDriver driver; 19 | 20 | @BeforeMethod 21 | public void setUp(){ 22 | driver = WebDriverFactory.getDriver("chrome"); 23 | 24 | } 25 | 26 | @AfterMethod 27 | public void tearDown() throws InterruptedException { 28 | Thread.sleep(2000); 29 | driver.quit(); 30 | } 31 | 32 | @Test 33 | public void hoverTest() throws InterruptedException { 34 | driver.get("http://practice.cybertekschool.com/hovers"); 35 | 36 | WebElement img1 = driver.findElement(By.tagName("img")); 37 | //Actions --> class that contains all the user interactions 38 | //how to create actions object --> passing driver as a constructor 39 | Actions actions = new Actions(driver); 40 | //perform() --> perform the action, complete the action 41 | //moveToElement --> move you mouse to webelement(hover over) 42 | Thread.sleep(2000); 43 | actions.moveToElement(img1).perform(); 44 | 45 | WebElement viewLink = driver.findElement(By.linkText("View profile")); 46 | 47 | Assert.assertTrue(viewLink.isDisplayed(),"verify view link is displayed"); 48 | 49 | } 50 | 51 | @Test 52 | public void dragAndDrop() throws InterruptedException { 53 | driver.get("https://demos.telerik.com/kendo-ui/dragdrop/index"); 54 | driver.manage().window().maximize(); 55 | 56 | Actions actions = new Actions(driver); 57 | 58 | List acceptAndClose = driver.findElements(By.xpath("//*[.='Accept and Close']")); 59 | List acceptCookies = driver.findElements(By.xpath("//*[.='Accept Cookies']")); 60 | Thread.sleep(1000); 61 | if(acceptAndClose.size()>0){ 62 | acceptAndClose.get(0).click(); 63 | }else if(acceptCookies.size()>0){ 64 | acceptCookies.get(0).click(); 65 | } 66 | 67 | WebElement source = driver.findElement(By.id("draggable")); 68 | WebElement target = driver.findElement(By.id("droptarget")); 69 | 70 | 71 | Thread.sleep(2000); 72 | actions.dragAndDrop(source,target).perform(); 73 | } 74 | 75 | @Test 76 | public void dragAndDropChaining() throws InterruptedException { 77 | driver.get("https://demos.telerik.com/kendo-ui/dragdrop/index"); 78 | driver.manage().window().maximize(); 79 | 80 | Actions actions = new Actions(driver); 81 | 82 | List acceptAndClose = driver.findElements(By.xpath("//*[.='Accept and Close']")); 83 | List acceptCookies = driver.findElements(By.xpath("//*[.='Accept Cookies']")); 84 | Thread.sleep(1000); 85 | if(acceptAndClose.size()>0){ 86 | acceptAndClose.get(0).click(); 87 | }else if(acceptCookies.size()>0){ 88 | acceptCookies.get(0).click(); 89 | } 90 | 91 | WebElement source = driver.findElement(By.id("draggable")); 92 | WebElement target = driver.findElement(By.id("droptarget")); 93 | 94 | Thread.sleep(2000); 95 | actions.moveToElement(source).clickAndHold().moveToElement(target).pause(2000).release().perform(); 96 | 97 | 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day10_actions_js/HoverTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day10_actions_js; 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 HoverTest { 14 | 15 | WebDriver driver; 16 | 17 | @BeforeMethod 18 | public void setUp(){ 19 | driver = WebDriverFactory.getDriver("chrome"); 20 | 21 | } 22 | 23 | @AfterMethod 24 | public void tearDown() throws InterruptedException { 25 | Thread.sleep(2000); 26 | driver.quit(); 27 | } 28 | 29 | /** 30 | * hover over each image in the website 31 | * verify each name:user text is displayed 32 | */ 33 | 34 | @Test 35 | public void oneImage() throws InterruptedException { 36 | driver.get("http://practice.cybertekschool.com/hovers"); 37 | 38 | WebElement img1 = driver.findElement(By.tagName("img")); 39 | 40 | Actions actions = new Actions(driver); 41 | 42 | Thread.sleep(2000); 43 | actions.moveToElement(img1).perform(); 44 | 45 | WebElement text1 = driver.findElement(By.xpath("//h5[.='name: user1']")); 46 | 47 | Assert.assertTrue(text1.isDisplayed(),"verify text 1 is displayed"); 48 | 49 | } 50 | 51 | /** 52 | * hover over each image in the website 53 | * verify each name:user text is displayed 54 | */ 55 | @Test 56 | public void test2() throws InterruptedException { 57 | driver.get("http://practice.cybertekschool.com/hovers"); 58 | 59 | for (int i = 1; i <= 3; i++) { 60 | 61 | String xpathImg = "(//img)["+i+"]"; 62 | WebElement img = driver.findElement(By.xpath(xpathImg)); 63 | System.out.println(xpathImg); 64 | 65 | Actions actions = new Actions(driver); 66 | Thread.sleep(1000); 67 | actions.moveToElement(img).perform(); 68 | 69 | String textXpath = "//h5[.='name: user"+i+"']"; 70 | WebElement text1 = driver.findElement(By.xpath(textXpath)); 71 | System.out.println(textXpath); 72 | Assert.assertTrue(text1.isDisplayed(),"verify user "+i+" is displayed"); 73 | 74 | } 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day10_actions_js/JavaScriptExecutorDemo.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day10_actions_js; 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.testng.annotations.AfterMethod; 9 | import org.testng.annotations.BeforeMethod; 10 | import org.testng.annotations.Test; 11 | 12 | public class JavaScriptExecutorDemo { 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() throws InterruptedException { 24 | Thread.sleep(2000); 25 | // driver.quit(); 26 | } 27 | 28 | @Test 29 | public void clickWithJS(){ 30 | driver.get("http://practice.cybertekschool.com/"); 31 | 32 | WebElement dropdownLink = driver.findElement(By.linkText("Dropdown")); 33 | JavascriptExecutor jse = (JavascriptExecutor) driver; 34 | 35 | jse.executeScript("arguments[0].click();", dropdownLink); 36 | 37 | } 38 | 39 | @Test 40 | public void typeWithJS(){ 41 | driver.get("http://practice.cybertekschool.com/dynamic_controls"); 42 | 43 | WebElement inputBox = driver.findElement(By.cssSelector("#input-example>input")); 44 | 45 | JavascriptExecutor jse = (JavascriptExecutor) driver; 46 | 47 | String text = "Hello Disabled Input"; 48 | 49 | jse.executeScript("arguments[0].setAttribute('value', '" + text +"')", inputBox); 50 | 51 | } 52 | 53 | @Test 54 | public void ScrollDownAndUp() throws InterruptedException { 55 | driver.get("http://practice.cybertekschool.com/infinite_scroll"); 56 | driver.manage().window().maximize(); 57 | 58 | JavascriptExecutor jse = (JavascriptExecutor) driver; 59 | 60 | for (int i = 0; i < 10; i++) { 61 | Thread.sleep(1000); 62 | jse.executeScript("window.scrollBy(0,250)"); 63 | 64 | } 65 | 66 | for (int i = 0; i < 10; i++) { 67 | Thread.sleep(1000); 68 | jse.executeScript("window.scrollBy(0,-250)"); 69 | 70 | } 71 | 72 | 73 | } 74 | 75 | @Test 76 | public void scrollToElement() throws InterruptedException { 77 | 78 | driver.get("https://www.amazon.com/"); 79 | WebElement eng = driver.findElement(By.id("icp-touch-link-language")); 80 | Thread.sleep(2000); 81 | JavascriptExecutor jse = (JavascriptExecutor) driver; 82 | 83 | jse.executeScript("arguments[0].scrollIntoView(true);",eng); 84 | 85 | 86 | } 87 | 88 | 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day10_file_upload/FilePathExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day10_file_upload; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | public class FilePathExample { 6 | 7 | @Test 8 | public void test1(){ 9 | // /Users/jamaldemir/IdeaProjects/fromgit/EU3TestNGSelenium/src/test/resources/textfile.txt 10 | 11 | // /Users/jamaldemir/IdeaProjects/fromgit/EU3TestNGSelenium src/test/resources/textfile.txt; 12 | //System.out.println(System.getProperty("user.dir")); 13 | System.out.println(System.getProperty("os.name")); 14 | String projectPath = System.getProperty("user.dir"); 15 | System.out.println("projectPath = " + projectPath); 16 | 17 | String filePath = "src/test/resources/textfile.txt"; 18 | 19 | String fullPath = projectPath+"/"+filePath; 20 | System.out.println(fullPath); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day10_file_upload/FileUploadTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day10_file_upload; 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 FileUploadTest { 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() throws InterruptedException { 24 | Thread.sleep(2000); 25 | //driver.quit(); 26 | } 27 | 28 | @Test 29 | public void test1(){ 30 | driver.get("http://practice.cybertekschool.com/upload"); 31 | //locating choose file button 32 | WebElement chooseFile = driver.findElement(By.name("file")); 33 | //sending file with sendKeys method 34 | chooseFile.sendKeys("C:/Users/Oscar/Desktop/cars.docx"); 35 | //clicking upload button 36 | driver.findElement(By.id("file-submit")).click(); 37 | 38 | //getting the file name from browser 39 | String actualFileName= driver.findElement(By.id("uploaded-files")).getText(); 40 | //verify file name is file.txt 41 | Assert.assertEquals(actualFileName,"file.txt"); 42 | 43 | } 44 | 45 | @Test 46 | public void test2(){ 47 | driver.get("http://practice.cybertekschool.com/upload"); 48 | //locating choose file button 49 | WebElement chooseFile = driver.findElement(By.name("file")); 50 | 51 | //sending file with sendKeys method 52 | String projectPath = System.getProperty("user.dir"); 53 | String filePath = "src/test/resources/textfile.txt"; 54 | String fullPath = projectPath+"/"+filePath; 55 | chooseFile.sendKeys(fullPath); 56 | //clicking upload button 57 | driver.findElement(By.id("file-submit")).click(); 58 | 59 | //getting the file name from browser 60 | String actualFileName= driver.findElement(By.id("uploaded-files")).getText(); 61 | //verify file name is file.txt 62 | Assert.assertEquals(actualFileName,"textfile.txt"); 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day11_webtables/WebTablesExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day11_webtables; 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.BeforeMethod; 9 | import org.testng.annotations.Test; 10 | 11 | import java.util.List; 12 | import java.util.concurrent.TimeUnit; 13 | 14 | public class WebTablesExample { 15 | 16 | 17 | WebDriver driver; 18 | 19 | @BeforeMethod 20 | public void setUp(){ 21 | driver = WebDriverFactory.getDriver("chrome"); 22 | driver.manage().window().maximize(); 23 | driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 24 | driver.get("http://practice.cybertekschool.com/tables"); 25 | } 26 | 27 | // @AfterMethod 28 | // public void tearDown() throws InterruptedException { 29 | // Thread.sleep(2000); 30 | // driver.quit(); 31 | // } 32 | 33 | @Test 34 | public void printTable(){ 35 | WebElement table = driver.findElement(By.xpath("//table[@id='table1']")); 36 | 37 | System.out.println(table.getText()); 38 | 39 | Assert.assertTrue(table.getText().contains("jdoe@hotmail.com")); 40 | } 41 | 42 | @Test 43 | public void getAllHeaders(){ 44 | //how many columns we have ? 45 | List headers = driver.findElements(By.xpath("//table[@id='table1']//th")); 46 | System.out.println("headers.size() = " + headers.size()); 47 | 48 | for (WebElement header : headers) { 49 | System.out.println(header.getText()); 50 | } 51 | 52 | } 53 | 54 | @Test 55 | public void printTableSize(){ 56 | //how many columns we have ? 57 | List headers = driver.findElements(By.xpath("//table[@id='table1']//th")); 58 | System.out.println("headers.size() = " + headers.size()); 59 | 60 | //number of rows 61 | List allRowsWithHeader = driver.findElements(By.xpath("//table[@id='table1']//tr")); 62 | System.out.println(allRowsWithHeader.size()); 63 | 64 | //number of rows without header(we prefer this) 65 | List allRowsWithoutHeader = driver.findElements(By.xpath("//table[@id='table1']/tbody/tr")); 66 | System.out.println(allRowsWithoutHeader.size()); 67 | } 68 | 69 | @Test 70 | public void getRow(){ 71 | //print the second row information 72 | WebElement row2 = driver.findElement(By.xpath("//table[@id='table1']/tbody/tr[2]")); 73 | 74 | //System.out.println(row2.getText()); 75 | 76 | //get all rows dynamically 77 | //1.find number of rows 78 | List numRows = driver.findElements(By.xpath("//table[@id='table1']/tbody/tr")); 79 | //2.iterate one by one 80 | for (int i = 1; i <= numRows.size(); i++) { 81 | WebElement row = driver.findElement(By.xpath("//table[@id='table1']/tbody/tr["+i+"]")); 82 | System.out.println(i+"-"+row.getText()); 83 | } 84 | 85 | //***loop shortcuts iter and itar 86 | 87 | } 88 | 89 | @Test 90 | public void getAllCellInOneRow(){ 91 | List allCellsInOneRow = driver.findElements(By.xpath("//table[@id='table1']/tbody/tr[3]/td")); 92 | 93 | for (WebElement element : allCellsInOneRow) { 94 | System.out.println(element.getText()); 95 | } 96 | } 97 | 98 | 99 | @Test 100 | public void getASingleCellByIndex(){ 101 | WebElement singleCell = driver.findElement(By.xpath("//table[@id='table1']/tbody/tr[3]/td[5]")); 102 | System.out.println("singleCell.getText() = " + singleCell.getText()); 103 | 104 | } 105 | 106 | @Test 107 | public void printAllCellsByIndex(){ 108 | 109 | int rowNumber = getNumberOfRows(); 110 | int colNumber = getNumberOfColumns(); 111 | 112 | System.out.println("colNumber = " + colNumber); 113 | System.out.println("rowNumber = " + rowNumber); 114 | 115 | //iterate through each row on the table 116 | for (int i = 1; i <= rowNumber; i++) { 117 | 118 | //iterate through each cell in the row 119 | for (int j = 1; j <= colNumber; j++) { 120 | 121 | String cellXpath = "//table[@id='table1']/tbody/tr["+i+"]/td["+j+"]"; 122 | System.out.println(cellXpath); 123 | 124 | WebElement cell = driver.findElement(By.xpath(cellXpath)); 125 | System.out.println(cell.getText()); 126 | 127 | } 128 | 129 | } 130 | 131 | } 132 | 133 | @Test 134 | public void getCellInRelationToAnotherCellInSameRow(){ 135 | 136 | String firstName="Jason"; 137 | 138 | String xpath ="//table[@id='table1']//td[.='"+firstName+"']/../td[3]"; 139 | WebElement email = driver.findElement(By.xpath(xpath)); 140 | System.out.println(email.getText()); 141 | 142 | 143 | } 144 | 145 | 146 | private int getNumberOfColumns() { 147 | List headers = driver.findElements(By.xpath("//table[@id='table1']//th")); 148 | return headers.size(); 149 | } 150 | 151 | private int getNumberOfRows() { 152 | List allRowsWithoutHeader = driver.findElements(By.xpath("//table[@id='table1']/tbody/tr")); 153 | return allRowsWithoutHeader.size(); 154 | } 155 | 156 | 157 | 158 | 159 | 160 | } 161 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day12_properties_driver_tests/AnotherLoginTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day12_properties_driver_tests; 2 | 3 | import com.cybertek.tests.TestBase; 4 | import com.cybertek.utilities.ConfigurationReader; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.Keys; 7 | import org.testng.annotations.Test; 8 | 9 | public class AnotherLoginTest extends TestBase { 10 | 11 | @Test 12 | public void test1(){ 13 | driver.get(ConfigurationReader.get("url")); 14 | 15 | String username = ConfigurationReader.get("driver_username"); 16 | String password = ConfigurationReader.get("driver_password"); 17 | 18 | driver.findElement(By.id("prependedInput")).sendKeys(username); 19 | driver.findElement(By.id("prependedInput2")).sendKeys(password+ Keys.ENTER); 20 | 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day12_properties_driver_tests/LoginTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day12_properties_driver_tests; 2 | 3 | import com.cybertek.tests.TestBase; 4 | import com.cybertek.utilities.ConfigurationReader; 5 | import org.openqa.selenium.By; 6 | import org.testng.annotations.Test; 7 | 8 | public class LoginTest extends TestBase { 9 | 10 | 11 | @Test 12 | public void OpenBrowserWithConf(){ 13 | 14 | driver.get(ConfigurationReader.get("url")); 15 | 16 | String username = ConfigurationReader.get("driver_username"); 17 | String password = ConfigurationReader.get("driver_password"); 18 | 19 | driver.findElement(By.id("prependedInput")).sendKeys(username); 20 | driver.findElement(By.id("prependedInput2")).sendKeys(password); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day12_properties_driver_tests/PropertiesTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day12_properties_driver_tests; 2 | 3 | import com.cybertek.utilities.ConfigurationReader; 4 | import com.cybertek.utilities.WebDriverFactory; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.Keys; 7 | import org.openqa.selenium.WebDriver; 8 | import org.testng.annotations.Test; 9 | 10 | public class PropertiesTest { 11 | 12 | @Test 13 | public void test1(){ 14 | 15 | String browserType = ConfigurationReader.get("browser"); 16 | 17 | System.out.println("browserType = " + browserType); 18 | System.out.println("Browser: "+ConfigurationReader.get("browser")); 19 | 20 | String url = ConfigurationReader.get("url"); 21 | 22 | System.out.println("url = " + url); 23 | 24 | 25 | } 26 | 27 | @Test 28 | public void OpenBrowserWithConf(){ 29 | 30 | WebDriver driver = WebDriverFactory.getDriver(ConfigurationReader.get("browser")); 31 | 32 | driver.get(ConfigurationReader.get("url")); 33 | 34 | String username = ConfigurationReader.get("driver_username"); 35 | String password = ConfigurationReader.get("driver_password"); 36 | 37 | driver.findElement(By.id("prependedInput")).sendKeys(username); 38 | driver.findElement(By.id("prependedInput2")).sendKeys(password+ Keys.TAB); 39 | 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day12_properties_driver_tests/Singleton.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day12_properties_driver_tests; 2 | 3 | public class Singleton { 4 | 5 | //singleton class will have private constructor 6 | //it means other classes cannot create object of this class 7 | private Singleton(){} 8 | 9 | private static String str; 10 | 11 | public static String getInstance(){ 12 | 13 | //if str has no value, initialize it and return it 14 | if(str==null){ 15 | System.out.println("str is null. assigning value it"); 16 | str="somevalue"; 17 | }else{ 18 | //if it has value just return it 19 | System.out.println("it has value, just returning it"); 20 | } 21 | 22 | return str; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day12_properties_driver_tests/SingletonTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day12_properties_driver_tests; 2 | 3 | import com.cybertek.utilities.Driver; 4 | import org.openqa.selenium.WebDriver; 5 | import org.testng.annotations.Test; 6 | 7 | public class SingletonTest { 8 | 9 | //@Test 10 | public void test1(){ 11 | String s1 = Singleton.getInstance(); 12 | String s2 = Singleton.getInstance(); 13 | 14 | System.out.println("s1 = " + s1); 15 | System.out.println("s2 = " + s2); 16 | } 17 | 18 | 19 | @Test 20 | public void test2() throws InterruptedException { 21 | WebDriver driver = Driver.get(); 22 | Thread.sleep(2000); 23 | driver.get("https://www.google.com"); 24 | 25 | } 26 | 27 | @Test 28 | public void test3(){ 29 | WebDriver driver = Driver.get(); 30 | 31 | driver.get("https://www.amazon.com"); 32 | 33 | 34 | Driver.get().get("https://www.amazon.com"); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day13_pom/NegativeLoginTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day13_pom; 2 | 3 | import com.cybertek.pages.LoginPage; 4 | import com.cybertek.tests.TestBase; 5 | import org.testng.Assert; 6 | import org.testng.annotations.Test; 7 | 8 | public class NegativeLoginTest extends TestBase { 9 | LoginPage loginPage = new LoginPage(); 10 | @Test 11 | public void wrongPasswordTest(){ 12 | 13 | // LoginPage loginPage = new LoginPage(); 14 | 15 | loginPage.usernameInput.sendKeys("user1"); 16 | loginPage.passwordInput.sendKeys("somepassword"); 17 | loginPage.loginBtn.click(); 18 | 19 | Assert.assertEquals(driver.getCurrentUrl(),"https://qa1.vytrack.com/user/login"); 20 | 21 | } 22 | 23 | @Test 24 | public void wrongUsernameTest(){ 25 | 26 | // LoginPage loginPage = new LoginPage(); 27 | 28 | loginPage.usernameInput.sendKeys("someusername"); 29 | loginPage.passwordInput.sendKeys("UserUser123"); 30 | loginPage.loginBtn.click(); 31 | 32 | Assert.assertEquals(driver.getCurrentUrl(),"https://qa1.vytrack.com/user/login"); 33 | 34 | } 35 | 36 | 37 | } -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day13_pom/PageSubtitleTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day13_pom; 2 | 3 | import com.cybertek.pages.CalendarEventsPage; 4 | import com.cybertek.pages.DashboardPage; 5 | import com.cybertek.pages.LoginPage; 6 | import com.cybertek.tests.TestBase; 7 | import com.cybertek.utilities.BrowserUtils; 8 | import org.testng.Assert; 9 | import org.testng.annotations.Test; 10 | 11 | public class PageSubtitleTest extends TestBase { 12 | 13 | /** 14 | * Test case 15 | * Open Chrome browser 16 | * Login as a Driver 17 | * Verify that page subtitle is Quick Launchpad 18 | * Go to Activities -> Calendar Events 19 | * verify that page subtitle is Calendar Events 20 | */ 21 | @Test 22 | public void test1(){ 23 | 24 | LoginPage loginPage = new LoginPage(); 25 | 26 | loginPage.loginAsDriver(); 27 | 28 | String expectedSubtitle = "Quick Launchpad"; 29 | 30 | DashboardPage dashboardPage = new DashboardPage(); 31 | 32 | String actualSubtitle = dashboardPage.getPageSubTitle(); 33 | 34 | Assert.assertEquals(actualSubtitle,expectedSubtitle,"Verify subtitle"); 35 | 36 | dashboardPage.navigateToModule("Activities","Calendar Events"); 37 | 38 | CalendarEventsPage calendarEventsPage = new CalendarEventsPage(); 39 | 40 | BrowserUtils.waitFor(2); 41 | 42 | Assert.assertEquals(calendarEventsPage.getPageSubTitle(),"Calendar Events","Verify subtitle Calendar Events"); 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day13_pom/PositiveLoginTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day13_pom; 2 | 3 | import com.cybertek.pages.LoginPage; 4 | import com.cybertek.tests.TestBase; 5 | import com.cybertek.utilities.ConfigurationReader; 6 | import org.testng.Assert; 7 | import org.testng.annotations.Test; 8 | 9 | public class PositiveLoginTest extends TestBase { 10 | 11 | 12 | @Test 13 | public void loginAsDriver(){ 14 | 15 | LoginPage loginPage = new LoginPage(); 16 | 17 | // String username = ConfigurationReader.get("driver_username"); 18 | // String password = ConfigurationReader.get("driver_password"); 19 | // 20 | // loginPage.usernameInput.sendKeys(username); 21 | // loginPage.passwordInput.sendKeys(password); 22 | // loginPage.loginBtn.click(); 23 | loginPage.loginAsDriver(); 24 | 25 | Assert.assertEquals(driver.getCurrentUrl(),"https://qa1.vytrack.com/"); 26 | 27 | 28 | } 29 | 30 | @Test 31 | public void loginAsStoreManager(){ 32 | 33 | LoginPage loginPage = new LoginPage(); 34 | 35 | String username = ConfigurationReader.get("storemanager_username"); 36 | String password = ConfigurationReader.get("storemanager_password"); 37 | loginPage.login(username,password); 38 | 39 | Assert.assertEquals(driver.getCurrentUrl(),"https://qa1.vytrack.com/"); 40 | 41 | 42 | } 43 | 44 | @Test 45 | public void loginAsStoreManager2(){ 46 | 47 | LoginPage loginPage = new LoginPage(); 48 | 49 | loginPage.loginAsStoreManager(); 50 | 51 | Assert.assertEquals(driver.getCurrentUrl(),"https://qa1.vytrack.com/"); 52 | 53 | 54 | } 55 | 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day13_pom/RepeatOptionsTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day13_pom; 2 | 3 | import com.cybertek.pages.CalendarEventsPage; 4 | import com.cybertek.pages.CreateCalendarEventsPage; 5 | import com.cybertek.pages.DashboardPage; 6 | import com.cybertek.pages.LoginPage; 7 | import com.cybertek.tests.TestBase; 8 | import com.cybertek.utilities.BrowserUtils; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.support.ui.Select; 11 | import org.testng.Assert; 12 | import org.testng.annotations.Test; 13 | 14 | import java.util.ArrayList; 15 | import java.util.Arrays; 16 | import java.util.List; 17 | 18 | public class RepeatOptionsTests extends TestBase { 19 | 20 | /*VERIFY RADIO BUTTONS 21 | Open Chrome browser 22 | Login as driver 23 | Go to Activities->Calendar Events 24 | Click on create calendar events 25 | Click on repeat 26 | Verify that repeat every days is checked 27 | verify that repeat weekday is not checked 28 | * */ 29 | //TASK UNTIL 12:45 30 | @Test 31 | public void test1(){ 32 | 33 | LoginPage loginPage = new LoginPage(); 34 | 35 | //Login as driver 36 | loginPage.loginAsDriver(); 37 | 38 | DashboardPage dashboardPage = new DashboardPage(); 39 | //Go to Activities->Calendar Events 40 | dashboardPage.navigateToModule("Activities","Calendar Events"); 41 | 42 | CalendarEventsPage calendarEventsPage = new CalendarEventsPage(); 43 | //Click on create calendar events 44 | //wait for loader mask 45 | calendarEventsPage.waitUntilLoaderScreenDisappear(); 46 | BrowserUtils.waitForClickablility(calendarEventsPage.createCalendarEvent,5); 47 | calendarEventsPage.createCalendarEvent.click(); 48 | 49 | CreateCalendarEventsPage createCalendarEventsPage = new CreateCalendarEventsPage(); 50 | // Click on repeat 51 | createCalendarEventsPage.repeat.click(); 52 | 53 | //Verify that repeat every days is checked 54 | Assert.assertTrue(createCalendarEventsPage.days.isSelected(),"Verify repeat days is selected"); 55 | //verify that repeat weekday is not checked 56 | Assert.assertFalse(createCalendarEventsPage.weekday.isSelected(),"Verify weekday is not selected"); 57 | 58 | } 59 | 60 | /* 61 | VERIFY REPEAT OPTIONS 62 | Open Chrome browser 63 | Login as driver 64 | Go to Activities->Calendar Events 65 | Click on create calendar events button 66 | Click on repeat checkbox 67 | Verify that repeat options are Daily, Weekly, Monthly,Yearly(in this order) 68 | */ 69 | 70 | @Test 71 | public void test2(){ 72 | 73 | LoginPage loginPage = new LoginPage(); 74 | 75 | //Login as driver 76 | loginPage.loginAsDriver(); 77 | 78 | DashboardPage dashboardPage = new DashboardPage(); 79 | //Go to Activities->Calendar Events 80 | dashboardPage.navigateToModule("Activities","Calendar Events"); 81 | 82 | CalendarEventsPage calendarEventsPage = new CalendarEventsPage(); 83 | //Click on create calendar events 84 | //wait for loader mask 85 | calendarEventsPage.waitUntilLoaderScreenDisappear(); 86 | BrowserUtils.waitForClickablility(calendarEventsPage.createCalendarEvent,5); 87 | calendarEventsPage.createCalendarEvent.click(); 88 | 89 | CreateCalendarEventsPage createCalendarEventsPage = new CreateCalendarEventsPage(); 90 | // Click on repeat 91 | createCalendarEventsPage.repeat.click(); 92 | 93 | Select repeatsDropdown = createCalendarEventsPage.repeatOptionsList(); 94 | 95 | // Verify that repeat options are Daily, Weekly, Monthly,Yearly(in this order) 96 | List expectedList = Arrays.asList("Daily","Weekly","Monthly","Yearly"); 97 | 98 | List actualList = new ArrayList<>(); 99 | 100 | List actualOptions = repeatsDropdown.getOptions(); 101 | for (WebElement option : actualOptions) { 102 | //get text of each element and add to actual List 103 | System.out.println(option.getText()); 104 | actualList.add(option.getText()); 105 | } 106 | System.out.println(actualList); 107 | //ready method for getting text of list of web elements 108 | List actualList2 = BrowserUtils.getElementsText(actualOptions); 109 | //Verify that repeat options are Daily, Weekly, Monthly,Yearly(in this order) 110 | Assert.assertEquals(actualList,expectedList,"Verify Daily weekly monthly yearly"); 111 | 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day14_extent_reports/ExtentDemoTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day14_extent_reports; 2 | 3 | import com.aventstack.extentreports.ExtentReports; 4 | import com.aventstack.extentreports.ExtentTest; 5 | import com.aventstack.extentreports.reporter.ExtentHtmlReporter; 6 | import com.cybertek.utilities.ConfigurationReader; 7 | import org.testng.annotations.AfterMethod; 8 | import org.testng.annotations.BeforeMethod; 9 | import org.testng.annotations.Test; 10 | 11 | public class ExtentDemoTest { 12 | 13 | //this class is used for starting nad building reports 14 | ExtentReports report; 15 | //this class is used to create HTML report file 16 | ExtentHtmlReporter htmlReporter; 17 | //this will define a test, enables adding logs, authors, test steps 18 | ExtentTest extentLogger; 19 | 20 | @BeforeMethod 21 | public void setup(){ 22 | //initialize the class 23 | report = new ExtentReports(); 24 | 25 | //create a report path 26 | String projectPath = System.getProperty("user.dir"); 27 | String path = projectPath + "/test-output/report.html"; 28 | 29 | //initialize the html reporter with the report path 30 | htmlReporter = new ExtentHtmlReporter(path); 31 | 32 | //attach the html report to report object 33 | report.attachReporter(htmlReporter); 34 | 35 | //title in report 36 | htmlReporter.config().setReportName("Vytrack Smoke Test"); 37 | 38 | //set environment information 39 | report.setSystemInfo("Environment","QA"); 40 | report.setSystemInfo("Browser", ConfigurationReader.get("browser")); 41 | report.setSystemInfo("OS",System.getProperty("os.name")); 42 | 43 | } 44 | 45 | @Test 46 | public void test1(){ 47 | //give name to current test 48 | extentLogger= report.createTest("TC123 Login as Driver Test"); 49 | 50 | //test steps 51 | extentLogger.info("Open Chrome Browser"); 52 | 53 | extentLogger.info("Go to this URL"); 54 | 55 | extentLogger.info("Enter driver username password"); 56 | 57 | extentLogger.info("Click Login"); 58 | 59 | extentLogger.info("Verify logged in"); 60 | 61 | //pass()--> marks the test case as passed 62 | extentLogger.pass("TC123 is passed"); 63 | 64 | } 65 | 66 | 67 | @AfterMethod 68 | public void teardown(){ 69 | //this is when the report is actually created 70 | report.flush(); 71 | 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day14_extent_reports/NegativeLoginTestWithReport.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day14_extent_reports; 2 | 3 | import com.cybertek.pages.LoginPage; 4 | import com.cybertek.tests.TestBase; 5 | import org.testng.Assert; 6 | import org.testng.annotations.Test; 7 | 8 | public class NegativeLoginTestWithReport extends TestBase { 9 | 10 | @Test 11 | public void wrongPasswordTest(){ 12 | //name of the test 13 | extentLogger = report.createTest("Wrong Password Test"); 14 | 15 | LoginPage loginPage = new LoginPage(); 16 | 17 | extentLogger.info("Enter Username: user1"); 18 | loginPage.usernameInput.sendKeys("user1"); 19 | 20 | extentLogger.info("Enter Password: somepassword"); 21 | loginPage.passwordInput.sendKeys("somepassword"); 22 | 23 | extentLogger.info("Click login Button"); 24 | loginPage.loginBtn.click(); 25 | 26 | extentLogger.info("Verify Page URL"); 27 | Assert.assertEquals(driver.getCurrentUrl(),"https://qa1.vytrack.com/user/login"); 28 | 29 | extentLogger.pass("Wrong Password Test is Passed"); 30 | 31 | } 32 | 33 | @Test 34 | public void wrongUsernameTest(){ 35 | //name of the test 36 | extentLogger = report.createTest("Wrong Username Test"); 37 | 38 | LoginPage loginPage = new LoginPage(); 39 | extentLogger.info("Enter username: someusername"); 40 | loginPage.usernameInput.sendKeys("someusername"); 41 | 42 | extentLogger.info("Enter password: UserUser123"); 43 | loginPage.passwordInput.sendKeys("UserUser123"); 44 | 45 | extentLogger.info("Click Login button"); 46 | loginPage.loginBtn.click(); 47 | 48 | extentLogger.info("verify page url"); 49 | Assert.assertEquals(driver.getCurrentUrl(),"https://qa1.vytrack.com/user/logi"); 50 | extentLogger.pass("PASSED"); 51 | } 52 | 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day15_review/verifyContactInfoTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day15_review; 2 | 3 | import com.cybertek.pages.ContactInfoPage; 4 | import com.cybertek.pages.ContactsPage; 5 | import com.cybertek.pages.DashboardPage; 6 | import com.cybertek.pages.LoginPage; 7 | import com.cybertek.tests.TestBase; 8 | import com.cybertek.utilities.ConfigurationReader; 9 | import org.testng.Assert; 10 | import org.testng.annotations.Test; 11 | 12 | public class verifyContactInfoTest extends TestBase { 13 | /** 14 | * open the chrome 15 | * go to qa1.vytrack 16 | * login as a sales manager 17 | * navigate to customers ->contacts 18 | * click on email mbrackstone9@example.com 19 | * verify that full name is Mariam Brackstone 20 | * verify that email is mbrackstone9@example.com 21 | * verify that phone number is +18982323434 22 | */ 23 | @Test 24 | public void contactDetailsTest(){ 25 | 26 | extentLogger = report.createTest("Contact Info Verification"); 27 | 28 | LoginPage loginPage = new LoginPage(); 29 | 30 | String username = ConfigurationReader.get("salesmanager_username"); 31 | String password = ConfigurationReader.get("salesmanager_password"); 32 | extentLogger.info("username: "+username); 33 | extentLogger.info("password: "+password); 34 | extentLogger.info("Login as a Sales Manager"); 35 | loginPage.login(username,password); 36 | 37 | extentLogger.info("Navigate to --> Customers > Contacts"); 38 | new DashboardPage().navigateToModule("Customers","Contacts"); 39 | 40 | ContactsPage contactsPage = new ContactsPage(); 41 | 42 | extentLogger.info("Click on mbrackstone9@example.com"); 43 | contactsPage.waitUntilLoaderScreenDisappear(); 44 | contactsPage.getContactEmail("mbrackstone9@example.com").click(); 45 | 46 | ContactInfoPage contactInfoPage = new ContactInfoPage(); 47 | 48 | String expectedFullName = "Mariam Brackstone"; 49 | String actualFullName = contactInfoPage.fullName.getText(); 50 | 51 | extentLogger.info("Verify full name is "+ expectedFullName); 52 | Assert.assertEquals(actualFullName,expectedFullName,"verify fullname"); 53 | 54 | extentLogger.info("verify email is mbrackstone9@example.com"); 55 | Assert.assertEquals(contactInfoPage.email.getText(),"mbrackstone9@example.com","Verify email"); 56 | 57 | extentLogger.info("verify phone number is +18982323434"); 58 | Assert.assertEquals(contactInfoPage.phone.getText(),"+18982323434","verify phone number"); 59 | 60 | extentLogger.pass("PASSED"); 61 | 62 | } 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day16_ddf/DDFLoginTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day16_ddf; 2 | 3 | import com.cybertek.pages.DashboardPage; 4 | import com.cybertek.pages.LoginPage; 5 | import com.cybertek.tests.TestBase; 6 | import com.cybertek.utilities.ExcelUtil; 7 | import org.testng.Assert; 8 | import org.testng.annotations.DataProvider; 9 | import org.testng.annotations.Test; 10 | 11 | public class DDFLoginTest extends TestBase { 12 | 13 | @DataProvider 14 | public Object [][] userData(){ 15 | 16 | ExcelUtil qa3short = new ExcelUtil("src/test/resources/Vytracktestdata.xlsx","QA3-all"); 17 | 18 | String [][] dataArray =qa3short.getDataArrayWithoutFirstRow(); 19 | 20 | return dataArray; 21 | } 22 | 23 | @Test(dataProvider = "userData") 24 | public void test1(String username,String password,String firstName,String lastName){ 25 | extentLogger=report.createTest("Test "+firstName+" "+lastName); 26 | LoginPage loginPage = new LoginPage(); 27 | 28 | loginPage.login(username,password); 29 | 30 | DashboardPage dashboardPage = new DashboardPage(); 31 | dashboardPage.waitUntilLoaderScreenDisappear(); 32 | 33 | String actualFullName = dashboardPage.getUserName(); 34 | String expectedFullName = firstName+" "+lastName; 35 | 36 | Assert.assertEquals(actualFullName,expectedFullName,"verify fullname"); 37 | extentLogger.pass("PASSED"); 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day16_ddf/DDFWithDataProvider.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day16_ddf; 2 | 3 | import org.testng.annotations.DataProvider; 4 | import org.testng.annotations.Test; 5 | 6 | public class DDFWithDataProvider { 7 | 8 | @DataProvider 9 | public Object [][] testData(){ 10 | String [][] data = {{"Person of Interest","10"}, {"Sherlock","9"}, {"Breaking Bad","9"}, {"The Office","8"}, 11 | {"Friends","7"}, 12 | {"Westworld","10"}, 13 | {"Gotham","9"}, 14 | {"Dark","8"} 15 | }; 16 | return data; 17 | } 18 | 19 | 20 | @Test(dataProvider ="testData") 21 | public void test1(String tvshow,String rating){ 22 | System.out.println("Tv show: "+tvshow +" has rating "+rating); 23 | 24 | } 25 | 26 | 27 | 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day16_ddf/ExcelUtilsDemo.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day16_ddf; 2 | 3 | import com.cybertek.utilities.ExcelUtil; 4 | import org.testng.annotations.Test; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class ExcelUtilsDemo { 11 | 12 | 13 | @Test 14 | public void readExcelFile(){ 15 | 16 | //Create an object from ExcelUtil 17 | //it accepts two argument 18 | //Argument 1: location of the file(path) 19 | //Argument 2: sheet that wew want to open(sheetName) 20 | 21 | ExcelUtil qa3short = new ExcelUtil("src/test/resources/Vytracktestdata.xlsx","QA3-short"); 22 | 23 | //how many rows in the sheet 24 | System.out.println("qa3short.rowCount() = " + qa3short.rowCount()); 25 | 26 | //how many columns in the sheet 27 | System.out.println("qa3short.columnCount() = " + qa3short.columnCount()); 28 | 29 | //get all column names 30 | System.out.println("qa3short.getColumnsNames() = " + qa3short.getColumnsNames()); 31 | 32 | //get all data in list of maps 33 | List> dataList = qa3short.getDataList(); 34 | for (Map onerow : dataList) { 35 | System.out.println(onerow); 36 | } 37 | 38 | //get Nona as a value 39 | System.out.println("dataList.get(2) = " + dataList.get(2).get("firstname")); 40 | 41 | //get Harber 42 | System.out.println("dataList.get(8) = " + dataList.get(8).get("lastname")); 43 | 44 | //get all data in 2d array 45 | String [][] dataArray = qa3short.getDataArray(); 46 | 47 | //print 2d array 48 | System.out.println(Arrays.deepToString(dataArray)); 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day1_intro/OpenBrowser.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day1_intro; 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 OpenBrowser { 8 | 9 | public static void main(String[] args) { 10 | // //we have to enter this line every time we want to open chrome 11 | // //hey webdrivermanager, can you make chrome ready for me for automation 12 | // WebDriverManager.chromedriver().setup(); 13 | // 14 | // //WebDriver represent the browser 15 | // //we are creating driver for chrome browser 16 | // //new ChromeDriver() --> this part will open chrome browser 17 | // WebDriver driver = new ChromeDriver(); 18 | // 19 | // //.get(url) method used for navigation to page 20 | // driver.get("https://cybertekschool.com"); 21 | // 22 | // //this line will allow selenium to automate firefox browser 23 | 24 | WebDriverManager.chromedriver().setup(); 25 | 26 | WebDriver driver = new ChromeDriver(); 27 | 28 | driver.get("https://www.facebook.com"); 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day2_webdriver_basics/CallWebDriverFactory.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day2_webdriver_basics; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.WebDriver; 5 | 6 | public class CallWebDriverFactory { 7 | 8 | public static void main(String[] args) { 9 | 10 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 11 | 12 | driver.get("https://www.google.com"); 13 | 14 | String title = driver.getTitle(); 15 | 16 | System.out.println("title = " + title); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day2_webdriver_basics/CloseAndQuit.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day2_webdriver_basics; 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 CloseAndQuit { 8 | 9 | public static void main(String[] args) throws InterruptedException { 10 | 11 | WebDriverManager.chromedriver().setup(); 12 | 13 | WebDriver driver = new ChromeDriver(); 14 | 15 | driver.get("http://practice.cybertekschool.com"); 16 | 17 | Thread.sleep(2000); 18 | 19 | //close current tab 20 | driver.close(); 21 | 22 | driver = new ChromeDriver(); 23 | 24 | driver.get("http://practice.cybertekschool.com/open_new_tab"); 25 | 26 | Thread.sleep(5000); 27 | 28 | //closes all tabs 29 | driver.quit(); 30 | 31 | 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day2_webdriver_basics/GetTitleAndUrl.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day2_webdriver_basics; 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 GetTitleAndUrl { 8 | 9 | public static void main(String[] args) { 10 | 11 | //Task open chrome and navigate to http://practice.cybertekschool.com 12 | WebDriverManager.chromedriver().setup(); 13 | 14 | WebDriver driver = new ChromeDriver(); 15 | 16 | driver.get("http://practice.cybertekschool.com"); 17 | 18 | //getting title with selenium 19 | //shortcut for creating variable 20 | //Option or ALT +enter enter 21 | //getTitle()-->get you the tiel of the page 22 | String title = driver.getTitle(); 23 | 24 | //soutv +enter to print variable name and value 25 | System.out.println("title = " + title); 26 | 27 | //getCurrentUrl --> get the url from browser 28 | String currentUrl = driver.getCurrentUrl(); 29 | System.out.println("currentUrl = " + currentUrl); 30 | 31 | //getPageSource()--> gets the source of the page 32 | String pageSource = driver.getPageSource(); 33 | System.out.println("pageSource = " + pageSource); 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day2_webdriver_basics/NavigationDemo.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day2_webdriver_basics; 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 NavigationDemo { 8 | 9 | public static void main(String[] args) throws InterruptedException { 10 | 11 | WebDriverManager.chromedriver().setup(); 12 | 13 | WebDriver driver = new ChromeDriver(); 14 | 15 | driver.get("https://www.google.com"); 16 | 17 | Thread.sleep(2000); 18 | 19 | //navigate to another website with different selenium method 20 | driver.navigate().to("https://www.facebook.com"); 21 | 22 | //wait 3 second here then move on 23 | Thread.sleep(3000); 24 | 25 | 26 | //goes back to previous page 27 | driver.navigate().back(); 28 | 29 | Thread.sleep(2000); 30 | 31 | //goes forward after goes back 32 | driver.navigate().forward(); 33 | 34 | //refresh to webpage 35 | driver.navigate().refresh(); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day3_webelement_intro/verifyConfirmationMessage.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day3_webelement_intro; 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 verifyConfirmationMessage { 9 | 10 | public static void main(String[] args) { 11 | /* 12 | Verify confirmation message 13 | open chrome browser 14 | go to http://practice.cybertekschool.com/forgot_password Links to an external site. 15 | enter any email 16 | verify that email is displayed in the input box 17 | click on Retrieve password 18 | verify that confirmation message says 'Your e-mail's been sent!' 19 | */ 20 | 21 | //open chrome browser 22 | WebDriver driver = WebDriverFactory.getDriver("cHromE"); 23 | 24 | //go to http://practice.cybertekschool.com/forgot_password 25 | driver.get("http://practice.cybertekschool.com/forgot_password"); 26 | 27 | //enter any email 28 | WebElement emailInputBox = driver.findElement(By.name("email")); 29 | 30 | String expectedEmail = "mike@smith.com"; 31 | 32 | //sendKeys()--> send keyboard action to the webelement 33 | emailInputBox.sendKeys(expectedEmail); 34 | 35 | 36 | //somehow we should get text from web elements 37 | //two main ways to get txt from web elements 38 | //1.getText()--> it will work %99 and it will return string 39 | //2.getAttribute("value") --> second way of getting text especially input boxes 40 | 41 | String actualEmail = emailInputBox.getAttribute("value"); 42 | System.out.println("actualEmail = " + actualEmail); 43 | 44 | //verify that email is displayed in the input box 45 | if(expectedEmail.equals(actualEmail)){ 46 | System.out.println("PASS"); 47 | }else{ 48 | System.out.println("FAIL"); 49 | } 50 | 51 | //click on retrieve password 52 | WebElement retrievePasswordButton = driver.findElement(By.id("form_submit")); 53 | retrievePasswordButton.click(); 54 | 55 | //verify that confirmation message says 'Your e-mail's been sent!' 56 | WebElement actualConfirmationMessage = driver.findElement(By.name("confirmation_message")); 57 | 58 | System.out.println(actualConfirmationMessage.getText()); 59 | //save expected message 60 | String expectedMessage = "Your e-mail's been sent!"; 61 | //save actual message to variable 62 | String actualMessage = actualConfirmationMessage.getText(); 63 | 64 | if(expectedMessage.equals(actualMessage)){ 65 | System.out.println("PASS"); 66 | }else{ 67 | System.out.println("FAIL"); 68 | System.out.println("expectedMessage = " + expectedMessage); 69 | System.out.println("actualMessage = " + actualMessage); 70 | } 71 | 72 | //close browser 73 | driver.quit(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day3_webelement_intro/verifyURLchanged.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day3_webelement_intro; 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 verifyURLchanged { 9 | 10 | 11 | 12 | public static void main(String[] args) { 13 | /* Verify URL changed 14 | open chrome browser 15 | go to http://practice.cybertekschool.com/forgot_password Links to an external site. 16 | enter any email 17 | click on Retrieve password 18 | verify that url changed to http://practice.cybertekschool.com/email_sent 19 | */ 20 | 21 | //open chrome browser 22 | WebDriver driver = WebDriverFactory.getDriver("cHromE"); 23 | 24 | //go to http://practice.cybertekschool.com/forgot_password 25 | driver.get("http://practice.cybertekschool.com/forgot_password"); 26 | 27 | //enter any email 28 | WebElement emailInputBox = driver.findElement(By.name("email")); 29 | 30 | //sendKeys()--> send keyboard action to the webelement 31 | emailInputBox.sendKeys("mike@smith.com"); 32 | 33 | //click retrieve password button 34 | WebElement retrievePasswordButton = driver.findElement(By.id("form_submit")); 35 | retrievePasswordButton.click(); 36 | 37 | //verify that url changed to http://practice.cybertekschool.com/email_sent 38 | //create expectedUrl 39 | String expectedUrl ="http://practice.cybertekschool.com/email_sent"; 40 | 41 | //saving actual url from browser after we enter any email and click retrieve password button 42 | String actualUrl = driver.getCurrentUrl(); 43 | 44 | if(expectedUrl.equals(actualUrl)){ 45 | System.out.println("PASS"); 46 | }else{ 47 | System.out.println("FAIL"); 48 | System.out.println("expectedUrl = " + expectedUrl); 49 | System.out.println("actualUrl = " + actualUrl); 50 | } 51 | 52 | //close browser 53 | driver.quit(); 54 | 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day3_webelement_intro/verifyURLnotChanged.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day3_webelement_intro; 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 verifyURLnotChanged { 9 | 10 | public static void main(String[] args) { 11 | /*Verify URL not changed 12 | -open chrome browser 13 | -go to http://practice.cybertekschool.com/forgot_password Links to an external site. 14 | -click on Retrieve password 15 | -verify that url did not change 16 | */ 17 | 18 | //open chrome browser 19 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 20 | 21 | //go to http://practice.cybertekschool.com/forgot_password 22 | driver.get("http://practice.cybertekschool.com/forgot_password"); 23 | 24 | //save expected url before clicking button 25 | String expectedUrl = driver.getCurrentUrl(); 26 | 27 | //click on Retrieve password 28 | //WebElement --> Interface that represent elements on the webpage 29 | //findElement --> method used to find element on a page 30 | WebElement retrievePasswordButton = driver.findElement(By.id("form_submit")); 31 | retrievePasswordButton.click(); 32 | 33 | //save actual url after clicking button 34 | String actualUrl = driver.getCurrentUrl(); 35 | 36 | //verify that url did not change 37 | if(expectedUrl.equals(actualUrl)){ 38 | System.out.println("PASS"); 39 | }else{ 40 | System.out.println("FAIL"); 41 | } 42 | 43 | //close your browser 44 | driver.quit(); 45 | 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day4_basic_locators/IDLocatorTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day4_basic_locators; 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 IDLocatorTest { 9 | 10 | public static void main(String[] args) { 11 | 12 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 13 | 14 | driver.get("http://practice.cybertekschool.com/multiple_buttons"); 15 | 16 | //click don't click button 17 | WebElement dontClickButton = driver.findElement(By.id("disappearing_button")); 18 | 19 | dontClickButton.click(); 20 | 21 | driver.quit(); 22 | 23 | 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day4_basic_locators/classNameTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day4_basic_locators; 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 classNameTest { 9 | 10 | public static void main(String[] args) { 11 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 12 | driver.get("http://practice.cybertekschool.com/sign_up"); 13 | 14 | WebElement homeLink = driver.findElement(By.className("nav-link")); 15 | homeLink.click(); 16 | 17 | driver.get("http://practice.cybertekschool.com/multiple_buttons"); 18 | 19 | //print multiple buttons header 20 | System.out.println(driver.findElement(By.className("h3")).getText()); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day4_basic_locators/linkTextandPartialLinkText.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day4_basic_locators; 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 linkTextandPartialLinkText { 9 | 10 | public static void main(String[] args) { 11 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 12 | 13 | driver.get("http://practice.cybertekschool.com/dynamic_loading"); 14 | 15 | WebElement link1 = driver.findElement(By.linkText("Example 1: Element on page that is hidden and become visible after trigger")); 16 | // link1.click(); 17 | 18 | WebElement link4 = driver.findElement(By.partialLinkText("Example 4 ")); 19 | 20 | link4.click(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day4_basic_locators/nameLocatorTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day4_basic_locators; 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 nameLocatorTest { 9 | public static void main(String[] args) { 10 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 11 | 12 | //make browser fullscreen 13 | driver.manage().window().maximize(); 14 | 15 | driver.get("http://practice2.cybertekschool.com/sign_up"); 16 | 17 | WebElement fullNameInput = driver.findElement(By.name("full_name")); 18 | fullNameInput.sendKeys("Mike Smith"); 19 | 20 | //task 21 | //put some email and click sign up button 22 | 23 | //proper way 24 | //WebElement emailInput = driver.findElement(By.name("email")); 25 | // emailInput.sendKeys("mike@smith.com"); 26 | 27 | //lazy way 28 | driver.findElement(By.name("email")).sendKeys("mike@smith.com"); 29 | 30 | //WebElement signUpButton = driver.findElement(By.name("wooden_spoon")); 31 | // signUpButton.click(); 32 | 33 | //lazy way 34 | driver.findElement(By.name("wooden_spoon")).click(); 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day4_basic_locators/tagNameLocator.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day4_basic_locators; 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 tagNameLocator { 9 | 10 | public static void main(String[] args) throws InterruptedException { 11 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 12 | //maximize the window 13 | driver.manage().window().maximize(); 14 | driver.get("http://practice.cybertekschool.com/sign_up"); 15 | //send keys to fullname 16 | WebElement fullNameInput = driver.findElement(By.tagName("input")); 17 | fullNameInput.sendKeys("Mike Smith With TagName"); 18 | //sendkeys to email 19 | WebElement emailInput = driver.findElement(By.name("email")); 20 | emailInput.sendKeys("mike@smith.com"); 21 | 22 | //lazy way to click button 23 | driver.findElement(By.tagName("button")).click(); 24 | 25 | Thread.sleep(3000); 26 | 27 | 28 | //close browser 29 | driver.quit(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day5_xpath/AmazonTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day5_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 AmazonTest { 9 | 10 | /** 11 | * TASK 12 | * go to amazon.com 13 | * search for selenium 14 | * click search button 15 | * verify 1-48 of 304 results for "Java" 16 | * 17 | */ 18 | 19 | public static void main(String[] args) { 20 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 21 | 22 | driver.get("https://www.amazon.com"); 23 | 24 | WebElement searchBox = driver.findElement(By.xpath("//input[@id='twotabsearchtextbox']")); 25 | 26 | searchBox.sendKeys("Java"); 27 | 28 | //click search button 29 | driver.findElement(By.xpath("//input[@value='Go']")).click(); 30 | 31 | WebElement result = driver.findElement(By.xpath("//span[contains(text(),'results for')]")); 32 | 33 | String resultText = result.getText(); 34 | 35 | System.out.println("resultText = " + resultText); 36 | 37 | String expectedResult = "1-48 of over 5,000 results for"; 38 | 39 | if(expectedResult.equals(resultText)){ 40 | System.out.println("PASS"); 41 | }else{ 42 | System.out.println("FAIL"); 43 | System.out.println("expectedResult = " + expectedResult); 44 | System.out.println("resultText = " + resultText); 45 | } 46 | 47 | driver.quit(); 48 | 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day5_xpath/xPathLocator.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day5_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 xPathLocator { 9 | 10 | public static void main(String[] args) throws InterruptedException { 11 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 12 | 13 | driver.get("http://practice.cybertekschool.com/multiple_buttons"); 14 | 15 | WebElement button2 = driver.findElement(By.xpath("//button[@name='button2']")); 16 | 17 | button2.click(); 18 | 19 | Thread.sleep(2000); 20 | 21 | driver.quit(); 22 | 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day6_css/cssLocator.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 cssLocator { 9 | 10 | public static void main(String[] args) { 11 | 12 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 13 | 14 | driver.get("http://practice.cybertekschool.com/multiple_buttons"); 15 | 16 | WebElement dontClick = driver.findElement(By.id("disappearing_buttonasdasd")); 17 | 18 | System.out.println(dontClick.getText()); 19 | 20 | driver.quit(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day7_testng/BeforeAfterMethod.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day7_testng; 2 | 3 | import org.testng.annotations.*; 4 | 5 | public class BeforeAfterMethod { 6 | 7 | @BeforeClass 8 | public void setUpClass(){ 9 | System.out.println("--BEFORE CLASS--"); 10 | System.out.println("executed one time before the class"); 11 | } 12 | 13 | @Test 14 | public void test1(){ 15 | 16 | System.out.println("First Test Case"); 17 | } 18 | 19 | @Ignore 20 | @Test 21 | public void test2(){ 22 | System.out.println("Second Test Case"); 23 | } 24 | 25 | @Test 26 | public void test3(){ 27 | System.out.println("Third Test Case"); 28 | } 29 | 30 | @BeforeMethod 31 | public void setUp(){ 32 | System.out.println("BEFORE METHOD"); 33 | System.out.println("WebDriver,Opening Browser"); 34 | } 35 | 36 | @AfterMethod 37 | public void tearDown(){ 38 | System.out.println("AFTER METHOD"); 39 | System.out.println("Closing Browser,Quit"); 40 | } 41 | 42 | @AfterClass 43 | public void tearDownClass(){ 44 | System.out.println("--AFTER CLASS--"); 45 | System.out.println("Some Reporting Code Here"); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day7_testng/FirstTestNGTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day7_testng; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | public class FirstTestNGTest { 6 | 7 | 8 | @Test 9 | public void test1(){ 10 | 11 | System.out.println("My First Test Case"); 12 | } 13 | 14 | @Test 15 | public void test2(){ 16 | System.out.println("My Second Test Case"); 17 | } 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day7_testng/TestNGAssertionsDemo.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day7_testng; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.AfterMethod; 5 | import org.testng.annotations.BeforeMethod; 6 | import org.testng.annotations.Test; 7 | 8 | public class TestNGAssertionsDemo { 9 | 10 | @BeforeMethod 11 | public void setUp(){ 12 | System.out.println("Open Browser"); 13 | 14 | } 15 | @Test 16 | public void test1(){ 17 | 18 | 19 | System.out.println("First Assertion"); 20 | Assert.assertEquals("title","tiTle"); 21 | 22 | System.out.println("Second Assertion"); 23 | Assert.assertEquals("url","url"); 24 | 25 | 26 | } 27 | 28 | @Test 29 | public void test2(){ 30 | Assert.assertEquals("test2","test22","verify test2"); 31 | } 32 | 33 | @Test 34 | public void test3(){ 35 | String expectedTitle ="Cyb"; 36 | String actualTitle = "Cybertek"; 37 | 38 | Assert.assertTrue(actualTitle.startsWith(expectedTitle),"Verify title starts with Cyb"); 39 | 40 | } 41 | 42 | @Test 43 | public void test4(){ 44 | //verify email contains @ sign 45 | String email = "mikesmith.com"; 46 | 47 | Assert.assertTrue(email.contains("@"),"verify email contains @"); 48 | 49 | } 50 | 51 | @Test 52 | public void test5(){ 53 | Assert.assertFalse(0>1,"verify that 0 is not greater than 1"); 54 | 55 | } 56 | 57 | @Test 58 | public void test6(){ 59 | Assert.assertNotEquals("one","two"); 60 | } 61 | 62 | 63 | 64 | @AfterMethod 65 | public void tearDown(){ 66 | System.out.println("Close browser"); 67 | } 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day7_types_of_elements/AttributeTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day7_types_of_elements; 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.Test; 9 | 10 | public class AttributeTest { 11 | 12 | @Test 13 | public void test1(){ 14 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 15 | driver.manage().window().maximize(); 16 | 17 | driver.get("http://practice.cybertekschool.com/radio_buttons"); 18 | 19 | WebElement blueRadioBtn = driver.findElement(By.id("blue")); 20 | 21 | blueRadioBtn.getAttribute("value"); 22 | 23 | //get the value of type attribute 24 | System.out.println(blueRadioBtn.getAttribute("type")); 25 | //get the value of name attribute 26 | System.out.println(blueRadioBtn.getAttribute("name")); 27 | //get the value of checked 28 | //since checked attribute does not keep any value, it will return true or false based on the condition 29 | System.out.println(blueRadioBtn.getAttribute("checked")); 30 | 31 | //trying to get attribute that does not exist 32 | //when we use non exist attribute it will return null to us. 33 | System.out.println(blueRadioBtn.getAttribute("href")); 34 | 35 | System.out.println(blueRadioBtn.getAttribute("outerHTML")); 36 | 37 | driver.get("http://practice.cybertekschool.com/multiple_buttons"); 38 | 39 | WebElement button2 = driver.findElement(By.name("button2")); 40 | 41 | System.out.println(button2.getAttribute("outerHTML")); 42 | String outerHTML = button2.getAttribute("outerHTML"); 43 | Assert.assertTrue(outerHTML.contains("Button 2")); 44 | 45 | System.out.println("Inner HTML: "+button2.getAttribute("innerHTML")); 46 | 47 | driver.quit(); 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day7_types_of_elements/CheckboxDemo.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day7_types_of_elements; 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.Test; 9 | 10 | public class CheckboxDemo { 11 | 12 | 13 | @Test 14 | public void test1() throws InterruptedException { 15 | WebDriver driver = WebDriverFactory.getDriver("Chrome"); 16 | driver.get("http://practice.cybertekschool.com/checkboxes"); 17 | 18 | WebElement checkbox1 = driver.findElement(By.xpath("//input[1]")); 19 | WebElement checkbox2 = driver.findElement(By.xpath("//input[2]")); 20 | 21 | //How to verify checkbox is selected or not ? 22 | System.out.println("checkbox1.isSelected() = " + checkbox1.isSelected()); 23 | System.out.println("checkbox2.isSelected() = " + checkbox2.isSelected()); 24 | //verify checkbox 1 is not selected, 2 is selected 25 | Assert.assertFalse(checkbox1.isSelected(),"verify checkbox 1 is NOT selected"); 26 | Assert.assertTrue(checkbox2.isSelected(),"verify checkbox 2 is selected"); 27 | 28 | //how to check checkboxes? 29 | //just like a radio button we use click() method 30 | Thread.sleep(2000); 31 | checkbox1.click(); 32 | 33 | //verify after click 34 | Assert.assertTrue(checkbox1.isSelected(),"verify checkbox 1 is selected"); 35 | Assert.assertTrue(checkbox2.isSelected(),"verify checkbox 2 is selected"); 36 | 37 | Thread.sleep(2000); 38 | driver.quit(); 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day7_types_of_elements/DisabledElements.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day7_types_of_elements; 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.Test; 9 | 10 | public class DisabledElements { 11 | 12 | @Test 13 | public void test1(){ 14 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 15 | driver.manage().window().maximize(); 16 | 17 | driver.get("http://practice.cybertekschool.com/radio_buttons"); 18 | 19 | WebElement greenRadioBtn = driver.findElement(By.id("green")); 20 | 21 | //how to check any web element is enabled or not ? 22 | System.out.println("greenRadioBtn.isEnabled() = " + greenRadioBtn.isEnabled()); 23 | Assert.assertFalse(greenRadioBtn.isEnabled(),"verify green radio button NOT enabled (disabled)"); 24 | 25 | greenRadioBtn.click(); 26 | 27 | } 28 | 29 | @Test 30 | public void test2(){ 31 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 32 | driver.manage().window().maximize(); 33 | 34 | driver.get("http://practice.cybertekschool.com/dynamic_controls"); 35 | 36 | WebElement inputBox = driver.findElement(By.cssSelector("#input-example>input")); 37 | 38 | inputBox.sendKeys("some message"); 39 | 40 | 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day7_types_of_elements/DisplayedDemo.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day7_types_of_elements; 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.Test; 9 | 10 | public class DisplayedDemo { 11 | 12 | @Test 13 | public void test1() throws InterruptedException { 14 | 15 | 16 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 17 | 18 | driver.get("http://practice.cybertekschool.com/dynamic_loading/1"); 19 | 20 | WebElement usernameInput = driver.findElement(By.id("username")); 21 | 22 | System.out.println("usernameInput.isDisplayed() = " + usernameInput.isDisplayed()); 23 | 24 | //TASK 25 | //verify username inputbox is not displayed on the screen 26 | Assert.assertFalse(usernameInput.isDisplayed(),"verify inputbox is NOT displayed"); 27 | //click start button 28 | //find start button and click 29 | driver.findElement(By.cssSelector("#start>button")).click(); 30 | //wait until elements displayed 31 | Thread.sleep(6000); 32 | //verify username displayed on the screen 33 | Assert.assertTrue(usernameInput.isDisplayed(),"verify username inputbox is displayed"); 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day7_types_of_elements/RadioButtonTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day7_types_of_elements; 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.Test; 9 | 10 | public class RadioButtonTest { 11 | 12 | 13 | @Test 14 | public void test1() throws InterruptedException { 15 | 16 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 17 | driver.manage().window().maximize(); 18 | 19 | driver.get("http://practice.cybertekschool.com/radio_buttons"); 20 | 21 | //locating radio buttons 22 | WebElement blueRadioBtn = driver.findElement(By.cssSelector("#blue")); 23 | WebElement redRadioBtn = driver.findElement(By.id("red")); 24 | 25 | //how to check radio button is selected ? 26 | System.out.println("blueRadioBtn.isSelected() = " + blueRadioBtn.isSelected()); 27 | System.out.println("redRadioBtn.isSelected() = " + redRadioBtn.isSelected()); 28 | 29 | 30 | //verify blue is selected red is not selected 31 | //blue --> true 32 | Assert.assertTrue(blueRadioBtn.isSelected(),"verify that blue is selected"); 33 | //red-->false 34 | Assert.assertFalse(redRadioBtn.isSelected(),"verify that red is NOT selected"); 35 | 36 | //how to click radio button ? 37 | //clicking red radio button 38 | redRadioBtn.click(); 39 | 40 | //blue --> false 41 | Assert.assertFalse(blueRadioBtn.isSelected(),"verify that blue is NOT selected"); 42 | //red-->true 43 | Assert.assertTrue(redRadioBtn.isSelected(),"verify that red is selected"); 44 | 45 | 46 | Thread.sleep(2000); 47 | driver.quit(); 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day8_types_of_elements_2/ListOfElements.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day8_types_of_elements_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 | 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.List; 13 | 14 | public class ListOfElements { 15 | 16 | WebDriver driver; 17 | 18 | @BeforeMethod 19 | public void setUp(){ 20 | driver = WebDriverFactory.getDriver("chrome"); 21 | } 22 | 23 | @AfterMethod 24 | public void tearDown() throws InterruptedException { 25 | Thread.sleep(2000); 26 | driver.quit(); 27 | } 28 | 29 | @Test 30 | public void test1(){ 31 | driver.get("http://practice.cybertekschool.com/multiple_buttons"); 32 | 33 | //save our web elements inside the list 34 | List buttons = driver.findElements(By.tagName("button")); 35 | 36 | System.out.println("buttons.size() = " + buttons.size()); 37 | //verify button size 38 | Assert.assertEquals(buttons.size(),6,"verify buttons size"); 39 | 40 | //iter + enter to get each loop with shortcut 41 | for (WebElement button : buttons) { 42 | System.out.println("button.isDisplayed() = " + button.isDisplayed()); 43 | Assert.assertTrue(button.isDisplayed(),"verify buttons are displayed"); 44 | } 45 | 46 | //click second button 47 | buttons.get(1).click(); 48 | 49 | } 50 | 51 | @Test 52 | public void test2(){ 53 | driver.get("http://practice.cybertekschool.com/multiple_buttons"); 54 | 55 | //regular findElement method will throw NSE if locator does not exist 56 | //driver.findElement(By.tagName("buttonaiysdgausda")); 57 | 58 | //passing locator which does not exist, it will not throw NoSuchElement 59 | //ALT+enter or OPTION+Enter then one more enter for the shortcut 60 | List buttons = driver.findElements(By.tagName("buttonaiysdgausda")); 61 | 62 | System.out.println("buttons.size() = " + buttons.size()); 63 | 64 | 65 | } 66 | 67 | 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day8_types_of_elements_2/NoSelectDropdown.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day8_types_of_elements_2; 2 | 3 | 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.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 | 15 | public class NoSelectDropdown { 16 | 17 | WebDriver driver; 18 | 19 | @BeforeMethod 20 | public void setUp(){ 21 | driver = WebDriverFactory.getDriver("chrome"); 22 | } 23 | 24 | @AfterMethod 25 | public void tearDown() throws InterruptedException { 26 | Thread.sleep(2000); 27 | driver.quit(); 28 | } 29 | 30 | @Test 31 | public void test1(){ 32 | driver.get("http://practice.cybertekschool.com/dropdown"); 33 | 34 | WebElement dropdownElement = driver.findElement(By.id("dropdownMenuLink")); 35 | 36 | 37 | //click the dropdown to see available options 38 | dropdownElement.click(); 39 | //get the options with findElements method and finding common locator between them 40 | List dropdownOptions = driver.findElements(By.className("dropdown-item")); 41 | 42 | //print size of options 43 | System.out.println("dropdownOptions.size() = " + dropdownOptions.size()); 44 | Assert.assertEquals(dropdownOptions.size(),5,"verify size of options"); 45 | 46 | //print them one by one 47 | for (WebElement option : dropdownOptions) { 48 | System.out.println(option.getText()); 49 | } 50 | 51 | //click yahoo 52 | dropdownOptions.get(2).click(); 53 | 54 | } 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day8_types_of_elements_2/SelectDropdownTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day8_types_of_elements_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 | 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.util.List; 14 | 15 | public class SelectDropdownTest { 16 | 17 | WebDriver driver; 18 | 19 | @BeforeMethod 20 | public void setUp(){ 21 | driver = WebDriverFactory.getDriver("chrome"); 22 | } 23 | 24 | @AfterMethod 25 | public void tearDown() throws InterruptedException { 26 | Thread.sleep(2000); 27 | driver.quit(); 28 | } 29 | 30 | @Test 31 | public void test1(){ 32 | driver.get("http://practice.cybertekschool.com/dropdown"); 33 | //1.locate your dropdown just like any other webelement with unique locator 34 | WebElement dropdownElement = driver.findElement(By.id("state")); 35 | 36 | //2.create Select object by passing that element as a constructor 37 | Select stateDropdown = new Select(dropdownElement); 38 | 39 | //getOptions --> returns all the available options from the dropdown 40 | List options = stateDropdown.getOptions(); 41 | //print size of the options 42 | System.out.println("options.size() = " + options.size()); 43 | 44 | //print options one by one 45 | for (WebElement option : options) { 46 | System.out.println(option.getText()); 47 | } 48 | 49 | } 50 | 51 | 52 | @Test 53 | public void test2() throws InterruptedException { 54 | driver.get("http://practice.cybertekschool.com/dropdown"); 55 | //1.locate your dropdown just like any other webelement with unique locator 56 | WebElement dropdownElement = driver.findElement(By.id("state")); 57 | 58 | //2.create Select object by passing that element as a constructor 59 | Select stateDropdown = new Select(dropdownElement); 60 | 61 | //verify that first selection is Select a state 62 | String expectedOption = "Select a State"; 63 | String actualOption = stateDropdown.getFirstSelectedOption().getText(); 64 | Assert.assertEquals(actualOption,expectedOption,"verify first selection"); 65 | 66 | //HOW TO SELECT OPTIONS FROM DROPDOWN ? 67 | //1.SELECT USING VISIBLE TEXT 68 | Thread.sleep(2000); 69 | stateDropdown.selectByVisibleText("Virginia"); 70 | 71 | expectedOption = "Virginia"; 72 | actualOption = stateDropdown.getFirstSelectedOption().getText(); 73 | Assert.assertEquals(actualOption,expectedOption,"verify first selection"); 74 | 75 | //2.SELECT USING INDEX 76 | Thread.sleep(2000); 77 | stateDropdown.selectByIndex(51); 78 | 79 | expectedOption = "Wyoming"; 80 | actualOption = stateDropdown.getFirstSelectedOption().getText(); 81 | Assert.assertEquals(actualOption,expectedOption,"verify first selection"); 82 | 83 | //3.SELECT BY VALUE 84 | Thread.sleep(2000); 85 | stateDropdown.selectByValue("TX"); 86 | 87 | expectedOption = "Texas"; 88 | actualOption = stateDropdown.getFirstSelectedOption().getText(); 89 | Assert.assertEquals(actualOption,expectedOption,"verify first selection"); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day9_popups_tabs_frames/MultipleWindows.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day9_popups_tabs_frames; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.testng.annotations.AfterMethod; 7 | import org.testng.annotations.BeforeMethod; 8 | import org.testng.annotations.Test; 9 | 10 | import java.util.Set; 11 | 12 | public class MultipleWindows { 13 | 14 | 15 | WebDriver driver; 16 | 17 | @BeforeMethod 18 | public void setUp(){ 19 | driver = WebDriverFactory.getDriver("chrome"); 20 | } 21 | 22 | @AfterMethod 23 | public void tearDown() throws InterruptedException { 24 | Thread.sleep(2000); 25 | driver.quit(); 26 | } 27 | 28 | @Test 29 | public void SwitchWindowsTest(){ 30 | 31 | driver.get("http://practice.cybertekschool.com/windows"); 32 | 33 | //get title 34 | System.out.println("Title before new window:"+driver.getTitle()); 35 | 36 | driver.findElement(By.linkText("Click Here")).click(); 37 | 38 | System.out.println("Title after new window:"+driver.getTitle()); 39 | 40 | // System.out.println("driver.getWindowHandle() = " + driver.getWindowHandle()); 41 | 42 | String currentWindowHandle = driver.getWindowHandle(); 43 | 44 | Set windowHandles = driver.getWindowHandles(); 45 | 46 | for (String handle : windowHandles) { 47 | 48 | if(!handle.equals(currentWindowHandle)){ 49 | driver.switchTo().window(handle); 50 | } 51 | } 52 | 53 | System.out.println("Title after switch new window:"+driver.getTitle()); 54 | 55 | } 56 | 57 | @Test 58 | public void moreThan2Window(){ 59 | driver.get("http://practice.cybertekschool.com/windows"); 60 | 61 | driver.findElement(By.linkText("Click Here")).click(); 62 | 63 | System.out.println("Before Switch:"+driver.getTitle()); 64 | 65 | Set windowHandles = driver.getWindowHandles(); 66 | 67 | 68 | //loop through each window 69 | for (String handle : windowHandles) { 70 | //one by one change it 71 | driver.switchTo().window(handle); 72 | 73 | //whenever your title equals to your expected window title 74 | if(driver.getTitle().equals("New Window")){ 75 | //stop on that window 76 | break; 77 | } 78 | 79 | } 80 | 81 | System.out.println("After Switch: "+driver.getTitle()); 82 | 83 | } 84 | 85 | 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day9_popups_tabs_frames/PopupsAndAlerts.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day9_popups_tabs_frames; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.Alert; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.WebDriver; 7 | import org.testng.annotations.AfterMethod; 8 | import org.testng.annotations.BeforeMethod; 9 | import org.testng.annotations.Test; 10 | 11 | public class PopupsAndAlerts { 12 | 13 | WebDriver driver; // our driver is an instance of WebDriver interface 14 | 15 | @BeforeMethod 16 | public void setUp(){ 17 | driver = WebDriverFactory.getDriver("chrome"); 18 | } 19 | 20 | @AfterMethod 21 | public void tearDown() throws InterruptedException { 22 | Thread.sleep(2000); 23 | //driver.quit(); 24 | } 25 | 26 | @Test 27 | public void test1(){ 28 | driver.get("https://www.primefaces.org/showcase/ui/overlay/confirmDialog.xhtml"); 29 | 30 | //click the Confirm button 31 | driver.findElement(By.xpath("//button/span[text()='Confirm']")).click(); 32 | 33 | //Click NO button 34 | driver.findElement(By.xpath("//button[.='No']")).click(); 35 | 36 | } 37 | 38 | @Test 39 | public void test2() throws InterruptedException { 40 | driver.get("http://practice.cybertekschool.com/javascript_alerts"); 41 | 42 | //click Click For JS Alert Button 43 | // driver.findElement(By.xpath("//button[1]")).click(); 44 | 45 | //switch to JS alert pop up 46 | Alert alert = driver.switchTo().alert(); // polymorphism: my alert object is an instance of Alert interface 47 | Thread.sleep(2000); 48 | alert.accept(); 49 | 50 | //click for JS confirm 51 | driver.findElement(By.xpath("//button[2]")).click(); 52 | Thread.sleep(2000); 53 | alert.dismiss(); 54 | 55 | //click for JS Prompt 56 | driver.findElement(By.xpath("//button[3]")).click(); 57 | //send keys to JS Prompt 58 | alert.sendKeys("MikeSmith"); 59 | //click OK 60 | alert.accept(); 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day9_popups_tabs_frames/iframeTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day9_popups_tabs_frames; 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 iframeTest { 12 | 13 | 14 | WebDriver driver; 15 | 16 | @BeforeMethod 17 | public void setUp(){ 18 | driver = WebDriverFactory.getDriver("chrome"); 19 | } 20 | 21 | @AfterMethod 22 | public void tearDown() throws InterruptedException { 23 | Thread.sleep(2000); 24 | driver.quit(); 25 | } 26 | 27 | @Test 28 | public void test1() throws InterruptedException { 29 | driver.get("http://practice.cybertekschool.com/iframe"); 30 | 31 | //How to switch frames 32 | //1.Switch using by name or ID attribute of iframe 33 | driver.switchTo().frame("mce_0_ifr"); 34 | 35 | //clear before sendkeys 36 | driver.findElement(By.cssSelector("#tinymce")).clear(); 37 | Thread.sleep(1000); 38 | driver.findElement(By.cssSelector("#tinymce")).sendKeys("MikeSmith"); 39 | 40 | //goes back to first frame(main html) 41 | //goes back to first frame, useful when we have switched multiple frames 42 | driver.switchTo().defaultContent(); 43 | 44 | //2.Switching with INDEX 45 | driver.switchTo().frame(0); 46 | Thread.sleep(1000); 47 | 48 | //clear before sendkeys 49 | driver.findElement(By.cssSelector("#tinymce")).clear(); 50 | Thread.sleep(1000); 51 | driver.findElement(By.cssSelector("#tinymce")).sendKeys("MikeSmith WITH INDEX"); 52 | 53 | //second way to switch parent 54 | driver.switchTo().parentFrame(); 55 | 56 | //3.USING WEBELEMENT 57 | //locating iframe with any valid locator 58 | WebElement iframeElement = driver.findElement(By.tagName("iframe")); 59 | 60 | driver.switchTo().frame(iframeElement); 61 | 62 | Thread.sleep(1000); 63 | driver.findElement(By.cssSelector("#tinymce")).sendKeys("MikeSmith WITH WEBELEMENT"); 64 | 65 | //html 66 | //top 67 | //left 68 | //middle 69 | //firstFrame 70 | //smallFrame 71 | //right 72 | //bottom 73 | /* 74 | We can switch one at a time, cannot switch to grandchild directly. 75 | · We cannot switch to siblings. 76 | · We can only switch from parent to child, or from child to parent. 77 | */ 78 | 79 | 80 | } 81 | 82 | @Test 83 | public void test2(){ 84 | driver.get("http://practice.cybertekschool.com/nested_frames"); 85 | 86 | //switching to frame top 87 | driver.switchTo().frame("frame-top"); 88 | //top has 3 frame under left middle and right 89 | //switch to frame middle 90 | driver.switchTo().frame("frame-middle"); 91 | 92 | System.out.println(driver.findElement(By.id("content")).getText()); 93 | 94 | //goes back to top frame 95 | driver.switchTo().parentFrame(); 96 | 97 | //switching right with index 98 | driver.switchTo().frame(2); 99 | 100 | System.out.println(driver.findElement(By.tagName("body")).getText()); 101 | 102 | //go to main html to switch bottom 103 | driver.switchTo().defaultContent(); 104 | 105 | driver.switchTo().frame(1); 106 | 107 | System.out.println(driver.findElement(By.tagName("body")).getText()); 108 | 109 | 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day9_waits/ExplicitWaitExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day9_waits; 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.ExpectedConditions; 8 | import org.openqa.selenium.support.ui.WebDriverWait; 9 | import org.testng.annotations.AfterMethod; 10 | import org.testng.annotations.BeforeMethod; 11 | import org.testng.annotations.Test; 12 | 13 | public class ExplicitWaitExample { 14 | 15 | 16 | WebDriver driver; 17 | 18 | @BeforeMethod 19 | public void setUp(){ 20 | driver = WebDriverFactory.getDriver("chrome"); 21 | 22 | } 23 | 24 | @AfterMethod 25 | public void tearDown() throws InterruptedException { 26 | //Thread.sleep(2000); 27 | driver.quit(); 28 | } 29 | 30 | @Test 31 | public void test1() throws InterruptedException { 32 | driver.get("http://practice.cybertekschool.com/dynamic_loading/1"); 33 | 34 | driver.findElement(By.tagName("button")).click(); 35 | 36 | WebElement usernameInput = driver.findElement(By.id("username")); 37 | 38 | //HOW TO WAIT EXPLICITLY ? 39 | //create Explicit wait object 40 | WebDriverWait wait = new WebDriverWait(driver,10); 41 | 42 | wait.until(ExpectedConditions.visibilityOf(usernameInput)); 43 | 44 | usernameInput.sendKeys("MikeSmith"); 45 | 46 | } 47 | 48 | @Test 49 | public void test2() throws InterruptedException { 50 | driver.get("http://practice.cybertekschool.com/dynamic_controls"); 51 | 52 | //click enable 53 | driver.findElement(By.xpath("//*[.='Enable']")).click(); 54 | 55 | //finding inputbox 56 | WebElement inputBox = driver.findElement(By.cssSelector("#input-example>input")); 57 | 58 | WebDriverWait wait = new WebDriverWait(driver,5); 59 | 60 | wait.until(ExpectedConditions.elementToBeClickable(inputBox)); 61 | 62 | 63 | 64 | inputBox.sendKeys("MikeSmith"); 65 | 66 | Thread.sleep(2000); 67 | } 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day9_waits/ImplicitWaitExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day9_waits; 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.concurrent.TimeUnit; 12 | 13 | public class ImplicitWaitExample { 14 | 15 | 16 | WebDriver driver; 17 | 18 | @BeforeMethod 19 | public void setUp(){ 20 | driver = WebDriverFactory.getDriver("chrome"); 21 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 22 | 23 | } 24 | 25 | @AfterMethod 26 | public void tearDown() throws InterruptedException { 27 | //Thread.sleep(2000); 28 | driver.quit(); 29 | } 30 | 31 | @Test 32 | public void test1() throws InterruptedException { 33 | driver.get("http://practice.cybertekschool.com/dynamic_loading/4"); 34 | 35 | 36 | WebElement element = driver.findElement(By.cssSelector("#finish")); 37 | 38 | System.out.println(element.getText()); 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/day9_waits/ThreadSleepExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.day9_waits; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.testng.annotations.AfterMethod; 7 | import org.testng.annotations.BeforeMethod; 8 | import org.testng.annotations.Test; 9 | 10 | public class ThreadSleepExample { 11 | 12 | 13 | WebDriver driver; 14 | 15 | @BeforeMethod 16 | public void setUp(){ 17 | driver = WebDriverFactory.getDriver("chrome"); 18 | } 19 | 20 | @AfterMethod 21 | public void tearDown() throws InterruptedException { 22 | Thread.sleep(2000); 23 | driver.quit(); 24 | } 25 | 26 | @Test 27 | public void test1() throws InterruptedException { 28 | driver.get("http://practice.cybertekschool.com/dynamic_loading/3"); 29 | 30 | Thread.sleep(6000); 31 | 32 | driver.findElement(By.id("username")).sendKeys("MikeSmith"); 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week01/NotesOfTheWeek: -------------------------------------------------------------------------------- 1 | 1. IntelliJ Settings 2 | mouse zoom: Settings->Editor -> General -> Mouse Control 3 | how to find stuff: 4 | - CTRL+Shift+F looks inside the whole project 5 | (MAC: CMND+Shift+F) 6 | -CTRL+F: looks for only in this file 7 | 8 | 2. When we create our Selenium project what is the build tool? 9 | MAVEN ----Built tool (Gradle, Ant ) 10 | Manage dependencies (libraries) 11 | Built: repeated steps when creating a project 12 | 13 | 3. What is automation? 14 | - If there are repeated steps & process, and you want to reduce human interaction, you can automate process 15 | ** Benefits of Automation: 16 | - Precision 17 | - Reduce mistakes 18 | - More accurate results 19 | - Faster and save time for us****** 20 | - Save cost 21 | - Auto generated reports and these reports can be sent automatically everyday to your colleagues. 22 | ( CI/CD Tools: Jenkins-- this one runs codes automatically and generate emails) 23 | 4. What is Selenium? 24 | * just a library (ready classes created for web automation) 25 | * you can only automate web based applications, you can NOT do desktop apps automation 26 | 27 | 5. In Selenium we will learn bunch of Methods: 28 | #1 What is the method doing? 29 | #2 Does it accept any arguments (parameters) ? 30 | #3 Does it return anything? What is the return type? 31 | #4 Does it throw an exception? // we need to handle the exception----- 32 | example: get() method 33 | #1- This gets the given url in an already opened browser 34 | #2- This method accepts String as an argument-- url 35 | #3- void method, not returning 36 | 37 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week01/T01_YahooPractice.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week01; 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 T01_YahooPractice { 8 | /* 9 | open the webpage 10 | go to https://www.yahoo.com/ 11 | verify the title 12 | expectedTitle= "Yahoo" 13 | actualTitle = webPage 14 | */ 15 | 16 | public static void main(String[] args) { 17 | 18 | // setUp browser type 19 | WebDriverManager.chromedriver().setup(); 20 | 21 | // how can I open a new page, this statement opens an empty page 22 | WebDriver driver = new ChromeDriver(); 23 | 24 | // go to the page 25 | driver.get("https://www.yahoo.com/"); 26 | 27 | String expectedTitle = "Yahoo"; 28 | 29 | String actualTitle = driver.getTitle(); 30 | 31 | System.out.println("expectedTitle = " + expectedTitle); 32 | System.out.println("actualTitle = " + actualTitle); 33 | 34 | if (actualTitle.contains(expectedTitle)) { 35 | System.out.println("Test Passed"); 36 | } else { 37 | System.out.println("Test Failed"); 38 | } 39 | 40 | driver.close(); 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week01/T02_CybertekUrlTask.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week01; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.WebDriver; 5 | 6 | public class T02_CybertekUrlTask { 7 | /* 8 | Use WebDriverFactory 9 | * go to http://practice.cybertekschool.com/ website 10 | * verify if the URL contains "cybertekschool" 11 | * Verify the title as well "Practice" 12 | */ 13 | 14 | public static void main(String[] args) { 15 | 16 | // initialize my driver object 17 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 18 | // I want to maximize my page, sometimes selenium can not find element without maximize 19 | driver.manage().window().maximize(); 20 | // go to the page 21 | driver.get("http://practice.cybertekschool.com/"); 22 | 23 | 24 | 25 | String expectedUrlText = "cybertekschool"; 26 | String actualUrl = driver.getCurrentUrl(); 27 | 28 | System.out.println("verify if the URL contains \"cybertekschool\" : "+actualUrl.contains(expectedUrlText)); 29 | 30 | System.out.println("Title verify : "+ driver.getTitle().equalsIgnoreCase("Practice")); 31 | 32 | driver.close(); 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week02/LocatorHWTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week02; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import io.github.bonigarcia.wdm.WebDriverManager; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | 9 | public class LocatorHWTest { 10 | /* 11 | Test case 12 | Go to Ebay 13 | search Selenium 14 | click on search button 15 | print number of results 16 | verify title contains Selenium 17 | */ 18 | 19 | public static void main(String[] args) { 20 | 21 | 22 | WebDriverManager.chromedriver().setup(); // handles all those downloading necessary driver for your operating system 23 | 24 | WebDriver driver = WebDriverFactory.getDriver("chrome"); // open an empty browser 25 | // Go to Ebay 26 | driver.get("https://www.ebay.com/"); 27 | 28 | // search Selenium 29 | 30 | // with ID locator WebElement searchBox = driver.findElement(By.id("gh-ac"));// to duplicate a line CTRL+D CMND+D 31 | 32 | 33 | // with name locator WebElement searchBox = driver.findElement(By.name("_nkw")); 34 | 35 | // this is xpath with class name attribute 36 | WebElement searchBox = driver.findElement(By.xpath("//input[@class='gh-tb ui-autocomplete-input']")); 37 | 38 | // WebElement searchBox = driver.findElement(By.className("gh-tb ui-autocomplete-input")); 39 | 40 | // for tagName //input tag for search box reveals 7 items and my element is the 3rd one 41 | 42 | String expectedSearcItem = "Selenium"; 43 | 44 | searchBox.sendKeys(expectedSearcItem); 45 | 46 | WebElement searchButton = driver.findElement(By.id("gh-btn")); // locate the element 47 | searchButton.click(); // apply action 48 | 49 | WebElement searchResultElement = driver.findElement(By.xpath("//h1[@class='srp-controls__count-heading']")); 50 | 51 | String searchResultText = searchResultElement.getText(); 52 | 53 | String [] arr = searchResultText.split(" "); 54 | 55 | System.out.println("Number os search results = " + arr[0]); 56 | 57 | 58 | driver.close(); 59 | 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week02/Notes.txt: -------------------------------------------------------------------------------- 1 | Purpose of our dependencies: 2 | In order to automate Browsers: 3 | * Selenium-Java Dependency: Version--3.141.59 4 | 5 | * Selenium needs to talk to browsers, there is a middle man 6 | WebDriverManager(Driver--binary files (0000110010)) 7 | Without WebDriverManager we need to install each browser (firefox, chrome...) 8 | manually. If you put the dependency then all these setup is done by the code. 9 | 10 | Let's get the latest one: mvnrepository website 11 | https://mvnrepository.com/ 12 | search for webdrivermanager 13 | 14 | What do we test as a tester? Main Job? 15 | We need to compare Expected VS Actual 16 | * Actual comes from : From Application (WebPage) 17 | * Expected comes from : SRS (system requirements specification), Documentation 18 | 19 | 20 | In order to get the actual data from webpage wih automation, Selenium 21 | comes with ready methods: 22 | 23 | 1. Finding WebElement is the most important part of it. 24 | 25 | 2. Locate them (findElement() Method) 26 | 27 | 3. Apply an action (click, sendKeys....) 28 | 29 | Locators: 30 | 6 Locators (non-custom) - id, name, tagName, ClassName, LinlTExt, PartialLinkText 31 | # id locator: it is always unique, but problem can be dynamic 32 | 33 | # name locator: check if it is duplicate 34 | 35 | # tagName: has to be only one of them or first 36 | this locator is good to use with findElements() method (List webelements) 37 | 38 | # className: has to be only one of them or first, if it has space 39 | this locator is good to use with findElements() method (List webelements) 40 | 41 | # LinkText/Partial LinkText 42 | works with anchor tag ----> tag : text of the webelement 43 | 44 | 2 Locators (custom) : Xpath --- CSS locators 45 | # XPATH: Most useful 3 formulas that you can memorize 46 | 1 ) //tagName[@attribute='value'] 47 | //h1[@class='srp-controls__count-heading'] 48 | 2 ) //tagName[.='text'] 49 | //a[.='Laptops'] 50 | 3 ) //tagName[contains(@attribute,'value')] : to find dynamic elements 51 | //input[contains(@class,'btn-prim')] 52 | /html/body/header/table/tbody/tr/td[3]/form/table/tbody/tr/td[3]/input 53 | How many different categories of Xpath 54 | 2: Absolute xpath, Relative xpath 55 | Absolute xpath: with '/' it looks child of each parent (parent to child hierarchy) 56 | Not Recommended 57 | Relative xpath: '//' look for any tag in anywhere in the page 58 | 59 | How to go from parent to child with xpath 60 | //tagName(xpath formula)/childTag single slash 61 | 62 | from child to parent 63 | //childElementXpathFormula/.. single slash and double dots (we will use this a lot with dynamic webtable) 64 | 65 | 66 | P.I.Q.: What is the exception that you get the most? 67 | I am getting NoSuchElementException the most 68 | 1. Wrong locator (my mistake) 69 | 2. Your locator is correct but Developer might have changed something 70 | 3. Environmental problem---> syncronization wait management (static wait--Thread.sleep(2000);) 71 | Your JAVA code is very fast comparing to WebSite loading 72 | We will learn dynamic waits. 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week02/Task2.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week02; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import io.github.bonigarcia.wdm.WebDriverManager; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | 9 | public class Task2 { 10 | /* 11 | go to https://www.demoblaze.com/index.html# 12 | Navigate to Laptops Category 13 | Then Sony vaio i7 laptop 14 | Verify the product price is 790 Dollars 15 | */ 16 | public static void main(String[] args) throws InterruptedException { 17 | 18 | WebDriver driver = WebDriverFactory.getDriver("chrome"); 19 | 20 | driver.manage().window().maximize(); 21 | 22 | driver.get("https://www.demoblaze.com/index.html"); 23 | 24 | // Navigate to Laptops Category 25 | 26 | driver.findElement(By.linkText("Laptops")).click(); 27 | 28 | Thread.sleep(1000); 29 | 30 | // Then Sony vaio i7 laptop 31 | 32 | driver.findElement(By.partialLinkText("Sony vaio i7")).click(); 33 | 34 | Thread.sleep(2000); 35 | 36 | int expectedPrice = 790; 37 | 38 | WebElement priceTextElement = driver.findElement(By.tagName("h3")); // locate price element 39 | 40 | String priceText = priceTextElement.getText(); // get the text of price element 41 | 42 | System.out.println("priceText = " + priceText); 43 | // priceText = $790 *includes tax 44 | 45 | String [] arr = priceText.split(" "); // top get the numbers I am dividing the text to pieces 46 | // arr[0] = $790 47 | int actualPrice = Integer.parseInt(arr[0].substring(1)); // Wrapper class to cast my String into integer 48 | 49 | // Assertion : Verification ---- TestNG comes with assertion methods 50 | System.out.println("Actual and Expected Price is same : "+(expectedPrice==actualPrice)); 51 | 52 | if(expectedPrice==actualPrice){ 53 | System.out.println("Actual and Expected Price is same"); 54 | }else{ 55 | System.out.println("Test Failed, price is not same"); 56 | } 57 | 58 | driver.close(); 59 | 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week03/CheckBoxHW.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week03; 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.*; 9 | 10 | import java.util.ArrayList; 11 | 12 | public class CheckBoxHW { 13 | /* 14 | Test Case Verify CheckBox CheckAll and UncheckAll Buttons 15 | 1. Go to http://secure.smartbearsoftware.com/samples/TestComplete12/WebOrders/Login.aspx 16 | 2. Login with-----Username: Tester, password: test 17 | // Test Case 1 18 | 3. Click on check all button verify all the checkboxes are checked 19 | 4. Click on uncheck all button verify that all the checkboxes are unchecked 20 | // Test Case 2 21 | 5. Select one of the checkbox and delete one person 22 | 6. Then verify that deleted item is no longer exists 23 | 24 | What is the precondition for both Test Cases? Login to webPage 25 | Can I out the same precondition to BeforeMethod? Yes 26 | */ 27 | public WebDriver driver; // declare your variable/object globally and use it at every method 28 | // annotations are there to effect your test flow 29 | 30 | 31 | @BeforeMethod 32 | public void openPage(){ 33 | driver = WebDriverFactory.getDriver("chrome"); // initialize our driver object 34 | driver.get("http://secure.smartbearsoftware.com/samples/TestComplete12/WebOrders/Login.aspx"); 35 | driver.manage().window().maximize(); 36 | // Login to WebPage 37 | WebElement userNameBox = driver.findElement(By.id("ctl00_MainContent_username")); 38 | userNameBox.sendKeys("Tester"); 39 | WebElement passwordBox = driver.findElement(By.cssSelector("input[name='ctl00$MainContent$password']")); 40 | passwordBox.sendKeys("test"); 41 | WebElement submitButton = driver.findElement(By.cssSelector("input[type='submit']")); 42 | submitButton.click(); 43 | } 44 | 45 | @AfterMethod 46 | public void closeBrowser(){ 47 | driver.close(); 48 | } 49 | 50 | 51 | 52 | @Test (priority = 1) 53 | public void checkBoxAll(){ 54 | // Click on check all button 55 | WebElement checkAllButton = driver.findElement(By.linkText("Check All")); checkAllButton.click(); 56 | // verify all the checkboxes are checked 57 | 58 | // (//input[@type='checkbox'])[1] for the first 59 | // (//input[@type='checkbox'])[2] 60 | // findElements method : can get actually dynamically row number 61 | /* 62 | Assert.assertTrue(driver.findElement(By.xpath("(//input[@type='checkbox'])[1]")).isSelected()); //1 63 | Assert.assertTrue(driver.findElement(By.xpath("(//input[@type='checkbox'])[2]")).isSelected()); //2 64 | Assert.assertTrue(driver.findElement(By.xpath("(//input[@type='checkbox'])[3]")).isSelected()); //3 65 | Assert.assertTrue(driver.findElement(By.xpath("(//input[@type='checkbox'])[4]")).isSelected()); //4 66 | Assert.assertTrue(driver.findElement(By.xpath("(//input[@type='checkbox'])[5]")).isSelected()); //5 67 | */ 68 | 69 | 70 | for (int i = 1; i <= 8 ; i++) { 71 | String rowChechBoxLocator = "(//input[@type='checkbox'])["+i+"]"; // String Concatination 72 | WebElement rowCheckBox = driver.findElement(By.xpath(rowChechBoxLocator)); 73 | Assert.assertTrue(rowCheckBox.isSelected(),"The CheckBox IS NOT selected"); 74 | } 75 | 76 | WebElement unheckAllButton = driver.findElement(By.linkText("Uncheck All")); 77 | unheckAllButton.click(); 78 | for (int i = 1; i <= 8 ; i++) { 79 | String rowChechBoxLocator = "(//input[@type='checkbox'])["+i+"]"; // String Concatination 80 | WebElement rowCheckBox = driver.findElement(By.xpath(rowChechBoxLocator)); 81 | // Assert False method rowCheckBox.isSelected() = NO looking for a FALSE result 82 | Assert.assertFalse(rowCheckBox.isSelected(),"The CheckBox IS STILL selected"); 83 | } 84 | 85 | 86 | 87 | } 88 | 89 | @Test (priority = 2) 90 | public void deletePersonTest(){ 91 | String name = "Charles Dodgeson"; // if I change the name code test should still work 92 | // locator for person name cell: //*[contains(text(),'Steve Johns')] 93 | // locator for checkBox of the person that I want to delete 94 | // //*[contains(text(),'Steve Johns')]/preceding-sibling::*/input (sibling method) 95 | // //*[contains(text(),'Steve Johns')]/..//td[1]/input (parent-child method) 96 | // //td[2]//*[contains(text(),'Charles Dodgeson')] 97 | 98 | String locatorCheckBoxOfPerson = "//*[contains(text(),'"+name+"')]/preceding-sibling::*/input"; 99 | 100 | WebElement checkBoxOfPerson = driver.findElement(By.xpath(locatorCheckBoxOfPerson)); 101 | 102 | checkBoxOfPerson.click(); 103 | 104 | WebElement deleteButton = driver.findElement(By.id("ctl00_MainContent_btnDelete")); 105 | deleteButton.click(); 106 | 107 | // After I delete, I will get all the names and put them in a ArrayList then verfiy that deleted person is not in the list 108 | 109 | // locator for the first person 110 | // (//input[@type='checkbox'])[1]/../../td[2] 111 | ArrayList names = new ArrayList<>(); 112 | 113 | for (int i = 1; i <= 7; i++) { 114 | String eachNameLocator = "(//input[@type='checkbox'])["+i+"]/../../td[2]"; 115 | WebElement eachNameElement = driver.findElement(By.xpath(eachNameLocator)); 116 | String eachName = eachNameElement.getText(); 117 | names.add(eachName); 118 | } 119 | 120 | System.out.println("names = " + names); 121 | 122 | Assert.assertFalse(names.contains(name),"The Name is STILL there, could NOT delete"); 123 | 124 | 125 | } 126 | 127 | 128 | 129 | 130 | 131 | } 132 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week03/Notes.txt: -------------------------------------------------------------------------------- 1 | return type of findElement method: WebElement 2 | What kind of exception does it throw? No such element exception 3 | What are the common reasons of no such element exception? 4 | 1. Our locator might be wrong 5 | 2. Maybe developer changed code 6 | 3. Synchronization: Thread.sleep (this method throws exception, and you need to handle it 7 | you need to add exception to your signature) 8 | 9 | CSS Locators: 10 | - Part of the 8 locators we have in selenium 11 | - like Xpath, it allows us for creating custom locators 12 | - NOT limited to name, id or className attributes, you can use other attributes as well 13 | - You can move from a known element to an element which does not have any attribute 14 | 15 | 2 different syntax: 16 | 1. tagName[attribute='value'] ----> shortcut(if you want to be less specific) [attribute='value'] 17 | 18 | 2. second one can be used only with id and class 19 | tagName#iDValue shortcut(if you want to be less specific) ---> #idValue 20 | tagName.classValue shortcut(if you want to be less specific) ---> .ClassName 21 | 22 | if your css custom locator returns more candidates of WebElements 23 | :nth-of-type(index): in oder to use this they need to be siblings(under same family) 24 | 25 | How to move from Parent to Child 26 | tagName[attribute='value'] > childTagName 27 | http://practice.cybertekschool.com/forgot_password 28 | div[id='content']>div>h2 29 | #content>div>h2 30 | 31 | How to move from child to parent with CSS? You can NOT do it with CSS 32 | With Xpath (XpathLOcator/..) 33 | 34 | PIQ: What are the differences between Xpath and CSS? 35 | 1. CSS has shorter and more cleaner syntax, maybe little bit faster than xpath 36 | 2. we can not locate using text with CSS, but with Xpath we can do it 37 | 3. using index, for CSS they have to be under same parent 38 | 39 | Erdem's Strategy: 40 | First ID, (check dynamic) 41 | With Class name, check for spaces 42 | attribute and value (check if it is duplicate or first one) 43 | Using parent child relationtry 44 | try the 6 locators first if it does not work 45 | then look for custom locator 46 | 47 | For practice purpose: do the same tasks with different locators 48 | 49 | PIQ: How do you handle dynamic web elements? 50 | How do you habdle web elelemnts that has dynamic attribute value? 51 | Melek: how to understand? refresh 52 | use custom locators and start with, ends with and contains 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | isDisplayed() method: 63 | * if the webelement is displayed or Not 64 | * return type: boolean (true/false) 65 | * it does not accept any argument 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week04/ChercherTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week04; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.Alert; 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.ExpectedConditions; 9 | import org.openqa.selenium.support.ui.WebDriverWait; 10 | import org.testng.Assert; 11 | import org.testng.annotations.AfterMethod; 12 | import org.testng.annotations.BeforeMethod; 13 | import org.testng.annotations.Test; 14 | 15 | import java.util.concurrent.TimeUnit; 16 | 17 | public class ChercherTest { 18 | /* 19 | Task1: 20 | 1. Go to https://chercher.tech/practice/explicit-wait-sample-selenium-webdriver 21 | 2. Click on "Click me, to Open an alert after 5 seconds" 22 | 3. Explicitly wait until alert is present 23 | 4. Then handle the Javascript alert 24 | 25 | Task2: 26 | 1. Go to https://chercher.tech/practice/explicit-wait-sample-selenium-webdriver 27 | 2. Click on "Enable button after 10 seconds" 28 | 3. Explicitly wait until the button is enabled 29 | 4. Then verify the button is enabled 30 | */ 31 | WebDriver driver; // declare our reference for the object 32 | 33 | WebDriverWait wait; 34 | 35 | @BeforeMethod 36 | public void setUp(){ 37 | driver = WebDriverFactory.getDriver("chrome"); // create the object 38 | driver.manage().window().maximize(); 39 | // implicitly wait, this is going to be applied to whole test cases and elements 40 | driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 41 | driver.get("https://chercher.tech/practice/explicit-wait-sample-selenium-webdriver"); 42 | } 43 | @AfterMethod 44 | public void tearDown(){ 45 | driver.close(); 46 | } 47 | 48 | @Test 49 | public void alertPresentTest(){ 50 | // Click on "Click me, to Open an alert after 5 seconds" 51 | WebElement initiateALert = driver.findElement(By.id("alert")); 52 | initiateALert.click(); 53 | 54 | wait = new WebDriverWait(driver,10); 55 | wait.until(ExpectedConditions.alertIsPresent()); 56 | // handle javascript alert 57 | // if you don't wait you will get NoAlertPresentException: no such alert 58 | Alert alert = driver.switchTo().alert(); 59 | alert.accept(); 60 | } 61 | 62 | @Test 63 | public void disabledButtonTest(){ 64 | WebElement button = driver.findElement(By.id("disable")); 65 | System.out.println("button.isEnabled() = " + button.isEnabled()); // false 66 | 67 | WebElement buttonInitiator = driver.findElement(By.id("enable-button")); 68 | buttonInitiator.click(); 69 | 70 | wait = new WebDriverWait(driver,10); 71 | wait.until(ExpectedConditions.elementToBeClickable(button)); 72 | 73 | System.out.println("button.isEnabled() = " + button.isEnabled()); // true 74 | Assert.assertTrue(button.isEnabled(),"Verify the Button is enabled"); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week04/DropdownTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week04; 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.support.ui.Select; 9 | import org.openqa.selenium.support.ui.WebDriverWait; 10 | import org.testng.Assert; 11 | import org.testng.annotations.AfterMethod; 12 | import org.testng.annotations.BeforeMethod; 13 | import org.testng.annotations.Test; 14 | 15 | import java.util.concurrent.TimeUnit; 16 | 17 | public class DropdownTest { 18 | /* 19 | Task3: 20 | 1. Go to: http://secure.smartbearsoftware.com/samples/testcomplete12/WebOrders/login.aspx 21 | 2. Login with username: Tester, password: test 22 | 3. Click Order button 23 | 4. Verify under Product Information, selected option is “MyMoney” 24 | 5. Then select FamilyAlbum, make quantity 2, and click Calculate, 25 | 6. Then verify Total is equal to Quantity*PricePerUnit 26 | 27 | 28 | I am trying to see if I can push new stuff 29 | */ 30 | 31 | WebDriver driver; // declare our reference for the object 32 | 33 | WebDriverWait wait; 34 | 35 | @BeforeMethod 36 | public void setUp(){ 37 | driver = WebDriverFactory.getDriver("chrome"); // create the object 38 | driver.manage().window().maximize(); 39 | // implicitly wait, this is going to be applied to whole test cases and elements 40 | driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 41 | driver.get("http://secure.smartbearsoftware.com/samples/testcomplete12/WebOrders/login.aspx"); 42 | } 43 | @AfterMethod 44 | public void tearDown(){ 45 | driver.close(); 46 | } 47 | 48 | @Test 49 | public void test(){ 50 | WebElement userInputBox = driver.findElement(By.id("ctl00_MainContent_username")); 51 | userInputBox.sendKeys("Tester"); 52 | WebElement passwordBox = driver.findElement(By.id("ctl00_MainContent_password")); 53 | passwordBox.sendKeys("test"+ Keys.ENTER); 54 | 55 | WebElement orderLink = driver.findElement(By.linkText("Order")); 56 | orderLink.click(); 57 | 58 | String expectedSelectedOption = "MyMoney"; 59 | WebElement productDropdownElement = driver.findElement(By.id("ctl00_MainContent_fmwOrder_ddlProduct")); 60 | Select productDropdown = new Select(productDropdownElement); 61 | String actualSelectedOption = productDropdown.getFirstSelectedOption().getText(); 62 | Assert.assertEquals(actualSelectedOption,expectedSelectedOption,"First option selected is NOT as expected"); 63 | 64 | // Then select FamilyAlbum, make quantity 2, and click Calculate 65 | productDropdown.selectByVisibleText("FamilyAlbum"); 66 | WebElement quatityBox = driver.findElement(By.id("ctl00_MainContent_fmwOrder_txtQuantity")); 67 | quatityBox.sendKeys("2"); 68 | 69 | WebElement calculateButton = driver.findElement(By.cssSelector("input[type='submit']")); 70 | calculateButton.click(); 71 | // Then verify Total is equal to Quantity*PricePerUnit 72 | int expectedPrice = 160; 73 | 74 | WebElement totalPriceElement = driver.findElement(By.id("ctl00_MainContent_fmwOrder_txtTotal")); 75 | 76 | // System.out.println("totalPriceElement.getText() = " + totalPriceElement.getText()); 77 | // will return nothing 78 | int actualPrice = Integer.parseInt(totalPriceElement.getAttribute("value")); 79 | 80 | Assert.assertEquals(actualPrice,expectedPrice,"Price is NOT as expected"); 81 | 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week5/ActionsandIframeTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week5; 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 | import java.util.concurrent.TimeUnit; 14 | 15 | public class ActionsandIframeTest { 16 | //1. Go to https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_ev_ondblclick2 17 | //2. Switch to iframe. 18 | //3. Double click on the text “Double-click me to change my text color.” 19 | //4. Assert: Text’s “style” attribute value contains “red”. 20 | 21 | WebDriver driver; 22 | @BeforeMethod 23 | public void setUp(){ 24 | driver = WebDriverFactory.getDriver("chrome"); 25 | driver.manage().window().maximize(); 26 | driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); 27 | driver.get("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_ev_ondblclick2"); 28 | } 29 | 30 | @AfterMethod 31 | public void tearDown(){ 32 | driver.close(); 33 | } 34 | 35 | @Test 36 | public void Test() throws InterruptedException { 37 | 38 | Thread.sleep(1000); 39 | //2. Switch to iframe. 40 | // We are switching to iframe using id attribute value and switchTo method. 41 | driver.switchTo().frame("iframeResult"); 42 | 43 | //Locating the text to double click 44 | WebElement textToDoubleClick = driver.findElement(By.id("demo")); 45 | 46 | //3. Double click on the text “Double-click me to change my text color.” 47 | Actions actions = new Actions(driver); 48 | 49 | //use the 'actions' object to double click to already located web element 50 | Thread.sleep(2000); 51 | actions.doubleClick(textToDoubleClick).perform(); 52 | //actions.perform(); 53 | Thread.sleep(2000); 54 | //4. Assert: Text’s “style” attribute value contains “red”. 55 | String expectedInStyle = "red"; 56 | String actual = textToDoubleClick.getAttribute("style"); 57 | 58 | Assert.assertTrue(actual.contains(expectedInStyle)); 59 | 60 | 61 | } 62 | } 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week5/AdidasTask.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week5; 2 | 3 | import com.cybertek.utilities.WebDriverFactory; 4 | import org.openqa.selenium.Alert; 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.ExpectedConditions; 9 | import org.openqa.selenium.support.ui.WebDriverWait; 10 | import org.testng.annotations.AfterMethod; 11 | import org.testng.annotations.BeforeMethod; 12 | import org.testng.annotations.Test; 13 | 14 | import java.util.concurrent.TimeUnit; 15 | 16 | public class AdidasTask { 17 | /* 18 | Adidas Company QA Test 19 | You have to implement the following Web automated checks over our DEMO ONLINE SHOP: https://www.demoblaze.com/index.html 20 | • Customer navigation through product categories: Phones, Laptops and Monitors 21 | • Navigate to "Laptop" → "Sony vaio i5" and click on "Add to cart". Accept pop up confirmation. 22 | • Navigate to "Laptop" → "Dell i7 8gb" and click on "Add to cart". Accept pop up confirmation. 23 | • Navigate to "Cart" → Delete "Dell i7 8gb" from cart. 24 | • Click on "Place order". 25 | • Fill in all web form fields. 26 | • Click on "Purchase" 27 | • Capture and log purchase Id and Amount. 28 | • Assert purchase amount equals expected. 29 | • Click on "Ok" 30 | 31 | HW: finish the task by returning deleted product price 32 | capture expectedPurchaseAmount dynamically 33 | Do the rest of the task, use Faker class for the form 34 | */ 35 | WebDriver driver; 36 | int expectedPurchaseAmount = 0; 37 | @BeforeMethod 38 | public void setUp(){ 39 | driver = WebDriverFactory.getDriver("chrome"); 40 | driver.manage().window().maximize(); 41 | driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); 42 | driver.get("https://www.demoblaze.com/index.html"); 43 | } 44 | 45 | @AfterMethod 46 | public void tearDown(){ 47 | driver.close(); 48 | } 49 | 50 | public void navigateTo(String str){ 51 | driver.findElement(By.partialLinkText(str)).click(); 52 | } 53 | 54 | public int productAdder(String category, String product){ 55 | navigateTo(category); 56 | navigateTo(product); 57 | // I want to get my expected price for that product 58 | WebDriverWait wait = new WebDriverWait(driver,10); 59 | wait.until(ExpectedConditions.visibilityOfElementLocated(By.tagName("h3"))); 60 | WebElement priceElement = driver.findElement(By.tagName("h3")); 61 | String priceWholeText = priceElement.getText(); 62 | String[] arr = priceWholeText.split(" "); 63 | int listPrice = Integer.parseInt(arr[0].substring(1)); 64 | 65 | navigateTo("Add to cart"); 66 | // handle pop up 67 | wait.until(ExpectedConditions.alertIsPresent()); 68 | Alert alert = driver.switchTo().alert(); 69 | alert.accept(); 70 | navigateTo("Home"); 71 | return listPrice; 72 | } 73 | 74 | public int productRemover(String product) throws InterruptedException { 75 | // locator //tr[contains(.,'Sony vaio i5')]/td[4]/a 76 | navigateTo("Cart"); 77 | WebElement deletButton = driver.findElement(By.xpath("//tr[contains(.,'"+product+"')]/td[4]/a")); 78 | deletButton.click(); 79 | Thread.sleep(3000); 80 | return 0; 81 | } 82 | 83 | @Test 84 | public void Test() throws InterruptedException { 85 | // Navigate to "Laptop" → "Sony vaio i5" and click on "Add to cart". Accept pop up confirmation. 86 | expectedPurchaseAmount += productAdder("Laptop","Sony vaio i5"); 87 | // Navigate to "Laptop" → "Dell i7 8gb" and click on "Add to cart". Accept pop up confirmation. 88 | expectedPurchaseAmount += productAdder("Laptop","Dell i7 8gb"); 89 | 90 | System.out.println("expectedPurchaseAmount = " + expectedPurchaseAmount); 91 | 92 | expectedPurchaseAmount -= productRemover("Sony vaio i5"); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week5/ScrollingTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week5; 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 | import java.util.concurrent.TimeUnit; 11 | 12 | public class ScrollingTest { 13 | /* 14 | http://practice.cybertekschool.com/ 15 | 16 | - P.I.Q.: How many ways do you know to scroll using Selenium? 17 | 1. action.moveToElement().perform() 18 | 2. PageUp, PageDown keys for scrolling 19 | 20 | action.sendKeys(Keys.PAGE_UP, PAGE_DOWN) 21 | 22 | 3. jse.executeScript("window.scrollBy(0,250)"); 23 | 4. jse.executeScript("arguments[0].scrollIntoView(true)",cybertekSchoolLink); 24 | */ 25 | // What is TestNG ? Unit testing tool, like JUNIT 26 | WebDriver driver; 27 | @BeforeMethod 28 | public void setUp(){ 29 | driver = WebDriverFactory.getDriver("chrome"); 30 | driver.manage().window().maximize(); 31 | driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); 32 | driver.get("http://practice.cybertekschool.com/"); 33 | } 34 | 35 | @AfterMethod 36 | public void tearDown(){ 37 | driver.close(); 38 | } 39 | 40 | @Test 41 | public void moveToElementTest() throws InterruptedException { // Declared the exception 42 | // Scroll down to Powered by Cybertek School 43 | Actions actions = new Actions(driver); 44 | // locate the element 45 | WebElement cybertekschoolLink = driver.findElement(By.linkText("Cybertek School")); 46 | // scrolling to that elelement 47 | Thread.sleep(5000); // checked exception 48 | 49 | actions.moveToElement(cybertekschoolLink).perform(); 50 | 51 | Thread.sleep(3000); 52 | 53 | // advanced Keyboard actions 54 | driver.get("http://practice.cybertekschool.com/infinite_scroll"); 55 | Thread.sleep(1000); 56 | actions.sendKeys(Keys.PAGE_DOWN,Keys.PAGE_DOWN,Keys.PAGE_DOWN).perform(); 57 | 58 | Thread.sleep(1000); 59 | 60 | } 61 | 62 | @Test 63 | public void scrollTestWithJSE() throws InterruptedException { 64 | 65 | JavascriptExecutor jse = (JavascriptExecutor) driver; 66 | // first way with JSE 67 | Thread.sleep(2000); 68 | jse.executeScript("window.scroll(0,document.body.scrollHeight)"); 69 | Thread.sleep(1000); 70 | jse.executeScript("window.scroll(0,- document.body.scrollHeight)"); 71 | Thread.sleep(1000); 72 | 73 | // Second way with JSE 74 | WebElement cybertekschoolLink = driver.findElement(By.linkText("Cybertek School")); 75 | jse.executeScript("arguments[0].scrollIntoView(true)",cybertekschoolLink); 76 | Thread.sleep(1000); 77 | } 78 | 79 | /* 80 | HW: This is from a real interview task: 81 | v.Test application www.IonicPartners.com: 82 | vi. Test 1: Go to page and scroll it down 83 | vii. Test 2: Go to page, scroll it down and click on Twitter icon at the bottom of the page 84 | */ 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week6/AdidasTaskWithPOM.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week6; 2 | 3 | import com.cybertek.pages.adidasPages.BasePageForAdidas; 4 | import com.cybertek.pages.adidasPages.CartPage; 5 | import com.cybertek.pages.adidasPages.ProductPage; 6 | import com.cybertek.tests.TestBaseTwo; 7 | import org.testng.annotations.Test; 8 | 9 | public class AdidasTaskWithPOM extends TestBaseTwo { 10 | 11 | int expectedPurchaseAmount = 0; 12 | ProductPage productPage = new ProductPage(); 13 | CartPage cartPage = new CartPage(); 14 | 15 | @Test 16 | public void PurchaseTest(){ 17 | 18 | 19 | 20 | // Navigate to "Laptop" → "Sony vaio i5" and click on "Add to cart". Accept pop up confirmation. 21 | expectedPurchaseAmount += productPage.productAdder("Laptop","Sony vaio i5"); 22 | // Navigate to "Laptop" → "Dell i7 8gb" and click on "Add to cart". Accept pop up confirmation. 23 | expectedPurchaseAmount += productPage.productAdder("Laptop","Dell i7 8gb"); 24 | 25 | System.out.println("expectedPurchaseAmount = " + expectedPurchaseAmount); 26 | 27 | expectedPurchaseAmount -= productPage.productRemover("Sony vaio i5"); 28 | 29 | System.out.println("expectedPurchaseAmount = " + expectedPurchaseAmount); 30 | 31 | productPage.navigateTo("Cart"); 32 | 33 | cartPage.placeOrderButton.click(); 34 | 35 | // need to fill up the form, I want to create a method that fills up the form 36 | cartPage.fillForm(); 37 | 38 | /* 39 | • Click on "Purchase" 40 | • Capture and log purchase Id and Amount. 41 | • Assert purchase amount equals expected. 42 | • Click on "Ok" 43 | */ 44 | 45 | // productPage.navigateTo("Laptops"); 46 | // productPage.navigateTo("Sony vaio i5"); 47 | // System.out.println("productPage.priceElement.getText() = " + productPage.priceElement.getText()); 48 | // System.out.println("productPage.productDescription.getText() = " + productPage.productDescription.getText()); 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week7/DataProviderExample.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week7; 2 | 3 | import com.cybertek.utilities.Driver; 4 | import org.apache.poi.hssf.record.chart.DatRecord; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.WebDriver; 7 | import org.testng.Assert; 8 | import org.testng.annotations.*; 9 | 10 | import java.util.concurrent.TimeUnit; 11 | 12 | public class DataProviderExample { 13 | /* 14 | Step 1. Go to “https://practice-cybertekschool.herokuapp.com” 15 | Step 2. And click on “Status Codes”. 16 | Step 3. Then click on “301”. 17 | Step 4. Verify that following message is displayed: 18 | “This page returned a 301 status code” 19 | */ 20 | WebDriver driver; 21 | @BeforeMethod 22 | public void setUp(){ 23 | driver = Driver.get(); 24 | driver.manage().window().maximize(); 25 | driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); 26 | driver.get("https://practice-cybertekschool.herokuapp.com"); 27 | driver.findElement(By.linkText("Status Codes")).click(); 28 | } 29 | 30 | @AfterMethod 31 | public void tearDown(){ 32 | Driver.closeDriver(); 33 | } 34 | @DataProvider 35 | public Object [][] getData(){ 36 | String [][] data = new String[4][2]; 37 | // test case number 9 38 | data[0][0] = "200"; 39 | data[0][1] = "This page returned a 200 status code"; 40 | // test case number 10 41 | data[1][0] = "301"; 42 | data[1][1] = "This page returned a 301 status code"; 43 | // test case number 11 44 | data[2][0] = "404"; 45 | data[2][1] = "This page returned a 404 status code"; 46 | // test case number 12 47 | data[3][0] = "500"; 48 | data[3][1] = "This page returned a 500 status code"; 49 | 50 | /* 51 | String[][] data = { 52 | {"200","This page returned a 200 status code."}, 53 | {"301","This page returned a 301 status code."}, 54 | {"404","This page returned a 404 status code."}, 55 | {"500","This page returned a 500 status code."} 56 | }; 57 | */ 58 | return data; 59 | } 60 | 61 | @Test(dataProvider = "getData") 62 | public void StatusCodesTests(String code, String expectedMessage){ 63 | // String code = "301"; 64 | // String expectedMessage = "This page returned a 301 status code"; 65 | driver.findElement(By.linkText(code)).click(); // clicks on 200 status code 66 | 67 | String actualMessage = driver.findElement(By.tagName("p")).getText(); 68 | 69 | Assert.assertTrue(actualMessage.contains(expectedMessage)); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week7/ExcelDDFTest.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week7; 2 | 3 | import com.cybertek.utilities.Driver; 4 | import com.cybertek.utilities.ExcelUtil; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.WebDriver; 7 | import org.testng.Assert; 8 | import org.testng.annotations.AfterMethod; 9 | import org.testng.annotations.BeforeMethod; 10 | import org.testng.annotations.DataProvider; 11 | import org.testng.annotations.Test; 12 | 13 | import java.util.concurrent.TimeUnit; 14 | 15 | public class ExcelDDFTest { 16 | 17 | /* 18 | Step 1. Go to “https://practice-cybertekschool.herokuapp.com” 19 | Step 2. And click on “Status Codes”. 20 | Step 3. Then click on “301”. 21 | Step 4. Verify that following message is displayed: 22 | “This page returned a 301 status code” 23 | */ 24 | WebDriver driver; 25 | @BeforeMethod 26 | public void setUp(){ 27 | driver = Driver.get(); 28 | driver.manage().window().maximize(); 29 | driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); 30 | driver.get("https://practice-cybertekschool.herokuapp.com"); 31 | driver.findElement(By.linkText("Status Codes")).click(); 32 | } 33 | 34 | @AfterMethod 35 | public void tearDown(){ 36 | Driver.closeDriver(); 37 | } 38 | @DataProvider 39 | public Object [][] getDataExcel(){ 40 | ExcelUtil readFile = new ExcelUtil("src/test/resources/StatusCodes.xlsx","Sheet1"); 41 | 42 | String [][] data = readFile.getDataArrayWithoutFirstRow(); 43 | 44 | return data; 45 | } 46 | 47 | @Test(dataProvider = "getDataExcel") 48 | public void StatusCodesTests(String code, String expectedMessage){ 49 | // String code = "301"; 50 | // String expectedMessage = "This page returned a 301 status code"; 51 | driver.findElement(By.linkText(code)).click(); // clicks on 200 status code 52 | 53 | String actualMessage = driver.findElement(By.tagName("p")).getText(); 54 | 55 | Assert.assertTrue(actualMessage.contains(expectedMessage)); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week7/ExelTestExamples.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week7; 2 | 3 | import com.cybertek.utilities.ExcelUtil; 4 | import org.apache.poi.ss.usermodel.Cell; 5 | import org.apache.poi.ss.usermodel.Row; 6 | import org.apache.poi.ss.usermodel.Sheet; 7 | import org.apache.poi.ss.usermodel.Workbook; 8 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 9 | import org.testng.annotations.Test; 10 | 11 | 12 | import java.io.FileOutputStream; 13 | import java.io.IOException; 14 | import java.util.ArrayList; 15 | import java.util.HashMap; 16 | import java.util.List; 17 | import java.util.Map; 18 | 19 | public class ExelTestExamples { 20 | 21 | List> users = new ArrayList<>(); 22 | @Test 23 | public void createExcelFile() throws IOException { 24 | ExcelUtil readFile = new ExcelUtil("src/test/resources/Vytracktestdata.xlsx","QA3-short"); 25 | 26 | int rowCount = readFile.rowCount(); // This one gives how many rows I have 27 | for (int i = 1; i < rowCount ; i++) { 28 | Map userDataofEachRow = new HashMap<>(); 29 | String userName = readFile.getCellData(i,0); // This one returns cell information 30 | String passWord = readFile.getCellData(i,1); 31 | String firstName = readFile.getCellData(i,2); 32 | String lastName = readFile.getCellData(i,3); 33 | userDataofEachRow.put(readFile.getColumnsNames().get(0),userName); // This one will return Column names in a List format, so I have to give index 34 | userDataofEachRow.put(readFile.getColumnsNames().get(1),passWord); 35 | userDataofEachRow.put(readFile.getColumnsNames().get(2),firstName); 36 | userDataofEachRow.put(readFile.getColumnsNames().get(3),lastName); 37 | users.add(userDataofEachRow); 38 | } 39 | 40 | System.out.println("users = " + users); 41 | 42 | System.out.println("users.get(5).get(\"password\") = " + users.get(5).get("firstname")); // points to line 7, gives the 6th person 43 | 44 | // Creating and writing to an excel file 45 | Workbook workbook = new XSSFWorkbook(); 46 | 47 | Sheet sheet = workbook.createSheet("MyUsers"); 48 | 49 | Row headerRow = sheet.createRow(0); 50 | for (int i = 0; i < readFile.columnCount() ; i++) { 51 | Cell cell = headerRow.createCell(i); // create a cell 52 | cell.setCellValue(readFile.getColumnsNames().get(i)); // put data in the cell 53 | } 54 | 55 | for (int i = 1; i < readFile.rowCount()-1; i++) { 56 | Row eachRow = sheet.createRow(i); 57 | eachRow.createCell(0).setCellValue(users.get(i-1).get("username")); 58 | eachRow.createCell(1).setCellValue(users.get(i-1).get("password")); 59 | eachRow.createCell(2).setCellValue(users.get(i-1).get("firstname")); 60 | eachRow.createCell(3).setCellValue(users.get(i-1).get("lastname")); 61 | } 62 | 63 | FileOutputStream fileOutputStream = new FileOutputStream("src/test/resources/MyUsers.xlsx"); 64 | 65 | workbook.write(fileOutputStream); 66 | fileOutputStream.close(); 67 | workbook.close(); 68 | /* 69 | 3 more weeks for UI Automation 70 | 2 weeks for DataBase (easiest topic) 71 | 3 weeks for API (Mobile Testing as optional videos) 72 | */ 73 | 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week7/HWTests.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week7; 2 | 3 | import com.cybertek.utilities.BrowserUtils; 4 | import org.openqa.selenium.support.ui.ExpectedConditions; 5 | import org.testng.Assert; 6 | import org.testng.annotations.Test; 7 | 8 | public class HWTests extends TestBaseForHW{ 9 | 10 | @Test 11 | public void verifyOptionsTest(){ 12 | extentLogger = report.createTest("Verify Options Link"); 13 | extentLogger.info("Preconditions Loaded"); 14 | extentLogger.info("Verify that Options Link is Displayed"); 15 | Assert.assertTrue(page.optionsLink.isDisplayed(),"Link is NOT Displayed"); 16 | extentLogger.pass("Options is Displayed"); 17 | } 18 | 19 | @Test 20 | public void verifyPageNumber(){ 21 | extentLogger = report.createTest("Verify Page Number"); 22 | int pageNumber = Integer.parseInt(page.pageNumber.getAttribute("value")); 23 | extentLogger.info("verify page number"); 24 | Assert.assertEquals(pageNumber,2,"Page Number is NOT equal to 1"); 25 | extentLogger.pass("page number verified"); 26 | } 27 | 28 | @Test 29 | public void verifyViewPerPageTest(){ 30 | extentLogger = report.createTest("Verify View Per Page Test"); 31 | wait.until(ExpectedConditions.visibilityOf(page.viewPerPage)); 32 | System.out.println("page.viewPerPage.getText() = " + page.viewPerPage.getText()); 33 | int viewPerPage = Integer.parseInt(page.viewPerPage.getText().trim()); 34 | extentLogger.info("Verify View Per Page is 25"); 35 | Assert.assertEquals(viewPerPage,25,"View Per Page is NOT equal to 25 "); 36 | extentLogger.pass("Test PASSED"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week7/Notes.txt: -------------------------------------------------------------------------------- 1 | Today's Topics: 2 | * Vytrack HW together 3 | - Reporting, Screenshot 4 | - TestNG Framework : pom.xml, conf.properties, ConfigurationReader, TestBaseHW, @Annotations, Page Object Models 5 | - Verifying status codes HW : Data Provider and Excel File 6 | * Practicing Data Driven Testing 7 | 8 | * Reporting With Extent Reports: 9 | Step 1: Get the dependency 10 | Step 2: create object for building the report 11 | Step 3: you need to create another object for HTML report file 12 | 13 | 14 | * Exel Documents Read and Write, How to use ExelUtil Class 15 | - How to read from an excel file 16 | - How to create an excel file 17 | 18 | Question: for every new project .we need to create these classes like test base , configuration . properties , configuration reader ????? 19 | 1. New Application ----> New Project : Testing Framework (TestNG, BDD: Behavioral Driven Development: Cucumber Framework) 20 | - MAVEN project: it requires pom.xml (created first) managing the project 21 | - pom.xml: dependencies, JDK level, Maven tools will be controlled 22 | - Utility Package: Driver, ConfigurationReader(to read properties), Project based utility classes 23 | - Parent of Test Cases: TestBase 24 | - If you are using Page Object Model design concept: need to create pages of your application 25 | - Create Test Cases 26 | 27 | XML Runners: 28 | XML files have no predefined tags 29 | pom.xml ---> only means something to MAVEN 30 | testNGRunners make sense only for TestNG -------------------------------------------------------------------------------- /src/test/java/com/cybertek/tests/reviews/week7/TestBaseForHW.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.tests.reviews.week7; 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.CalendarEventsPage; 7 | import com.cybertek.pages.LoginPage; 8 | import com.cybertek.utilities.BrowserUtils; 9 | import com.cybertek.utilities.ConfigurationReader; 10 | import com.cybertek.utilities.Driver; 11 | import org.openqa.selenium.WebDriver; 12 | import org.openqa.selenium.interactions.Actions; 13 | import org.openqa.selenium.support.ui.WebDriverWait; 14 | import org.testng.ITestResult; 15 | import org.testng.annotations.AfterMethod; 16 | import org.testng.annotations.AfterTest; 17 | import org.testng.annotations.BeforeMethod; 18 | import org.testng.annotations.BeforeTest; 19 | 20 | 21 | import java.io.IOException; 22 | import java.util.concurrent.TimeUnit; 23 | 24 | public class TestBaseForHW { 25 | 26 | protected WebDriver driver; 27 | protected Actions actions; 28 | protected WebDriverWait wait; 29 | // For extent report methods 30 | protected ExtentReports report; 31 | protected ExtentHtmlReporter htmlReporter; 32 | protected ExtentTest extentLogger; 33 | 34 | CalendarEventsPage page; 35 | 36 | @BeforeTest 37 | public void setUpTest(){ 38 | report = new ExtentReports(); 39 | String projectPath = System.getProperty("user.dir"); 40 | String path = projectPath+"/test-output/report.html"; 41 | htmlReporter = new ExtentHtmlReporter(path); 42 | report.attachReporter(htmlReporter); 43 | 44 | htmlReporter.config().setReportName("Vytrack Homework Test Cases"); 45 | 46 | report.setSystemInfo("Environment","Test"); 47 | report.setSystemInfo("Browser", ConfigurationReader.get("browser")); 48 | report.setSystemInfo("OS", System.getProperty("os.name")); 49 | } 50 | 51 | @BeforeMethod 52 | public void setUpEachCase(){ 53 | driver = Driver.get(); 54 | driver.manage().window().maximize(); 55 | driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 56 | actions = new Actions(driver); 57 | wait = new WebDriverWait(driver,10); 58 | driver.get(ConfigurationReader.get("qa2_url")); 59 | new LoginPage().loginAsStoreManager(); // Login as a store manager 60 | 61 | page = new CalendarEventsPage(); 62 | page.navigateToModule("Activities","Calendar Events"); 63 | } 64 | 65 | @AfterMethod 66 | public void tearDown(ITestResult result) throws IOException { 67 | if(result.getStatus() == ITestResult.FAILURE){ 68 | extentLogger.fail(result.getName()); 69 | String screenShotPath = BrowserUtils.getScreenshot(result.getName()); 70 | extentLogger.addScreenCaptureFromPath(screenShotPath); 71 | extentLogger.fail(result.getThrowable()); 72 | } 73 | /* 74 | else{ // if you also want to get screenshot if scenario passes (contributed by Berkan) 75 | //record the name of passed test case 76 | extentLogger.pass(result.getName()); 77 | //take the screenshot and return location of screenshot 78 | String screenShotPath= BrowserUtils.getScreenshot(result.getName()); 79 | //add your screenshot to your report 80 | extentLogger.addScreenCaptureFromPath(screenShotPath); 81 | } */ 82 | Driver.closeDriver(); 83 | } 84 | 85 | @AfterTest 86 | public void fullTearDown(){ 87 | report.flush(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/utilities/BrowserUtils.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.utilities; 2 | 3 | 4 | import org.apache.commons.io.FileUtils; 5 | import org.openqa.selenium.*; 6 | import org.openqa.selenium.interactions.Actions; 7 | import org.openqa.selenium.support.ui.ExpectedCondition; 8 | import org.openqa.selenium.support.ui.ExpectedConditions; 9 | import org.openqa.selenium.support.ui.WebDriverWait; 10 | import org.testng.Assert; 11 | 12 | import java.io.File; 13 | import java.io.IOException; 14 | import java.text.SimpleDateFormat; 15 | import java.util.ArrayList; 16 | import java.util.Date; 17 | import java.util.List; 18 | 19 | 20 | public class BrowserUtils { 21 | /* 22 | * takes screenshot 23 | * @param name 24 | * take a name of a test and returns a path to screenshot takes 25 | */ 26 | public static String getScreenshot(String name) throws IOException { 27 | // name the screenshot with the current date time to avoid duplicate name 28 | String date = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()); 29 | // TakesScreenshot ---> interface from selenium which takes screenshots 30 | TakesScreenshot ts = (TakesScreenshot) Driver.get(); 31 | File source = ts.getScreenshotAs(OutputType.FILE); 32 | // full path to the screenshot location 33 | String target = System.getProperty("user.dir") + "/test-output/Screenshots/" + name + date + ".png"; 34 | File finalDestination = new File(target); 35 | // save the screenshot to the path given 36 | FileUtils.copyFile(source, finalDestination); 37 | return target; 38 | } 39 | 40 | /** 41 | * Switches to new window by the exact title. Returns to original window if target title not found 42 | * @param targetTitle 43 | */ 44 | public static void switchToWindow(String targetTitle,WebDriver driver) { 45 | String origin = Driver.get().getWindowHandle(); 46 | for (String handle : Driver.get().getWindowHandles()) { 47 | Driver.get().switchTo().window(handle); 48 | if (Driver.get().getTitle().equals(targetTitle)) { 49 | return; 50 | } 51 | } 52 | Driver.get().switchTo().window(origin); 53 | } 54 | 55 | /** 56 | * Moves the mouse to given element 57 | * 58 | * @param element on which to hover 59 | */ 60 | public static void hover(WebElement element) { 61 | Actions actions = new Actions(Driver.get()); 62 | actions.moveToElement(element).perform(); 63 | } 64 | 65 | /** 66 | * return a list of string from a list of elements 67 | * 68 | * @param list of webelements 69 | * @return list of string 70 | */ 71 | public static List getElementsText(List list) { 72 | List elemTexts = new ArrayList<>(); 73 | for (WebElement el : list) { 74 | elemTexts.add(el.getText()); 75 | } 76 | return elemTexts; 77 | } 78 | 79 | /** 80 | * Extracts text from list of elements matching the provided locator into new List 81 | * 82 | * @param locator 83 | * @return list of strings 84 | */ 85 | public static List getElementsText(By locator) { 86 | 87 | List elems = Driver.get().findElements(locator); 88 | List elemTexts = new ArrayList<>(); 89 | 90 | for (WebElement el : elems) { 91 | elemTexts.add(el.getText()); 92 | } 93 | return elemTexts; 94 | } 95 | 96 | /** 97 | * Performs a pause 98 | * 99 | * @param seconds 100 | */ 101 | public static void waitFor(int seconds) { 102 | try { 103 | Thread.sleep(seconds * 1000); 104 | } catch (InterruptedException e) { 105 | e.printStackTrace(); 106 | } 107 | } 108 | 109 | /** 110 | * Waits for the provided element to be visible on the page 111 | * 112 | * @param element 113 | * @param timeToWaitInSec 114 | * @return 115 | */ 116 | public static WebElement waitForVisibility(WebElement element, int timeToWaitInSec) { 117 | WebDriverWait wait = new WebDriverWait(Driver.get(), timeToWaitInSec); 118 | return wait.until(ExpectedConditions.visibilityOf(element)); 119 | } 120 | 121 | /** 122 | * Waits for element matching the locator to be visible on the page 123 | * 124 | * @param locator 125 | * @param timeout 126 | * @return 127 | */ 128 | public static WebElement waitForVisibility(By locator, int timeout) { 129 | WebDriverWait wait = new WebDriverWait(Driver.get(), timeout); 130 | return wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); 131 | } 132 | 133 | /** 134 | * Waits for provided element to be clickable 135 | * 136 | * @param element 137 | * @param timeout 138 | * @return 139 | */ 140 | public static WebElement waitForClickablility(WebElement element, int timeout) { 141 | WebDriverWait wait = new WebDriverWait(Driver.get(), timeout); 142 | return wait.until(ExpectedConditions.elementToBeClickable(element)); 143 | } 144 | 145 | /** 146 | * Waits for element matching the locator to be clickable 147 | * 148 | * @param locator 149 | * @param timeout 150 | * @return 151 | */ 152 | public static WebElement waitForClickablility(By locator, int timeout) { 153 | WebDriverWait wait = new WebDriverWait(Driver.get(), timeout); 154 | return wait.until(ExpectedConditions.elementToBeClickable(locator)); 155 | } 156 | 157 | /** 158 | * waits for backgrounds processes on the browser to complete 159 | * 160 | * @param timeOutInSeconds 161 | */ 162 | public static void waitForPageToLoad(long timeOutInSeconds) { 163 | ExpectedCondition expectation = new ExpectedCondition() { 164 | public Boolean apply(WebDriver driver) { 165 | return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete"); 166 | } 167 | }; 168 | try { 169 | WebDriverWait wait = new WebDriverWait(Driver.get(), timeOutInSeconds); 170 | wait.until(expectation); 171 | } catch (Throwable error) { 172 | error.printStackTrace(); 173 | } 174 | } 175 | 176 | /** 177 | * Verifies whether the element matching the provided locator is displayed on page 178 | * 179 | * @param by 180 | * @throws AssertionError if the element matching the provided locator is not found or not displayed 181 | */ 182 | public static void verifyElementDisplayed(By by) { 183 | try { 184 | Assert.assertTrue(Driver.get().findElement(by).isDisplayed(), "Element not visible: " + by); 185 | } catch (NoSuchElementException e) { 186 | e.printStackTrace(); 187 | Assert.fail("Element not found: " + by); 188 | 189 | } 190 | } 191 | 192 | /** 193 | * Verifies whether the element matching the provided locator is NOT displayed on page 194 | * 195 | * @param by 196 | * @throws AssertionError the element matching the provided locator is displayed 197 | */ 198 | public static void verifyElementNotDisplayed(By by) { 199 | try { 200 | Assert.assertFalse(Driver.get().findElement(by).isDisplayed(), "Element should not be visible: " + by); 201 | } catch (NoSuchElementException e) { 202 | e.printStackTrace(); 203 | 204 | } 205 | } 206 | 207 | 208 | /** 209 | * Verifies whether the element is displayed on page 210 | * 211 | * @param element 212 | * @throws AssertionError if the element is not found or not displayed 213 | */ 214 | public static void verifyElementDisplayed(WebElement element) { 215 | try { 216 | Assert.assertTrue(element.isDisplayed(), "Element not visible: " + element); 217 | } catch (NoSuchElementException e) { 218 | e.printStackTrace(); 219 | Assert.fail("Element not found: " + element); 220 | 221 | } 222 | } 223 | 224 | 225 | /** 226 | * Waits for element to be not stale 227 | * 228 | * @param element 229 | */ 230 | public static void waitForStaleElement(WebElement element) { 231 | int y = 0; 232 | while (y <= 15) { 233 | if (y == 1) 234 | try { 235 | element.isDisplayed(); 236 | break; 237 | } catch (StaleElementReferenceException st) { 238 | y++; 239 | try { 240 | Thread.sleep(300); 241 | } catch (InterruptedException e) { 242 | e.printStackTrace(); 243 | } 244 | } catch (WebDriverException we) { 245 | y++; 246 | try { 247 | Thread.sleep(300); 248 | } catch (InterruptedException e) { 249 | e.printStackTrace(); 250 | } 251 | } 252 | } 253 | } 254 | 255 | 256 | /** 257 | * Clicks on an element using JavaScript 258 | * 259 | * @param element 260 | */ 261 | public static void clickWithJS(WebElement element) { 262 | ((JavascriptExecutor) Driver.get()).executeScript("arguments[0].scrollIntoView(true);", element); 263 | ((JavascriptExecutor) Driver.get()).executeScript("arguments[0].click();", element); 264 | } 265 | 266 | 267 | /** 268 | * Scrolls down to an element using JavaScript 269 | * 270 | * @param element 271 | */ 272 | public static void scrollToElement(WebElement element) { 273 | ((JavascriptExecutor) Driver.get()).executeScript("arguments[0].scrollIntoView(true);", element); 274 | } 275 | 276 | 277 | 278 | /** 279 | * Performs double click action on an element 280 | * 281 | * @param element 282 | */ 283 | public static void doubleClick(WebElement element) { 284 | new Actions(Driver.get()).doubleClick(element).build().perform(); 285 | } 286 | 287 | /** 288 | * Changes the HTML attribute of a Web Element to the given value using JavaScript 289 | * 290 | * @param element 291 | * @param attributeName 292 | * @param attributeValue 293 | */ 294 | public static void setAttribute(WebElement element, String attributeName, String attributeValue) { 295 | ((JavascriptExecutor) Driver.get()).executeScript("arguments[0].setAttribute(arguments[1], arguments[2]);", element, attributeName, attributeValue); 296 | } 297 | 298 | /** 299 | * Highlighs an element by changing its background and border color 300 | * @param element 301 | */ 302 | public static void highlight(WebElement element) { 303 | ((JavascriptExecutor) Driver.get()).executeScript("arguments[0].setAttribute('style', 'background: yellow; border: 2px solid red;');", element); 304 | waitFor(1); 305 | ((JavascriptExecutor) Driver.get()).executeScript("arguments[0].removeAttribute('style', 'background: yellow; border: 2px solid red;');", element); 306 | } 307 | 308 | /** 309 | * Checks or unchecks given checkbox 310 | * 311 | * @param element 312 | * @param check 313 | */ 314 | public static void selectCheckBox(WebElement element, boolean check) { 315 | if (check) { 316 | if (!element.isSelected()) { 317 | element.click(); 318 | } 319 | } else { 320 | if (element.isSelected()) { 321 | element.click(); 322 | } 323 | } 324 | } 325 | 326 | /** 327 | * attempts to click on provided element until given time runs out 328 | * 329 | * @param element 330 | * @param timeout 331 | */ 332 | public static void clickWithTimeOut(WebElement element, int timeout) { 333 | for (int i = 0; i < timeout; i++) { 334 | try { 335 | element.click(); 336 | return; 337 | } catch (WebDriverException e) { 338 | waitFor(1); 339 | } 340 | } 341 | } 342 | 343 | /** 344 | * executes the given JavaScript command on given web element 345 | * 346 | * @param element 347 | */ 348 | public static void executeJScommand(WebElement element, String command) { 349 | JavascriptExecutor jse = (JavascriptExecutor) Driver.get(); 350 | jse.executeScript(command, element); 351 | 352 | } 353 | 354 | /** 355 | * executes the given JavaScript command on given web element 356 | * 357 | * @param command 358 | */ 359 | public static void executeJScommand(String command) { 360 | JavascriptExecutor jse = (JavascriptExecutor) Driver.get(); 361 | jse.executeScript(command); 362 | 363 | } 364 | 365 | 366 | /** 367 | * This method will recover in case of exception after unsuccessful the click, 368 | * and will try to click on element again. 369 | * 370 | * @param by 371 | * @param attempts 372 | */ 373 | public static void clickWithWait(By by, int attempts) { 374 | int counter = 0; 375 | //click on element as many as you specified in attempts parameter 376 | while (counter < attempts) { 377 | try { 378 | //selenium must look for element again 379 | clickWithJS(Driver.get().findElement(by)); 380 | //if click is successful - then break 381 | break; 382 | } catch (WebDriverException e) { 383 | //if click failed 384 | //print exception 385 | //print attempt 386 | e.printStackTrace(); 387 | ++counter; 388 | //wait for 1 second, and try to click again 389 | waitFor(1); 390 | } 391 | } 392 | } 393 | 394 | /** 395 | * checks that an element is present on the DOM of a page. This does not 396 | * * necessarily mean that the element is visible. 397 | * @param by 398 | * @param time 399 | */ 400 | public static void waitForPresenceOfElement(By by, long time) { 401 | new WebDriverWait(Driver.get(), time).until(ExpectedConditions.presenceOfElementLocated(by)); 402 | } 403 | 404 | 405 | 406 | 407 | 408 | 409 | } -------------------------------------------------------------------------------- /src/test/java/com/cybertek/utilities/ConfigurationReader.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.utilities; 2 | 3 | import java.io.FileInputStream; 4 | import java.util.Properties; 5 | 6 | /** 7 | * reads the properties file configuration.properties 8 | */ 9 | public class ConfigurationReader { 10 | 11 | private static Properties properties; 12 | 13 | static { 14 | 15 | try { 16 | // what file to read 17 | String path = "configuration.properties"; 18 | // read the file into java, finds the file using the string path 19 | FileInputStream input = new FileInputStream(path); 20 | // properties --> class that store properties in key / value format 21 | properties = new Properties(); 22 | // the values from the file input is loaded / fed in to the properties object 23 | properties.load(input); 24 | 25 | input.close(); 26 | } catch (Exception e) { 27 | e.printStackTrace(); 28 | 29 | } 30 | } 31 | 32 | public static String get(String keyName) { 33 | 34 | return properties.getProperty(keyName); 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/utilities/ConfigurationReaderTwo.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.utilities; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.FileNotFoundException; 5 | import java.io.IOException; 6 | import java.util.Properties; 7 | 8 | public class ConfigurationReaderTwo { 9 | 10 | private static Properties properties; // declare a variable 11 | // static blocks: it initiates every time I call class name 12 | 13 | static { 14 | String path = "configurationTwo.properties"; 15 | try { 16 | properties = new Properties(); // created properties object 17 | FileInputStream file = new FileInputStream(path); // throws java io execption, checked exception 18 | properties.load(file); 19 | file.close(); 20 | } catch (IOException e) { 21 | e.printStackTrace(); 22 | } 23 | } 24 | 25 | public static String get(String keyName){ 26 | return properties.getProperty(keyName); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/cybertek/utilities/Driver.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.utilities; 2 | 3 | 4 | import io.github.bonigarcia.wdm.WebDriverManager; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebDriverException; 7 | import org.openqa.selenium.chrome.ChromeDriver; 8 | import org.openqa.selenium.chrome.ChromeOptions; 9 | import org.openqa.selenium.edge.EdgeDriver; 10 | import org.openqa.selenium.firefox.FirefoxDriver; 11 | import org.openqa.selenium.firefox.FirefoxOptions; 12 | import org.openqa.selenium.ie.InternetExplorerDriver; 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 get() { 22 | if (driver == null) { 23 | String browser = ConfigurationReader.get("browser"); 24 | switch (browser) { 25 | case "chrome": 26 | WebDriverManager.chromedriver().setup(); 27 | driver = new ChromeDriver(); 28 | break; 29 | case "chrome-headless": 30 | WebDriverManager.chromedriver().setup(); 31 | driver = new ChromeDriver(new ChromeOptions().setHeadless(true)); 32 | break; 33 | case "firefox": 34 | WebDriverManager.firefoxdriver().setup(); 35 | driver = new FirefoxDriver(); 36 | break; 37 | case "firefox-headless": 38 | WebDriverManager.firefoxdriver().setup(); 39 | driver = new FirefoxDriver(new FirefoxOptions().setHeadless(true)); 40 | break; 41 | case "ie": 42 | if (!System.getProperty("os.name").toLowerCase().contains("windows")) 43 | throw new WebDriverException("Your OS doesn't support Internet Explorer"); 44 | WebDriverManager.iedriver().setup(); 45 | driver = new InternetExplorerDriver(); 46 | break; 47 | 48 | case "edge": 49 | if (!System.getProperty("os.name").toLowerCase().contains("windows")) 50 | throw new WebDriverException("Your OS doesn't support Edge"); 51 | WebDriverManager.edgedriver().setup(); 52 | driver = new EdgeDriver(); 53 | break; 54 | 55 | case "safari": 56 | if (!System.getProperty("os.name").toLowerCase().contains("mac")) 57 | throw new WebDriverException("Your OS doesn't support Safari"); 58 | WebDriverManager.getInstance(SafariDriver.class).setup(); 59 | driver = new SafariDriver(); 60 | break; 61 | 62 | } 63 | 64 | 65 | 66 | } 67 | 68 | return driver; 69 | } 70 | 71 | public static void closeDriver() { 72 | if (driver != null) { 73 | driver.quit(); 74 | driver = null; 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /src/test/java/com/cybertek/utilities/ExcelUtil.java: -------------------------------------------------------------------------------- 1 | package com.cybertek.utilities; 2 | 3 | 4 | import org.apache.poi.ss.usermodel.*; 5 | import org.testng.Assert; 6 | 7 | import java.io.FileInputStream; 8 | import java.io.FileOutputStream; 9 | import java.util.ArrayList; 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /* 15 | * This is a utility for reading from writing to excel files. 16 | * it works with xls and xlsx files. 17 | */ 18 | public class ExcelUtil { 19 | 20 | private Sheet workSheet; 21 | private Workbook workBook; 22 | private String path; 23 | 24 | public ExcelUtil(String path, String sheetName) { 25 | this.path = path; 26 | try { 27 | // Open the Excel file 28 | FileInputStream ExcelFile = new FileInputStream(path); 29 | // Access the required test data sheet 30 | workBook = WorkbookFactory.create(ExcelFile); 31 | workSheet = workBook.getSheet(sheetName); 32 | // check if sheet is null or not. null means sheetname was wrong 33 | Assert.assertNotNull(workSheet, "Sheet: \""+sheetName+"\" does not exist\n"); 34 | 35 | } catch (Exception e) { 36 | throw new RuntimeException(e); 37 | } 38 | } 39 | 40 | public String getCellData(int rowNum, int colNum) { 41 | Cell cell; 42 | try { 43 | cell = workSheet.getRow(rowNum).getCell(colNum); 44 | String cellData = cell.toString(); 45 | return cellData; 46 | } catch (Exception e) { 47 | throw new RuntimeException(e); 48 | } 49 | } 50 | 51 | public String[][] getDataArray() { 52 | 53 | String[][] data = new String[rowCount()][columnCount()]; 54 | 55 | for (int i = 0; i > getDataList() { 82 | // get all columns 83 | List columns = getColumnsNames(); 84 | // this will be returned 85 | List> data = new ArrayList<>(); 86 | 87 | for (int i = 1; i < rowCount(); i++) { 88 | // get each row 89 | Row row = workSheet.getRow(i); 90 | // create map of the row using the column and value 91 | // column map key, cell value --> map bvalue 92 | Map rowMap = new HashMap(); 93 | for (Cell cell : row) { 94 | int columnIndex = cell.getColumnIndex(); 95 | rowMap.put(columns.get(columnIndex), cell.toString()); 96 | } 97 | 98 | data.add(rowMap); 99 | } 100 | 101 | return data; 102 | } 103 | 104 | public List getColumnsNames() { 105 | List columns = new ArrayList<>(); 106 | 107 | for (Cell cell : workSheet.getRow(0)) { 108 | columns.add(cell.toString()); 109 | } 110 | return columns; 111 | } 112 | 113 | public void setCellData(String value, int rowNum, int colNum) { 114 | Cell cell; 115 | Row row; 116 | 117 | try { 118 | row = workSheet.getRow(rowNum); 119 | cell = row.getCell(colNum); 120 | 121 | if (cell == null) { 122 | cell = row.createCell(colNum); 123 | cell.setCellValue(value); 124 | } else { 125 | cell.setCellValue(value); 126 | } 127 | FileOutputStream fileOut = new FileOutputStream(path); 128 | workBook.write(fileOut); 129 | 130 | fileOut.close(); 131 | } catch (Exception e) { 132 | e.printStackTrace(); 133 | } 134 | } 135 | 136 | public void setCellData(String value, String columnName, int row) { 137 | int column = getColumnsNames().indexOf(columnName); 138 | setCellData(value, row, column); 139 | } 140 | 141 | public int columnCount() { 142 | return workSheet.getRow(0).getLastCellNum(); 143 | } 144 | 145 | public int rowCount() { 146 | return workSheet.getLastRowNum()+1; 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /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 | import org.openqa.selenium.safari.SafariDriver; 8 | 9 | public class WebDriverFactory { 10 | 11 | //Task: 12 | //write a static method that takes a string parameter name: browserType 13 | //based on the value of parameter 14 | //it will setup the browser and 15 | //the method will return chromedriver or firefoxdriver object. 16 | //name of the method: getDriver 17 | 18 | public static WebDriver getDriver(String browserType){ 19 | 20 | WebDriver driver = null; 21 | 22 | //Chrome,CHROME,ChrOme 23 | switch (browserType.toLowerCase()){ 24 | case "chrome": 25 | WebDriverManager.chromedriver().setup(); 26 | driver= new ChromeDriver(); 27 | break; 28 | case "firefox": 29 | WebDriverManager.firefoxdriver().setup(); 30 | driver=new FirefoxDriver(); 31 | break; 32 | case "safari": 33 | WebDriverManager.safaridriver().setup(); 34 | driver=new SafariDriver(); 35 | break; 36 | } 37 | return driver; 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/test/resources/StatusCodes.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybertek-EU7/EU7TestNGSelenium/ab30576701fceae0755bf8d898b13c716e45c77a/src/test/resources/StatusCodes.xlsx -------------------------------------------------------------------------------- /src/test/resources/Vytracktestdata.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybertek-EU7/EU7TestNGSelenium/ab30576701fceae0755bf8d898b13c716e45c77a/src/test/resources/Vytracktestdata.xlsx -------------------------------------------------------------------------------- /src/test/resources/textfile.txt: -------------------------------------------------------------------------------- 1 | some text here -------------------------------------------------------------------------------- /testng_runner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | --------------------------------------------------------------------------------