├── .gitignore
├── configuration.properties
├── pom.xml
├── regression_test_runner.xml
├── smoke_test_runner.xml
├── src
└── test
│ ├── java
│ └── com
│ │ └── cybertek
│ │ ├── base
│ │ ├── TestBase.java
│ │ ├── VytrackPageBase.java
│ │ └── VytrackTestBase.java
│ │ ├── pages
│ │ ├── CreateCalendarEventsPage.java
│ │ ├── CreateContactsPage.java
│ │ ├── DashboardPage.java
│ │ ├── LoginPage.java
│ │ ├── LoginPageNoPageFactory.java
│ │ └── VehiclesPage.java
│ │ ├── tests
│ │ ├── day10_webelement
│ │ │ ├── CheckboxesTest.java
│ │ │ ├── DisabledAndDisplayedTests.java
│ │ │ ├── ListOfElementsTests.java
│ │ │ ├── OrderOfTests.java
│ │ │ └── RadioButtonsTest.java
│ │ ├── day11_select_actions
│ │ │ ├── ActionsClassDemo.java
│ │ │ ├── JavaScriptExecutorTests.java
│ │ │ └── SelectClassTests.java
│ │ ├── day12_pops_tabs_alerts_iframes
│ │ │ ├── IframeExample.java
│ │ │ ├── PopupAndAlertsExamples.java
│ │ │ └── TabsAndWindowsExample.java
│ │ ├── day13_waits_and_synchronization
│ │ │ ├── ExplicitWaitExamples.java
│ │ │ ├── ImplicitWaitExamples.java
│ │ │ ├── RandomStuff.java
│ │ │ ├── ThreadSleepExample.java
│ │ │ └── VytrachLoginTestWithWait.java
│ │ ├── day14_test_base_props_driver
│ │ │ ├── FileUploadTests.java
│ │ │ ├── PropertiesExamples.java
│ │ │ ├── Singleton.java
│ │ │ └── TestingTestBaseTests.java
│ │ ├── day15_webtables
│ │ │ └── WebTablesTests.java
│ │ ├── day16_page_object_model
│ │ │ ├── NegativeLoginTests.java
│ │ │ ├── PageHeadersTests.java
│ │ │ └── PositiveLoginTests.java
│ │ ├── day17_ddt_dataprovider_pom2
│ │ │ ├── CreateCalendarEventTests.java
│ │ │ ├── MenuOptionsTests.java
│ │ │ ├── UserInfoDataDrivenTests.java
│ │ │ └── UserInfoDataDrivenTests2.java
│ │ ├── day18_html_report
│ │ │ └── ExtentReportExample.java
│ │ ├── day19_excel_io
│ │ │ ├── ExcelUtilityDemo.java
│ │ │ ├── ExcelWriteExample.java
│ │ │ ├── ReadExcelExample.java
│ │ │ └── VytrackExcelDDTTests.java
│ │ ├── day1_Navigation
│ │ │ ├── BookitTitleVerify.java
│ │ │ ├── EtsyTitleVerify.java
│ │ │ ├── FirstClass.java
│ │ │ ├── Navigations.java
│ │ │ ├── VerifyBookItURL.java
│ │ │ ├── VerifyTitle.java
│ │ │ ├── VerifyURL.java
│ │ │ ├── VrifyURLOfPracticeWeb.java
│ │ │ └── task1.java
│ │ ├── day20_jdbc
│ │ │ ├── MySQLJDBCConnectionDemo.java
│ │ │ └── OracleJDBCConnectionDemo.java
│ │ ├── day21_db_testing
│ │ │ ├── CreateNewContactDBTest.java
│ │ │ └── DbUtilityDemo.java
│ │ ├── day2_Locators
│ │ │ ├── EbaySearch.java
│ │ │ ├── FindElemet.java
│ │ │ └── login.java
│ │ ├── day3_locators2
│ │ │ ├── FakerPractice.java
│ │ │ ├── GetAttributeValue.java
│ │ │ ├── LinkText.java
│ │ │ ├── VerifyErrorMassage.java
│ │ │ └── VerifyLogin.java
│ │ ├── day4_xpath
│ │ │ ├── ClicikvsSubmit.java
│ │ │ ├── GetAttribute.java
│ │ │ ├── PracticeFactory.java
│ │ │ ├── XpathPractice.java
│ │ │ ├── getAttribute2.java
│ │ │ ├── getText.java
│ │ │ └── textMethodOfXpath.java
│ │ ├── day5_more_xpath
│ │ │ ├── ClassNameExample.java
│ │ │ └── XpathDemo.java
│ │ ├── day6_css
│ │ │ └── CssExample.java
│ │ ├── day7_review
│ │ │ ├── AmazonCssExample.java
│ │ │ ├── AmazonTestWithText.java
│ │ │ ├── AmazonTests.java
│ │ │ ├── StaleElementExample.java
│ │ │ └── SystemPropertiesExample.java
│ │ ├── day8_review_2
│ │ │ ├── EbaySearchTest.java
│ │ │ ├── GetAttributeExamples.java
│ │ │ └── VytrackTests.java
│ │ ├── day9_testng_intro
│ │ │ ├── BeforeAndAfterTest.java
│ │ │ ├── FirstTestNGTest.java
│ │ │ └── TestNGAssertionsTest.java
│ │ ├── office_hours1
│ │ │ └── GoogleSearchTest.java
│ │ ├── office_hours2
│ │ │ ├── GoogleHoverTest.java
│ │ │ └── SelectClassPracticeTests.java
│ │ ├── office_hours3
│ │ │ ├── DifferentBrowsers.java
│ │ │ └── EtsyTests.java
│ │ └── office_hours4
│ │ │ ├── ChangeMenuSoftAssertTest.java
│ │ │ ├── CookiesExample.java
│ │ │ ├── CountryInformationDDT.java
│ │ │ ├── IframesExample.java
│ │ │ ├── JavaScriptExecutorExample.java
│ │ │ ├── SoftAssertionsExamples.java
│ │ │ └── WebTablesPractice.java
│ │ └── utilities
│ │ ├── BrowserUtils.java
│ │ ├── ConfigurationReader.java
│ │ ├── DBUtils.java
│ │ ├── Driver.java
│ │ ├── ExcelUtil.java
│ │ └── WebDriverFactory.java
│ └── resources
│ ├── Countries.xlsx
│ └── Vytrack testusers.xlsx
└── testng_runner.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 | .idea
3 | *.iml
4 | *.DS_Store
5 | test-output
--------------------------------------------------------------------------------
/configuration.properties:
--------------------------------------------------------------------------------
1 | browser=chrome
2 | url=http://practice.cybertekschool.com
3 | vytrack_url=https://qa3.vytrack.com/
4 | driver_username=user1
5 | driver_password=UserUser123
6 | sales_manager_username=salesmanager101
7 | sales_manager_password=UserUser123
8 | store_manager_username=storemanager51
9 | store_manager_password=UserUser123
10 | qa3_db_host=107.23.27.171
11 | qa3_db_port=3306
12 | qa3_db_name=bitnami_orocrm
13 | qa3_db_username=qa_user
14 | qa3_db_password=qa_user
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 4.0.0
8 |
9 | com.cybertek
10 | fall-2019-selenium-project
11 | 1.0-SNAPSHOT
12 |
13 |
14 | 1.8
15 | 1.8
16 |
17 |
18 |
19 |
20 |
21 | org.seleniumhq.selenium
22 | selenium-java
23 | 3.141.59
24 |
25 |
26 |
27 |
28 | io.github.bonigarcia
29 | webdrivermanager
30 | 3.8.1
31 |
32 |
33 |
34 |
35 | com.github.javafaker
36 | javafaker
37 | 1.0.1
38 |
39 |
40 |
41 | org.testng
42 | testng
43 | 7.1.0
44 | test
45 |
46 |
47 |
48 | com.aventstack
49 | extentreports
50 | 4.0.4
51 |
52 |
53 |
54 | org.apache.poi
55 | poi
56 | 4.1.2
57 |
58 |
59 |
60 | org.apache.poi
61 | poi-ooxml
62 | 4.1.2
63 |
64 |
65 | com.oracle.ojdbc
66 | ojdbc8
67 | 19.3.0.0
68 |
69 |
70 | mysql
71 | mysql-connector-java
72 | 8.0.18
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/regression_test_runner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/smoke_test_runner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/base/TestBase.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.base;
2 |
3 | import com.cybertek.utilities.Driver;
4 | import com.cybertek.utilities.WebDriverFactory;
5 | import org.openqa.selenium.WebDriver;
6 | import org.testng.annotations.AfterMethod;
7 | import org.testng.annotations.BeforeMethod;
8 |
9 | public abstract class TestBase {
10 | protected WebDriver driver;
11 |
12 | @BeforeMethod
13 | public void setUpMethod() {
14 | driver = Driver.getDriver();
15 |
16 | }
17 |
18 | @AfterMethod
19 | public void tearDownMethod() throws InterruptedException {
20 | // Thread.sleep(5000);
21 | Driver.closeDriver();
22 | }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/base/VytrackPageBase.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.base;
2 |
3 | import com.cybertek.utilities.Driver;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.support.FindBy;
7 | import org.openqa.selenium.support.PageFactory;
8 | import org.openqa.selenium.support.ui.ExpectedConditions;
9 | import org.openqa.selenium.support.ui.WebDriverWait;
10 |
11 | import java.util.List;
12 |
13 | public abstract class VytrackPageBase {
14 |
15 | public VytrackPageBase() {
16 | PageFactory.initElements(Driver.getDriver(), this);
17 | }
18 |
19 | @FindBy(className = "oro-subtitle")
20 | public WebElement pageHeader;
21 |
22 | @FindBy(xpath = "//span[contains(text(), 'Fleet')][@class='title title-level-1']")
23 | public WebElement fleet;
24 |
25 | @FindBy(xpath = "//span[.='Vehicles'][@class='title title-level-2']")
26 | public WebElement vehicles;
27 |
28 | @FindBy(xpath = "(//a[@class='dropdown-toggle'])[1]")
29 | public WebElement accountHolderName;
30 |
31 | @FindBy(css = ".title-level-1")
32 | public List menu1Options;
33 |
34 | public void changeMenu(String menu1, String menu2) {
35 | String menu1X = "//span[contains(text(), '"+menu1+"')][@class='title title-level-1']";
36 | WebElement menu1El = Driver.getDriver().findElement(By.xpath(menu1X));
37 |
38 | String menu2X = "//span[.='"+menu2+"'][@class='title title-level-2']";
39 | WebElement menu2El = Driver.getDriver().findElement(By.xpath(menu2X));
40 |
41 | WebDriverWait wait =new WebDriverWait(Driver.getDriver(), 5);
42 |
43 | wait.until(ExpectedConditions.elementToBeClickable(menu1El));
44 |
45 | menu1El.click();
46 | try {
47 | Thread.sleep(500);
48 | } catch (InterruptedException e) {
49 | e.printStackTrace();
50 | }
51 | wait.until(ExpectedConditions.elementToBeClickable(menu2El));
52 | menu2El.click();
53 |
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/base/VytrackTestBase.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.base;
2 |
3 | import com.aventstack.extentreports.ExtentReports;
4 | import com.aventstack.extentreports.ExtentTest;
5 | import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
6 | import com.cybertek.pages.*;
7 | import com.cybertek.utilities.BrowserUtils;
8 | import com.cybertek.utilities.ConfigurationReader;
9 | import com.cybertek.utilities.Driver;
10 | import org.openqa.selenium.WebDriver;
11 | import org.openqa.selenium.support.ui.WebDriverWait;
12 | import org.testng.ITestResult;
13 | import org.testng.annotations.*;
14 | import org.testng.asserts.SoftAssert;
15 |
16 | import java.io.IOException;
17 |
18 | public abstract class VytrackTestBase {
19 | protected WebDriver driver;
20 | protected WebDriverWait wait;
21 | protected SoftAssert softAssert;
22 | protected LoginPage loginPage;
23 | protected DashboardPage dashboardPage;
24 | protected VehiclesPage vehiclesPage;
25 | protected CreateCalendarEventsPage createCalendarEventsPage;
26 | protected CreateContactsPage createContactsPage;
27 |
28 | protected ExtentReports report;
29 | private ExtentHtmlReporter htmlReporter;
30 | protected ExtentTest test;
31 |
32 | @BeforeSuite
33 | public void setUpSuite() {
34 | report = new ExtentReports();
35 | String path = System.getProperty("user.dir") + "/test-output/report.html";
36 | htmlReporter = new ExtentHtmlReporter(path);
37 | htmlReporter.config().setReportName("Vytrack Automated Tests");
38 |
39 | report.attachReporter(htmlReporter);
40 | report.setSystemInfo("Environment", "QA");
41 | report.setSystemInfo("Browser", ConfigurationReader.getProperty("browser"));
42 |
43 | }
44 |
45 | @AfterSuite
46 | public void tearDownSuite() {
47 | report.flush();
48 | }
49 |
50 | @Parameters("url")
51 | @BeforeMethod()
52 | public void setUpMethod(@Optional String url) {
53 | System.out.println("url = " + url);
54 | driver = Driver.getDriver();
55 | wait = new WebDriverWait(driver, 10);
56 | softAssert = new SoftAssert();
57 |
58 | if (url == null) {
59 | driver.get(ConfigurationReader.getProperty("vytrack_url"));
60 | } else {
61 | driver.get(url);
62 | }
63 |
64 | loginPage = new LoginPage();
65 | dashboardPage = new DashboardPage();
66 | vehiclesPage = new VehiclesPage();
67 | createCalendarEventsPage = new CreateCalendarEventsPage();
68 | createContactsPage = new CreateContactsPage();
69 | }
70 |
71 | @AfterMethod
72 | public void tearDownMethod(ITestResult iTestResult) throws InterruptedException, IOException {
73 | // ITestResult class from testng gives information about current test: name, status
74 | // check if the test failed
75 | if (iTestResult.getStatus() == ITestResult.FAILURE) {
76 | // tell extent report that the test failed
77 | test.fail(iTestResult.getName());
78 |
79 | // take screen shot of the screen and save location
80 | String screenshot = BrowserUtils.getScreenshot(iTestResult.getName());
81 | // show path to screenshot
82 | test.addScreenCaptureFromPath(screenshot);
83 | }
84 |
85 |
86 | // Thread.sleep(3000);
87 | Driver.closeDriver();
88 | softAssert.assertAll();
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/pages/CreateCalendarEventsPage.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.pages;
2 |
3 | import com.cybertek.base.VytrackPageBase;
4 | import com.cybertek.utilities.Driver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.support.FindBy;
7 | import org.openqa.selenium.support.PageFactory;
8 |
9 | public class CreateCalendarEventsPage extends VytrackPageBase {
10 | public CreateCalendarEventsPage(){
11 | PageFactory.initElements(Driver.getDriver(), this);
12 | }
13 |
14 | @FindBy(name = "oro_calendar_event_form[allDay]")
15 | public WebElement allDayEventCheckbox;
16 |
17 | @FindBy(css = "input[id^='recurrence-repeat-view']")
18 | public WebElement repeatCheckbox;
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/pages/CreateContactsPage.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.pages;
2 |
3 | import com.cybertek.base.VytrackPageBase;
4 | import com.cybertek.utilities.Driver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.support.FindBy;
7 | import org.openqa.selenium.support.PageFactory;
8 |
9 | public class CreateContactsPage extends VytrackPageBase {
10 | public CreateContactsPage(){
11 | PageFactory.initElements(Driver.getDriver(), this);
12 | }
13 |
14 | @FindBy(name = "oro_contact_form[firstName]")
15 | public WebElement firstName;
16 |
17 | @FindBy(name = "oro_contact_form[lastName]")
18 | public WebElement lastName;
19 |
20 | @FindBy(name = "oro_contact_form[emails][0][email]")
21 | public WebElement email;
22 |
23 | @FindBy(css = "button[type='submit']")
24 | public WebElement saveAndClose;
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/pages/DashboardPage.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.pages;
2 |
3 | import com.cybertek.base.VytrackPageBase;
4 | import com.cybertek.utilities.Driver;
5 | import org.openqa.selenium.support.PageFactory;
6 |
7 | public class DashboardPage extends VytrackPageBase {
8 | public DashboardPage() {
9 | PageFactory.initElements(Driver.getDriver(), this);
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/pages/LoginPage.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.pages;
2 |
3 | import com.cybertek.base.VytrackPageBase;
4 | import com.cybertek.utilities.Driver;
5 | import org.openqa.selenium.By;
6 | import org.openqa.selenium.WebElement;
7 | import org.openqa.selenium.support.FindBy;
8 | import org.openqa.selenium.support.PageFactory;
9 |
10 | public class LoginPage {
11 | public LoginPage() {
12 | // page object classes needs contructor. here we have to call the PageFactory.initElements
13 | // from selenium and pass a webdriver object and this class as param
14 | PageFactory.initElements(Driver.getDriver(), this);
15 |
16 | }
17 |
18 | // FindBy --> we provide the locator for webelement
19 | @FindBy(id = "prependedInput")
20 | public WebElement username;
21 |
22 | @FindBy(id = "prependedInput2")
23 | public WebElement password;
24 |
25 | @FindBy(name = "_submit")
26 | public WebElement logIn;
27 |
28 | @FindBy(css = ".alert-error>div")
29 | public WebElement errorMessage;
30 |
31 | public void login(String username, String password){
32 | this.username.sendKeys(username);
33 | this.password.sendKeys(password);
34 | logIn.click();
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/pages/LoginPageNoPageFactory.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.pages;
2 |
3 | import com.cybertek.utilities.Driver;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 | import org.openqa.selenium.support.FindBy;
8 | import org.openqa.selenium.support.PageFactory;
9 |
10 | public class LoginPageNoPageFactory {
11 |
12 | private WebDriver driver;
13 |
14 | final By username = By.id("prependedInput");
15 | final By password = By.id("prependedInput2");
16 | final By logIn = By.name("_submit");
17 |
18 | public LoginPageNoPageFactory(WebDriver driver) {
19 | this.driver = driver;
20 | }
21 |
22 | public WebElement getUsername() {
23 | return driver.findElement(username);
24 | }
25 |
26 | public WebElement getPassword() {
27 | return driver.findElement(password);
28 | }
29 |
30 | public WebElement getLoginBtn() {
31 | return driver.findElement(logIn);
32 | }
33 |
34 | public void login(String usernameText, String passwordText) {
35 | getUsername().sendKeys(usernameText);
36 | getPassword().sendKeys(passwordText);
37 | getLoginBtn().click();
38 | }
39 |
40 | public static void main(String[] args) {
41 | LoginPageNoPageFactory loginPage = new LoginPageNoPageFactory(Driver.getDriver());
42 | loginPage.login("abc", "abc");
43 |
44 | loginPage.getUsername().sendKeys("abc");
45 | loginPage.getPassword().sendKeys("abc");
46 |
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/pages/VehiclesPage.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.pages;
2 |
3 | import com.cybertek.base.VytrackPageBase;
4 | import com.cybertek.utilities.Driver;
5 | import org.openqa.selenium.support.PageFactory;
6 |
7 | public class VehiclesPage extends VytrackPageBase {
8 |
9 | public VehiclesPage() {
10 | PageFactory.initElements(Driver.getDriver(), this);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day10_webelement/CheckboxesTest.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day10_webelement;
2 |
3 | import com.cybertek.utilities.WebDriverFactory;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 | import org.testng.Assert;
8 | import org.testng.annotations.AfterMethod;
9 | import org.testng.annotations.BeforeMethod;
10 | import org.testng.annotations.Test;
11 |
12 | public class CheckboxesTest {
13 |
14 | WebDriver driver;
15 |
16 | @BeforeMethod
17 | public void beforeMethod() {
18 | driver = WebDriverFactory.getDriver("chrome");
19 | driver.get("http://practice.cybertekschool.com/checkboxes");
20 |
21 | }
22 |
23 | @AfterMethod
24 | public void afterTest() {
25 | driver.quit();
26 | }
27 |
28 | @Test
29 | public void test(){
30 | WebElement one = driver.findElement(By.xpath("//input[1]"));
31 | WebElement two = driver.findElement(By.xpath("//input[2]"));
32 | // by default one is not checked, two is checked
33 | System.out.println("is one selected: "+ one.isSelected());
34 | System.out.println("is two selected: "+ two.isSelected());
35 |
36 | Assert.assertFalse(one.isSelected());
37 | Assert.assertTrue(two.isSelected());
38 |
39 | // check the first checkbox
40 | // verify one is selected
41 | // verify two is selected
42 | System.out.println("check the first checkbox");
43 | one.click();
44 | System.out.println("is one selected: "+ one.isSelected());
45 | System.out.println("is two selected: "+ two.isSelected());
46 |
47 | Assert.assertTrue(one.isSelected());
48 | Assert.assertTrue(two.isSelected());
49 |
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day10_webelement/DisabledAndDisplayedTests.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day10_webelement;
2 |
3 | import com.cybertek.utilities.WebDriverFactory;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 | import org.testng.Assert;
8 | import org.testng.annotations.AfterMethod;
9 | import org.testng.annotations.BeforeMethod;
10 | import org.testng.annotations.Test;
11 |
12 | public class DisabledAndDisplayedTests {
13 |
14 | WebDriver driver;
15 |
16 | @BeforeMethod
17 | public void beforeMethod() {
18 | driver = WebDriverFactory.getDriver("chrome");
19 | driver.get("http://practice.cybertekschool.com/radio_buttons");
20 |
21 | }
22 |
23 | @AfterMethod
24 | public void afterTest() {
25 | driver.quit();
26 | }
27 |
28 | /*
29 | go to http://practice.cybertekschool.com/radio_buttons
30 | verify green is disabled
31 | verify black is enabled
32 | */
33 |
34 | @Test
35 | public void disabledTest() throws InterruptedException {
36 | Thread.sleep(2000);
37 | WebElement green = driver.findElement(By.id("green"));
38 | WebElement black = driver.findElement(By.id("black"));
39 | // isEnabled --> returns true if the element is enabled, active
40 | System.out.println("Is green enabled: "+green.isEnabled());
41 | System.out.println("Is black enabled: "+black.isEnabled());
42 | Assert.assertFalse(green.isEnabled());
43 | Assert.assertTrue(black.isEnabled());
44 |
45 | }
46 |
47 |
48 | @Test
49 | public void disabledTestWithAttribute() throws InterruptedException {
50 | Thread.sleep(2000);
51 | WebElement green = driver.findElement(By.id("green"));
52 | WebElement black = driver.findElement(By.id("black"));
53 |
54 |
55 | System.out.println("black: "+ black.getAttribute("disabled"));
56 | System.out.println("green: "+ green.getAttribute("disabled"));
57 |
58 | // verify that certain value is equal to null. verify element is enabled
59 | Assert.assertEquals(black.getAttribute("disabled"), null);
60 | // VERIFY THAT VALUE OF black.getAttribute("disabled") IS NULL
61 | Assert.assertNull(black.getAttribute("disabled"));
62 |
63 | // verify that certain value is equal to TRUE. verify element is DISALBED
64 | Assert.assertEquals(green.getAttribute("disabled"), "true");
65 | Assert.assertTrue(Boolean.parseBoolean(green.getAttribute("disabled")));
66 | }
67 |
68 | @Test
69 | public void testElementVisible() throws InterruptedException {
70 | driver.get("http://practice.cybertekschool.com/dynamic_loading/1");
71 | WebElement username = driver.findElement(By.id("username"));
72 | WebElement start = driver.findElement(By.tagName("button"));
73 |
74 | // verify that username is not visible
75 | /// isDisplayed --> returns true element we found in HTML is visible on page
76 | System.out.println("Username is visible: " + username.isDisplayed());
77 | Assert.assertFalse(username.isDisplayed());
78 |
79 | System.out.println("click on start");
80 | start.click();
81 |
82 | Thread.sleep(7000);
83 | System.out.println("Username is visible: " + username.isDisplayed());
84 | Assert.assertTrue(username.isDisplayed());
85 |
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day10_webelement/ListOfElementsTests.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day10_webelement;
2 |
3 | import com.cybertek.utilities.WebDriverFactory;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.Keys;
6 | import org.openqa.selenium.WebDriver;
7 | import org.openqa.selenium.WebElement;
8 | import org.testng.Assert;
9 | import org.testng.annotations.AfterMethod;
10 | import org.testng.annotations.BeforeMethod;
11 | import org.testng.annotations.Test;
12 |
13 | import java.util.List;
14 | import java.util.Random;
15 |
16 | public class ListOfElementsTests {
17 | WebDriver driver;
18 |
19 | @BeforeMethod
20 | public void beforeMethod() {
21 | driver = WebDriverFactory.getDriver("chrome");
22 |
23 | }
24 |
25 | @AfterMethod
26 | public void afterTest() {
27 | driver.quit();
28 | }
29 |
30 | /*
31 | go to page radio buttons
32 | verify that none of the sports radio buttons are selected
33 | */
34 | @Test
35 | public void listOfRadioButtons() throws InterruptedException {
36 | driver.get("http://practice.cybertekschool.com/radio_buttons");
37 |
38 | // driver.findElements --> returns a LIST of element
39 | // returns all the elements that match the given locator
40 | // if the locator does not match anhytihg, it does not throw exception, it just returns empty list
41 |
42 | List sports = driver.findElements(By.name("sport"));
43 |
44 | System.out.println(sports.size());
45 |
46 | for (WebElement radioButton : sports) {
47 | Assert.assertFalse(radioButton.isSelected());
48 | }
49 | }
50 |
51 | /*
52 | go to practice website
53 | get all the links present in the page
54 | print their text
55 | */
56 | @Test
57 | public void getAllLinksTest() {
58 | driver.get("http://practice.cybertekschool.com");
59 |
60 | // get all the links in a page
61 | List links = driver.findElements(By.tagName("a"));
62 | System.out.println(links.size());
63 | // get the text of each link and print
64 |
65 | for (WebElement link : links) {
66 | System.out.println(link.getText());
67 | }
68 | }
69 |
70 |
71 | /*
72 | go to amazon
73 | search for paper towels
74 | print the number of results
75 | print the first result
76 | print the second result
77 | print the last result
78 | */
79 |
80 | @Test
81 | public void amazonTest() throws InterruptedException {
82 | driver.get("https://amazon.com");
83 | WebElement input = driver.findElement(By.id("twotabsearchtextbox"));
84 | input.sendKeys("paper towels" + Keys.ENTER);
85 |
86 | List allResults = driver.findElements(By.cssSelector("span.a-size-base-plus"));
87 |
88 | Thread.sleep(2000);
89 | System.out.println("Number of results: " + allResults.size());
90 |
91 | System.out.println("First result: " + allResults.get(0).getText());
92 | System.out.println("Second result: " + allResults.get(1).getText());
93 | System.out.println("Last result: " + allResults.get(allResults.size() - 1).getText());
94 |
95 |
96 | }
97 |
98 | /*
99 | go to http://practice.cybertekschool.com/radio_buttons
100 | verify the all sports checkboxes are NOT checked by default
101 | randomly click any sport
102 | verify that that sport is clicked
103 | verify that all others are not clicked
104 | repeat the last step for 5 times
105 |
106 | Amirjon special
107 | */
108 |
109 | @Test
110 | public void radioTest() throws InterruptedException {
111 | driver.get("http://practice.cybertekschool.com/radio_buttons");
112 | List list = driver.findElements(By.name("sport"));
113 |
114 | System.out.println("verify none of them selected by default");
115 | System.out.println(list.size());
116 | //checking all the sport checkboxes are not checked
117 | for (int i = 0; i < list.size(); i++) {
118 | Assert.assertFalse(list.get(i).isSelected());
119 | }
120 |
121 | System.out.println("Start randomly selecting radio buttons");
122 |
123 | //randomly clicking and verifying
124 |
125 | for (int q = 0; q < 5; q++) {
126 |
127 | Thread.sleep(5000);
128 | Random ran = new Random();
129 | int num = ran.nextInt(4);
130 | list.get(num).click();
131 | System.out.println("Selecting button number: " + (num + 1));
132 |
133 | for (int i = 0; i < list.size(); i++) {
134 | if (i == num) {
135 | Assert.assertTrue(list.get(num).isSelected());
136 | } else {
137 | Assert.assertFalse(list.get(i).isSelected());
138 | }
139 | }
140 |
141 | }
142 | }
143 |
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day10_webelement/OrderOfTests.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day10_webelement;
2 |
3 | import org.testng.Assert;
4 | import org.testng.annotations.Test;
5 |
6 | public class OrderOfTests {
7 |
8 | String title;
9 |
10 | @Test(priority = 0)
11 | public void login() {
12 | System.out.println("opening the browser");
13 | System.out.println("capturing title");
14 | title = "cbt";
15 | // i will make this test fail. Assert.fail() --> is a ready method that makes test fail
16 | Assert.fail();
17 | }
18 |
19 | @Test(priority = 1, dependsOnMethods = "login")
20 | public void assertTitle() {
21 | System.out.println("verifying the title");
22 | Assert.assertEquals(title, "cbt");
23 | }
24 |
25 | @Test(priority = 55)
26 | public void verifyOtherThings() {
27 | System.out.println("verify sth else");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day10_webelement/RadioButtonsTest.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day10_webelement;
2 |
3 | import com.cybertek.utilities.WebDriverFactory;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 | import org.testng.Assert;
8 | import org.testng.annotations.AfterClass;
9 | import org.testng.annotations.AfterMethod;
10 | import org.testng.annotations.BeforeMethod;
11 | import org.testng.annotations.Test;
12 |
13 | public class RadioButtonsTest {
14 |
15 | WebDriver driver;
16 |
17 | @BeforeMethod
18 | public void beforeMethod() {
19 | driver = WebDriverFactory.getDriver("chrome");
20 | driver.get("http://practice.cybertekschool.com/radio_buttons");
21 |
22 | }
23 |
24 | @AfterMethod
25 | public void afterTest() {
26 | driver.quit();
27 | }
28 |
29 | /* default behavior test
30 | go to http://practice.cybertekschool.com/radio_buttons
31 | verify that blue is selected
32 | verify red is not selected
33 | */
34 |
35 | @Test
36 | public void test1() {
37 | WebElement blue = driver.findElement(By.id("blue"));
38 | // isSelected --> returns true if element is selected
39 | System.out.println(blue.isSelected());
40 |
41 | // verify is the radio button is selected
42 | Assert.assertTrue(blue.isSelected());
43 |
44 | WebElement red = driver.findElement(By.id("red"));
45 | // print red is not selected
46 | System.out.println(red.isSelected());
47 |
48 | // verifies if the statement it false. if it is false, it passes. if true it fails.
49 | Assert.assertFalse(red.isSelected());
50 |
51 | }
52 |
53 | /*
54 | go to http://practice.cybertekschool.com/
55 | click on red
56 | verify that blue is not selected
57 | red is selected
58 | */
59 |
60 | @Test
61 | public void test2() {
62 | WebElement red = driver.findElement(By.id("red"));
63 | WebElement blue = driver.findElement(By.id("blue"));
64 | red.click();
65 | Assert.assertFalse(blue.isSelected());
66 | Assert.assertTrue(red.isSelected());
67 |
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day11_select_actions/ActionsClassDemo.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day11_select_actions;
2 |
3 | import com.cybertek.utilities.WebDriverFactory;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.Keys;
6 | import org.openqa.selenium.WebDriver;
7 | import org.openqa.selenium.WebElement;
8 | import org.openqa.selenium.interactions.Actions;
9 | import org.testng.annotations.AfterMethod;
10 | import org.testng.annotations.BeforeMethod;
11 | import org.testng.annotations.Test;
12 |
13 | public class ActionsClassDemo {
14 |
15 | WebDriver driver;
16 | Actions actions;
17 |
18 | @BeforeMethod
19 | public void beforeMethod() {
20 | driver = WebDriverFactory.getDriver("firefox");
21 | actions = new Actions(driver);
22 | }
23 |
24 | @AfterMethod
25 | public void afterTest() {
26 | driver.quit();
27 | }
28 |
29 | @Test
30 | public void hoverTest() throws InterruptedException {
31 | driver.get("http://practice.cybertekschool.com/hovers");
32 | Thread.sleep(2000);
33 | WebElement target = driver.findElement(By.tagName("img"));
34 |
35 | // moveToElement --> moves the mouse on top of given web element
36 | actions.moveToElement(target).perform();
37 | Thread.sleep(3000);
38 |
39 | }
40 |
41 | @Test
42 | public void hover2(){
43 | driver.get("http://practice.cybertekschool.com/jqueryui/menu");
44 | WebElement enabled = driver.findElement(By.id("ui-id-3"));
45 | WebElement downloads = driver.findElement(By.id("ui-id-4"));
46 | WebElement pdf = driver.findElement(By.id("ui-id-5"));
47 |
48 | // move the mouse to enabled
49 | // wait
50 | // move the mouse to downloads
51 | // wait
52 | // click on PDF
53 |
54 | actions.moveToElement(enabled).
55 | pause(2000).
56 | moveToElement(downloads).
57 | pause(2000).
58 | click(pdf).
59 | build().perform();
60 |
61 | }
62 |
63 | @Test
64 | public void dragAndDrop() throws InterruptedException {
65 | driver.get("https://demos.telerik.com/kendo-ui/dragdrop/index");
66 |
67 | WebElement money = driver.findElement(By.id("draggable"));
68 | WebElement bank = driver.findElement(By.id("droptarget"));
69 | Thread.sleep(2000);
70 |
71 | // scroll
72 | actions.sendKeys(Keys.PAGE_DOWN).perform();
73 | // actions.sendKeys(Keys.ARROW_DOWN).perform();
74 |
75 | actions.dragAndDrop(money, bank).perform();
76 | Thread.sleep(2000);
77 | }
78 |
79 | /*
80 | TASK
81 | do the drag and drop by chaining actions
82 | move mouse to source/money
83 | mouse down
84 | move mouse to target/bank
85 | mouse up
86 | */
87 |
88 | @Test
89 | public void dragAndDropAgain() throws InterruptedException {
90 | driver.get("https://demos.telerik.com/kendo-ui/dragdrop/index");
91 |
92 | WebElement money = driver.findElement(By.id("draggable"));
93 | WebElement bank = driver.findElement(By.id("droptarget"));
94 | Thread.sleep(2000);
95 | actions.moveToElement(money).clickAndHold().moveToElement(bank).release().build().perform();
96 | Thread.sleep(2000);
97 |
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day11_select_actions/JavaScriptExecutorTests.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day11_select_actions;
2 |
3 | import com.cybertek.utilities.WebDriverFactory;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.JavascriptExecutor;
6 | import org.openqa.selenium.WebDriver;
7 | import org.openqa.selenium.WebElement;
8 | import org.openqa.selenium.interactions.Actions;
9 | import org.testng.annotations.AfterMethod;
10 | import org.testng.annotations.BeforeMethod;
11 | import org.testng.annotations.Test;
12 |
13 | public class JavaScriptExecutorTests {
14 | WebDriver driver;
15 | JavascriptExecutor jse;
16 |
17 | @BeforeMethod
18 | public void beforeMethod() {
19 | driver = WebDriverFactory.getDriver("chrome");
20 | jse = (JavascriptExecutor) driver;
21 | }
22 |
23 | @AfterMethod
24 | public void afterTest() {
25 | driver.quit();
26 | }
27 |
28 | @Test
29 | public void scroll() throws InterruptedException {
30 | driver.get("http://practice.cybertekschool.com/");
31 |
32 | WebElement link = driver.findElement(By.linkText("Cybertek School"));
33 | Thread.sleep(2000);
34 | jse.executeScript("arguments[0].scrollIntoView(true);", link);
35 |
36 | Thread.sleep(2000);
37 | }
38 |
39 | @Test
40 | public void sendKeysWithJS(){
41 |
42 | driver.get("http://practice.cybertekschool.com/dynamic_controls");
43 |
44 | WebElement input = driver.findElement(By.cssSelector("input[disabled]"));
45 |
46 | String text = "hi world";
47 |
48 | jse.executeScript("arguments[0].setAttribute('value', '" + text +"')", input);
49 |
50 | // arguments[0].setAttribute('value', 'HELLO WORLD')
51 |
52 | }
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day11_select_actions/SelectClassTests.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day11_select_actions;
2 |
3 | import com.cybertek.utilities.WebDriverFactory;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 | import org.openqa.selenium.support.ui.Select;
8 | import org.testng.Assert;
9 | import org.testng.annotations.AfterMethod;
10 | import org.testng.annotations.BeforeMethod;
11 | import org.testng.annotations.Test;
12 |
13 | import java.text.SimpleDateFormat;
14 | import java.time.LocalDate;
15 | import java.util.ArrayList;
16 | import java.util.Arrays;
17 | import java.util.Date;
18 | import java.util.List;
19 |
20 | public class SelectClassTests {
21 | WebDriver driver;
22 |
23 | @BeforeMethod
24 | public void beforeMethod() {
25 | driver = WebDriverFactory.getDriver("chrome");
26 | driver.get("http://practice.cybertekschool.com/dropdown");
27 |
28 | }
29 |
30 | @AfterMethod
31 | public void afterTest() {
32 | driver.quit();
33 | }
34 |
35 | @Test
36 | public void getSelectedOption() {
37 | // FIND THE ELEMENT THAT HAS SELECT TAG
38 | WebElement dropdown = driver.findElement(By.id("dropdown"));
39 |
40 | // create a select class using the web element
41 | Select dropdownList = new Select(dropdown);
42 |
43 | // get the selected option
44 | WebElement selectedOption = dropdownList.getFirstSelectedOption();
45 | System.out.println(selectedOption.getText());
46 | // verify selected option
47 | Assert.assertEquals(selectedOption.getText(), "Please select an option");
48 | }
49 |
50 | @Test
51 | public void selectFromList() throws InterruptedException {
52 | // get the element with select tag
53 | WebElement dropdown = driver.findElement(By.id("state"));
54 | // create select class
55 | Select states = new Select(dropdown);
56 |
57 | // TODO selectByVisibleText --> selects by the text of the option
58 | states.selectByVisibleText("Iowa");
59 | Thread.sleep(1000);
60 | states.selectByVisibleText("Vermont");
61 | Thread.sleep(1000);
62 | states.selectByVisibleText("Kentucky");
63 | Thread.sleep(1000);
64 |
65 | // TODO selectByIndex --> selects based on the index of the option, 0 based count
66 | states.selectByIndex(0);
67 | Thread.sleep(1000);
68 | states.selectByIndex(10);
69 | Thread.sleep(1000);
70 | states.selectByIndex(20);
71 | Thread.sleep(1000);
72 |
73 | // TODO selectByValue--> selects based on the value of the value attribute of the option
74 | // TODO selectByValue --> it is not select text
75 | states.selectByValue("VA");
76 | Thread.sleep(1000);
77 | states.selectByValue("SC");
78 | Thread.sleep(1000);
79 | states.selectByValue("CO");
80 | Thread.sleep(1000);
81 | states.selectByValue("NE");
82 |
83 | }
84 |
85 | @Test
86 | public void getAllAvailableOptions() {
87 | Select monthList = new Select(driver.findElement(By.id("month")));
88 |
89 | // print the current selection
90 | System.out.println(monthList.getFirstSelectedOption().getText());
91 |
92 | // TODO getOptions--> returns all of the availabe options from dropdown
93 | List allOptions = monthList.getOptions();
94 |
95 | System.out.println("Number of months: " + allOptions.size());
96 |
97 | for (WebElement month : allOptions) {
98 | System.out.println(month.getText());
99 | }
100 |
101 | // verify that months list always shows the current month as selected
102 | // get the current month
103 | String expected = LocalDate.now().getMonth().name();
104 | String actual = monthList.getFirstSelectedOption().getText();
105 | Assert.assertEquals(actual.toLowerCase(), expected.toLowerCase());
106 |
107 | // verify that months list has following values: January....December
108 | List expectedMonths = Arrays.asList("January", "February", "March", "April", "May", "June", "July", "August",
109 | "September", "October", "November", "December");
110 |
111 |
112 | // get options gives me list webelements, so allOptions is alist of web elemetns
113 | // but my expected it a list strings. i have to make sure the both list of strings
114 | // i need to get lsit string from list of webeelment
115 |
116 | List actualMonths = new ArrayList<>();
117 | for (WebElement option : allOptions) {
118 | actualMonths.add(option.getText());
119 | }
120 | Assert.assertEquals(actualMonths, expectedMonths);
121 |
122 | }
123 |
124 |
125 | @Test
126 | public void verifyOptions(){
127 | Select list = new Select(driver.findElement(By.id("dropdown")));
128 | // verify that list has 3 options
129 | int expectedSize = 3;
130 | int actualSize = list.getOptions().size();
131 |
132 | List expectedValues = Arrays.asList("Please select an option", "Option 1", "Option 2");
133 |
134 | List actualValues = new ArrayList<>();
135 | for (WebElement option : list.getOptions()) {
136 | actualValues.add(option.getText());
137 | }
138 |
139 | Assert.assertEquals(actualValues, expectedValues);
140 |
141 | } // BREAK 2.03
142 | }
143 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day12_pops_tabs_alerts_iframes/IframeExample.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day12_pops_tabs_alerts_iframes;
2 |
3 | import com.cybertek.utilities.WebDriverFactory;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 | import org.testng.annotations.AfterMethod;
8 | import org.testng.annotations.BeforeMethod;
9 | import org.testng.annotations.Test;
10 |
11 | public class IframeExample {
12 |
13 |
14 | WebDriver driver;
15 |
16 | @BeforeMethod
17 | public void beforeMethod() {
18 | driver = WebDriverFactory.getDriver("chrome");
19 | }
20 |
21 | @AfterMethod
22 | public void afterTest() {
23 | driver.quit();
24 | }
25 |
26 | @Test
27 | public void test() throws InterruptedException {
28 | driver.get("http://practice.cybertekschool.com/tinymce");
29 |
30 | // we will switch to iframe.
31 | // TODO switch by id/name
32 | driver.switchTo().frame("mce_0_ifr");
33 |
34 | WebElement textBox = driver.findElement(By.id("tinymce"));
35 | textBox.clear();
36 | textBox.sendKeys("great.thanks");
37 |
38 | // get out fo the frame
39 | driver.switchTo().defaultContent();
40 | System.out.println(driver.findElement(By.tagName("h3")).getText());
41 |
42 | // TODO switch by webelement
43 | WebElement frame = driver.findElement(By.tagName("iframe"));
44 | driver.switchTo().frame(frame);
45 |
46 | textBox = driver.findElement(By.id("tinymce"));
47 | textBox.clear();
48 | textBox.sendKeys("great.thanks one time");
49 |
50 | // get out of the frame
51 | driver.switchTo().parentFrame();
52 | System.out.println(driver.findElement(By.tagName("h3")).getText());
53 |
54 | // TODO switch by index
55 | driver.switchTo().frame(0);
56 |
57 | textBox = driver.findElement(By.id("tinymce"));
58 | textBox.clear();
59 | textBox.sendKeys("great.thanks last time");
60 |
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day12_pops_tabs_alerts_iframes/PopupAndAlertsExamples.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day12_pops_tabs_alerts_iframes;
2 |
3 | import com.cybertek.utilities.WebDriverFactory;
4 | import org.openqa.selenium.*;
5 | import org.openqa.selenium.interactions.Actions;
6 | import org.testng.annotations.AfterMethod;
7 | import org.testng.annotations.BeforeMethod;
8 | import org.testng.annotations.Test;
9 |
10 | public class PopupAndAlertsExamples {
11 |
12 |
13 | WebDriver driver;
14 |
15 | @BeforeMethod
16 | public void beforeMethod() {
17 | driver = WebDriverFactory.getDriver("chrome");
18 | }
19 |
20 | @AfterMethod
21 | public void afterTest() {
22 | driver.quit();
23 | }
24 |
25 | @Test
26 | public void htmlPopup() throws InterruptedException {
27 | driver.get("https://www.primefaces.org/showcase/ui/overlay/confirmDialog.xhtml");
28 | WebElement button = driver.findElement(By.xpath("//span[text()='Destroy the World']"));
29 | button.click();
30 |
31 | Thread.sleep(1000);
32 | WebElement noooo = driver.findElement(By.xpath("//span[.='No']"));
33 | noooo.click();
34 | Thread.sleep(1000);
35 | }
36 |
37 | @Test
38 | public void jsAlertsAccept() {
39 | driver.get("http://practice.cybertekschool.com/javascript_alerts");
40 |
41 | WebElement button1 = driver.findElement(By.xpath("//button[1]"));
42 | button1.click();
43 |
44 | Alert alert = driver.switchTo().alert();
45 | alert.accept();
46 | }
47 |
48 | @Test
49 | public void jsAlertsCancel() {
50 | driver.get("http://practice.cybertekschool.com/javascript_alerts");
51 |
52 | WebElement button2 = driver.findElement(By.xpath("//button[2]"));
53 | button2.click();
54 |
55 | Alert alert = driver.switchTo().alert();
56 | alert.dismiss();
57 | }
58 |
59 | @Test
60 | public void jsAlertsSendkeys() {
61 | driver.get("http://practice.cybertekschool.com/javascript_alerts");
62 |
63 | WebElement button3 = driver.findElement(By.xpath("//button[3]"));
64 | // button3.click();
65 |
66 | Alert alert = null;
67 | try {
68 | alert = driver.switchTo().alert();
69 | alert.sendKeys("Admiral Kunkka");
70 | alert.accept();
71 |
72 | } catch (NoAlertPresentException e) {
73 | e.printStackTrace();
74 | }
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day12_pops_tabs_alerts_iframes/TabsAndWindowsExample.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day12_pops_tabs_alerts_iframes;
2 |
3 | import com.cybertek.utilities.WebDriverFactory;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 | import org.testng.annotations.AfterMethod;
8 | import org.testng.annotations.BeforeMethod;
9 | import org.testng.annotations.Test;
10 |
11 | import java.util.Set;
12 |
13 | public class TabsAndWindowsExample {
14 |
15 | WebDriver driver;
16 |
17 | @BeforeMethod
18 | public void beforeMethod() {
19 | driver = WebDriverFactory.getDriver("chrome");
20 | }
21 |
22 | @AfterMethod
23 | public void afterTest() {
24 | // driver.quit();
25 | }
26 |
27 | @Test
28 | public void test(){
29 | driver.get("http://practice.cybertekschool.com/windows");
30 | WebElement link = driver.findElement(By.linkText("Click Here"));
31 | link.click();
32 |
33 | // get all the available tabs
34 | Set windowHandles = driver.getWindowHandles();
35 |
36 | // print all the windows handles
37 | for (String windowHandle : windowHandles) {
38 | System.out.println(windowHandle);
39 | }
40 |
41 | // get the id of current window/tab
42 | String currentWindow = driver.getWindowHandle();
43 | System.out.println("currentWindow = " + currentWindow);
44 | System.out.println("BEFORE SWITCHING");
45 | System.out.println(driver.getTitle());
46 | System.out.println(driver.findElement(By.tagName("h3")).getText());
47 |
48 | for (String windowHandle : windowHandles) {
49 | driver.switchTo().window(windowHandle);
50 | if (driver.getTitle().equals("New Window")) {
51 | break;
52 | }
53 | }
54 |
55 | System.out.println("AFTER SWITCHING");
56 | System.out.println(driver.getTitle());
57 | System.out.println(driver.findElement(By.tagName("h3")).getText());
58 |
59 |
60 | }
61 |
62 | // write a utility that takes a String title,
63 | // changes to tab with given title,
64 | // if such title is not found, go back to original window
65 |
66 | // write a utility that takes a String url,
67 | // changes to tab with given url,
68 | // if such url is not found, go back to original window
69 | }
70 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day13_waits_and_synchronization/ExplicitWaitExamples.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day13_waits_and_synchronization;
2 |
3 | import com.cybertek.utilities.WebDriverFactory;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.ElementClickInterceptedException;
6 | import org.openqa.selenium.WebDriver;
7 | import org.openqa.selenium.WebElement;
8 | import org.openqa.selenium.support.ui.ExpectedConditions;
9 | import org.openqa.selenium.support.ui.FluentWait;
10 | import org.openqa.selenium.support.ui.Wait;
11 | import org.openqa.selenium.support.ui.WebDriverWait;
12 | import org.testng.Assert;
13 | import org.testng.annotations.AfterMethod;
14 | import org.testng.annotations.BeforeMethod;
15 | import org.testng.annotations.Test;
16 |
17 | import java.time.Duration;
18 | import java.util.NoSuchElementException;
19 | import java.util.concurrent.TimeUnit;
20 |
21 | public class ExplicitWaitExamples {
22 |
23 | WebDriver driver;
24 | // create web object
25 | WebDriverWait wait;
26 |
27 | @BeforeMethod
28 | public void setUp() {
29 | driver = WebDriverFactory.getDriver("firefox");
30 | wait = new WebDriverWait(driver, 10);
31 | }
32 |
33 | @AfterMethod
34 | public void tearDown() {
35 | driver.quit();
36 | }
37 |
38 | @Test
39 | public void test1TitleTest(){
40 | driver.get("https://google.com");
41 |
42 | System.out.println(driver.getTitle());
43 |
44 | driver.get("https://store.steampowered.com/");
45 |
46 | // wait for the title of the second page
47 |
48 | // start waiting for title contain text
49 | wait.until(ExpectedConditions.titleContains("Steam"));
50 |
51 | System.out.println(driver.getTitle());
52 |
53 | }
54 |
55 | @Test
56 | public void test2WaitForVisible(){
57 | driver.get("http://practice.cybertekschool.com/dynamic_loading/1");
58 |
59 | WebElement button = driver.findElement(By.tagName("button"));
60 | button.click();
61 |
62 | WebElement username = driver.findElement(By.id("username"));
63 | WebElement password = driver.findElement(By.id("pwd"));
64 |
65 | // waits for given element to be visible on page
66 | wait.until(ExpectedConditions.visibilityOf(username));
67 | // make sure that username is visible on page
68 | Assert.assertTrue(username.isDisplayed());
69 | username.sendKeys("johndoe");
70 | }
71 |
72 | // THIS WILL THROW EXCEPTION
73 | @Test
74 | public void test3WaitForVisibleFail(){
75 | driver.get("http://practice.cybertekschool.com/dynamic_loading/1");
76 |
77 | WebElement button = driver.findElement(By.tagName("button"));
78 | button.click();
79 |
80 | WebElement username = driver.findElement(By.id("username"));
81 | WebElement password = driver.findElement(By.id("pwd"));
82 |
83 | // give no,t enough time. change the wait time
84 | wait.withTimeout(Duration.ofSeconds(2));
85 |
86 | // waits for given element to be visible on page
87 | wait.until(ExpectedConditions.visibilityOf(username));
88 | // make sure that username is visible on page
89 | Assert.assertTrue(username.isDisplayed());
90 | username.sendKeys("johndoe");
91 | }
92 |
93 | @Test
94 | public void test4WaitForClickable(){
95 | driver.get("http://practice.cybertekschool.com/dynamic_loading/6");
96 |
97 | WebElement username = driver.findElement(By.id("username"));
98 | WebElement password = driver.findElement(By.id("pwd"));
99 | WebElement submit = driver.findElement(By.tagName("button"));
100 |
101 | Assert.assertTrue(username.isDisplayed());
102 | username.sendKeys("tomsmith");
103 | password.sendKeys("SuperSecretPassword");
104 |
105 | // wait for element to disappear.
106 | // wait until the overlay element disappears
107 | WebElement overlay = driver.findElement(By.className("loadingoverlay"));
108 | wait.until(ExpectedConditions.invisibilityOf(overlay));
109 |
110 | // waits for given element to be clickable
111 | wait.until(ExpectedConditions.elementToBeClickable(submit));
112 | submit.click();
113 |
114 | }
115 |
116 | @Test
117 | public void test4WaitForInvisible(){
118 | driver.manage().window().maximize();
119 | driver.get("http://qa3.vytrack.com");
120 | WebElement username = driver.findElement(By.id("prependedInput"));
121 | username.sendKeys("salesmanager110");
122 | WebElement password = driver.findElement(By.id("prependedInput2"));
123 | password.sendKeys("UserUser123");
124 | password.submit();
125 |
126 | driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
127 |
128 | WebElement myCalendar = driver.findElement(By.linkText("My Calendar"));
129 |
130 | // wait until the element with class loader-mask is not visible
131 |
132 | wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".loader-mask")));
133 | myCalendar.click();
134 |
135 | }
136 |
137 |
138 | @Test
139 | public void test5Fluent(){
140 |
141 | driver.get("http://practice.cybertekschool.com/dynamic_loading/6");
142 |
143 | Wait fluentWait = new FluentWait<>(driver).
144 | withTimeout(Duration.ofSeconds(10)).
145 | pollingEvery(Duration.ofSeconds(5)).
146 | ignoring(NoSuchElementException.class).
147 | ignoring(ElementClickInterceptedException.class);
148 |
149 |
150 | WebElement submitBtn = fluentWait.until(driver -> driver.findElement(By.xpath("//button[text()='Submit']")));
151 |
152 | driver.findElement(By.name("username")).sendKeys("tomsmith");
153 | driver.findElement(By.name("password")).sendKeys("SuperSecretPassword");
154 |
155 | submitBtn.click();
156 |
157 | }
158 |
159 | }
160 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day13_waits_and_synchronization/ImplicitWaitExamples.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day13_waits_and_synchronization;
2 |
3 | import com.cybertek.utilities.WebDriverFactory;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 | import org.testng.Assert;
8 | import org.testng.annotations.AfterMethod;
9 | import org.testng.annotations.BeforeMethod;
10 | import org.testng.annotations.Test;
11 |
12 | import java.util.concurrent.TimeUnit;
13 |
14 | public class ImplicitWaitExamples {
15 |
16 | WebDriver driver;
17 |
18 | @BeforeMethod
19 | public void setUp() {
20 | driver = WebDriverFactory.getDriver("chrome");
21 | driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
22 |
23 | }
24 |
25 | @AfterMethod
26 | public void tearDown() {
27 | driver.quit();
28 | }
29 |
30 |
31 | @Test
32 | public void test1(){
33 |
34 | driver.get("http://practice.cybertekschool.com/dynamic_loading/4");
35 |
36 | WebElement message = driver.findElement(By.cssSelector("#finish>h4"));
37 |
38 | Assert.assertTrue(message.isDisplayed());
39 | System.out.println(message.getText());
40 |
41 | driver.get("http://practice.cybertekschool.com/dynamic_loading/2");
42 | WebElement button = driver.findElement(By.tagName("button"));
43 | button.click();
44 |
45 | message = driver.findElement(By.cssSelector("#finish>h4"));
46 |
47 | Assert.assertTrue(message.isDisplayed());
48 | System.out.println(message.getText());
49 |
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day13_waits_and_synchronization/RandomStuff.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day13_waits_and_synchronization;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.support.ui.ExpectedConditions;
6 | import org.openqa.selenium.support.ui.WebDriverWait;
7 | import org.testng.Assert;
8 | import org.testng.annotations.Test;
9 |
10 | public class RandomStuff {
11 | WebDriver driver;
12 | WebDriverWait wait;
13 |
14 | @Test
15 | public void test() {
16 | // wait until title changes
17 | wait.until(ExpectedConditions.titleContains("Steam"));
18 |
19 | // verify the title
20 | Assert.assertTrue(driver.getTitle().contains("Steam"));
21 |
22 | // wait until title changes and get the boolean value at the end. use it in assertion
23 | Assert.assertTrue(wait.until(ExpectedConditions.titleContains("Steam")));
24 |
25 | Assert.assertTrue(wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id"))).isDisplayed());
26 |
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day13_waits_and_synchronization/ThreadSleepExample.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day13_waits_and_synchronization;
2 |
3 | import com.cybertek.utilities.WebDriverFactory;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 | import org.testng.Assert;
8 | import org.testng.annotations.AfterMethod;
9 | import org.testng.annotations.BeforeMethod;
10 | import org.testng.annotations.Test;
11 |
12 | public class ThreadSleepExample {
13 |
14 | WebDriver driver;
15 |
16 | @BeforeMethod
17 | public void setUp() {
18 | driver = WebDriverFactory.getDriver("chrome");
19 |
20 | }
21 |
22 | @AfterMethod
23 | public void tearDown() {
24 | driver.quit();
25 | }
26 |
27 | @Test
28 | public void test1() throws InterruptedException {
29 | driver.get("http://practice.cybertekschool.com/dynamic_loading/4");
30 |
31 | Thread.sleep(7000);
32 |
33 | WebElement message = driver.findElement(By.cssSelector("#finish>h4"));
34 |
35 | Assert.assertTrue(message.isDisplayed());
36 | System.out.println(message.getText());
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day13_waits_and_synchronization/VytrachLoginTestWithWait.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day13_waits_and_synchronization;
2 |
3 | import com.cybertek.utilities.WebDriverFactory;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 | import org.testng.Assert;
8 | import org.testng.annotations.AfterMethod;
9 | import org.testng.annotations.BeforeMethod;
10 | import org.testng.annotations.Test;
11 |
12 | import java.util.concurrent.TimeUnit;
13 |
14 | public class VytrachLoginTestWithWait {
15 | WebDriver driver;
16 |
17 | @BeforeMethod
18 | public void setUp() {
19 | driver = WebDriverFactory.getDriver("firefox");
20 | driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
21 |
22 | }
23 |
24 | @AfterMethod
25 | public void tearDown() {
26 | driver.quit();
27 | }
28 |
29 | @Test
30 | public void test() {
31 | driver.get("http://qa3.vytrack.com");
32 | WebElement username = driver.findElement(By.id("prependedInput"));
33 | username.sendKeys("salesmanager110");
34 | WebElement password = driver.findElement(By.id("prependedInput2"));
35 | password.sendKeys("UserUser123");
36 | password.submit();
37 |
38 |
39 | WebElement pageName = driver.findElement(By.cssSelector(".oro-subtitle"));
40 | Assert.assertEquals(pageName.getText(), "Dashboard");
41 |
42 | Assert.assertEquals(driver.getTitle(), "Dashboard");
43 | }
44 |
45 |
46 | @Test
47 | public void test2(){
48 | driver.get("http://practice.cybertekschool.com/dynamic_loading/3");
49 |
50 | WebElement input = driver.findElement(By.tagName("input"));
51 |
52 | input.sendKeys("t shirt");
53 | }
54 |
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day14_test_base_props_driver/FileUploadTests.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day14_test_base_props_driver;
2 |
3 | import com.cybertek.base.TestBase;
4 | import com.cybertek.utilities.ConfigurationReader;
5 | import org.openqa.selenium.By;
6 | import org.openqa.selenium.WebElement;
7 | import org.testng.Assert;
8 | import org.testng.annotations.Test;
9 |
10 | public class FileUploadTests extends TestBase {
11 | /*
12 | go to practice website
13 | click on file upload link
14 | upload a file
15 | click submit
16 | very file name is displayed in next page
17 | */
18 |
19 | @Test
20 | public void fileUploadTest() {
21 | String url = ConfigurationReader.getProperty("url");
22 | driver.get(url);
23 |
24 | WebElement file_upload = driver.findElement(By.linkText("File Upload"));
25 | file_upload.click();
26 |
27 | WebElement fileInput = driver.findElement(By.id("file-upload"));
28 |
29 | fileInput.sendKeys("/Users/marufjon/Desktop/my_file.txt");
30 |
31 | WebElement submit = driver.findElement(By.id("file-submit"));
32 | submit.click();
33 |
34 | WebElement uploadedFile = driver.findElement(By.id("uploaded-files"));
35 | Assert.assertEquals(uploadedFile.getText(), "my_file.txt");
36 |
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day14_test_base_props_driver/PropertiesExamples.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day14_test_base_props_driver;
2 |
3 | import com.cybertek.utilities.ConfigurationReader;
4 | import com.cybertek.utilities.WebDriverFactory;
5 | import org.openqa.selenium.WebDriver;
6 | import org.testng.annotations.Test;
7 |
8 | import java.util.Properties;
9 |
10 | public class PropertiesExamples {
11 |
12 | @Test
13 | public void test(){
14 |
15 | System.out.println(System.getProperty("os.name"));
16 | System.out.println(System.getProperty("os.version"));
17 | System.out.println(System.getProperty("user.home"));
18 | System.out.println(System.getProperty("user.name"));
19 |
20 | // browser url
21 | // Properties --> class from java that saves key value combinations
22 | Properties properties = new Properties();
23 | properties.setProperty("browser", "chrome");
24 | properties.setProperty("url", "http://practice.cybertekschool.com");
25 |
26 | String browser = properties.getProperty("browser");
27 | System.out.println("browser name= " + browser);
28 |
29 | // i need the browser/url from properties file
30 |
31 | String pBrowser = ConfigurationReader.getProperty("browser");
32 | System.out.println("pBrowser =" + pBrowser);
33 |
34 | String pUrl = ConfigurationReader.getProperty("url");
35 |
36 | System.out.println("pUrl = " + pUrl);
37 |
38 |
39 | }
40 |
41 | @Test
42 | public void test2(){
43 | WebDriver driver = WebDriverFactory.getDriver("chrome");
44 |
45 | // get the the from props file
46 | String url = ConfigurationReader.getProperty("url");
47 | driver.get(url);
48 | driver.close();
49 | String str = Singleton.getInstance().toUpperCase();
50 | System.out.println(str);
51 | }
52 |
53 | @Test
54 | public void test3(){
55 | String str = Singleton.getInstance();
56 | System.out.println(str);
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day14_test_base_props_driver/Singleton.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day14_test_base_props_driver;
2 |
3 | public class Singleton {
4 | // make constructor private
5 | private Singleton() {
6 | }
7 |
8 | private static String string;
9 |
10 | public static String getInstance() {
11 | if (string == null) {
12 | string = "chrome";
13 | }
14 | return string;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day14_test_base_props_driver/TestingTestBaseTests.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day14_test_base_props_driver;
2 |
3 | import com.cybertek.base.TestBase;
4 | import com.cybertek.utilities.ConfigurationReader;
5 | import org.testng.Assert;
6 | import org.testng.annotations.Test;
7 |
8 | public class TestingTestBaseTests extends TestBase {
9 |
10 | @Test
11 | public void testTitle() {
12 | String url = ConfigurationReader.getProperty("url");
13 | driver.get(url);
14 |
15 | Assert.assertEquals(driver.getTitle(), "Practice");
16 | System.out.println(driver.getTitle());
17 | System.out.println(driver.getCurrentUrl());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day15_webtables/WebTablesTests.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day15_webtables;
2 |
3 | import com.cybertek.base.TestBase;
4 | import com.cybertek.utilities.BrowserUtils;
5 | import com.cybertek.utilities.ConfigurationReader;
6 | import org.openqa.selenium.By;
7 | import org.openqa.selenium.WebElement;
8 | import org.testng.Assert;
9 | import org.testng.annotations.BeforeMethod;
10 | import org.testng.annotations.Test;
11 |
12 | import java.util.List;
13 |
14 | public class WebTablesTests extends TestBase {
15 |
16 | @BeforeMethod
17 | public void setUpTest() {
18 | String url = ConfigurationReader.getProperty("url");
19 | driver.get(url);
20 | driver.findElement(By.linkText("Sortable Data Tables")).click();
21 |
22 | }
23 |
24 | // GET WHOLE TABLE
25 | @Test
26 | public void printTable() {
27 | WebElement myTable = driver.findElement(By.id("table1"));
28 | System.out.println(myTable.getText());
29 | }
30 |
31 | // GET ALL HEADERS
32 | @Test
33 | public void getHeaders() {
34 | // get all headers in a single element
35 | WebElement header = driver.findElement(By.tagName("thead"));
36 | System.out.println(header.getText());
37 |
38 | // get all headers in a list
39 | List headers = driver.findElements(By.xpath("//table[@id='table1']//th"));
40 | System.out.println(headers.size());
41 | // use BrowserUtils to get the list of headers as text and print
42 | System.out.println(BrowserUtils.getElementsText(headers));
43 |
44 | }
45 |
46 | // GET table size
47 | @Test
48 | public void getTableSize() {
49 | // get number of cols
50 | List headers = driver.findElements(By.xpath("//table[@id='table1']//th"));
51 | System.out.println("Number columns: " + headers.size());
52 |
53 | // get number of rows including header
54 | List rowsWithHeader = driver.findElements(By.xpath("//table[@id='table1']//tr"));
55 | System.out.println("Number of row with header: " + rowsWithHeader.size());
56 |
57 | // get number of rows without header
58 | List rowsWithOutHeader = driver.findElements(By.xpath("//table[@id='table1']/tbody/tr"));
59 | System.out.println("Number of row without header: " + rowsWithOutHeader.size());
60 |
61 | }
62 |
63 | // GET SINGLE ROW BY INDEX
64 | @Test
65 | public void getSingleRowByIndex() {
66 | // get the first row (in the body)
67 | WebElement row = driver.findElement(By.xpath("//table[@id='table1']/tbody/tr[1]"));
68 | System.out.println(row.getText());
69 |
70 | // get the first row (in the body) dynamic xpath
71 | String xpath = getTableRowXpath(3);
72 | row = driver.findElement(By.xpath(xpath));
73 | System.out.println(row.getText());
74 |
75 | }
76 |
77 | // getTableRowXpath based on index
78 | public static String getTableRowXpath(int index) {
79 | String xpath = "//table[@id='table1']/tbody/tr[" + index + "]";
80 | return xpath;
81 | }
82 |
83 | // GET SINGLE CELL BASED ON INDEX
84 | @Test
85 | public void getSingleBasedByIndex() {
86 | WebElement cell = driver.findElement(By.xpath("//table[@id='table1']/tbody/tr[1]/td[1]"));
87 | System.out.println(cell.getText());
88 |
89 | String xpath = getCellXpathByIndex(2, 3);
90 | cell = driver.findElement(By.xpath(xpath));
91 | System.out.println(cell.getText());
92 | }
93 |
94 | public static String getCellXpathByIndex(int row, int column) {
95 | String xpath = "//table[@id='table1']/tbody/tr[" + row + "]/td[" + column + "]";
96 | return xpath;
97 | }
98 |
99 |
100 | // GO THROUGH THE TABLE USING LOOPS AND GET ALL VALUES
101 | @Test
102 | public void iterateTheTableUsingLoops() {
103 | // get the number of rows
104 | int rowCount = getRowCount();
105 | // get the number of cols
106 | int colCount = getColCount();
107 |
108 | for (int i = 1; i <= rowCount; i++) {
109 | for (int j = 1; j <= colCount; j++) {
110 | String xpath = getCellXpathByIndex(i, j);
111 | WebElement cell = driver.findElement(By.xpath(xpath));
112 | System.out.println(cell.getText());
113 | }
114 | }
115 | }
116 |
117 | // returns number of rows excluding the table headers
118 | public int getRowCount() {
119 | return driver.findElements(By.xpath("//table[@id='table1']/tbody/tr")).size();
120 | }
121 |
122 | // return number of rows
123 | public int getColCount() {
124 | return driver.findElements(By.xpath("//table[@id='table1']//th")).size();
125 |
126 | }
127 |
128 | // GET CELL IN RELATION TO ANOTHER CELL
129 | // verify that Jason owes me $100.00
130 | @Test
131 | public void verifyCellValueByOtherCell(){
132 | String firstName = "Jason";
133 |
134 | String xpath = "//table[@id='table1']//td[2][.='"+firstName+"']/../td[4]";
135 | WebElement amount = driver.findElement(By.xpath(xpath));
136 | Assert.assertEquals(amount.getText(), "$100.00");
137 | }
138 |
139 | // from Kateryna Medvedieva
140 | public String getXpathForValue(String value, String columnIdx){
141 | String xpath = "/table[@id='table1']//td[.='" + value + "']/../td[" + columnIdx + "]";
142 | return xpath;
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day16_page_object_model/NegativeLoginTests.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day16_page_object_model;
2 |
3 | import com.cybertek.base.TestBase;
4 | import com.cybertek.pages.LoginPage;
5 | import com.cybertek.utilities.ConfigurationReader;
6 | import org.testng.Assert;
7 | import org.testng.annotations.BeforeMethod;
8 | import org.testng.annotations.Test;
9 |
10 | public class NegativeLoginTests extends TestBase {
11 |
12 | LoginPage loginPage;
13 |
14 | @BeforeMethod
15 | public void setUpTests() {
16 | driver.get(ConfigurationReader.getProperty("vytrack_url"));
17 | loginPage = new LoginPage();
18 |
19 | }
20 |
21 | @Test
22 | public void wrongUsernameTest() {
23 | loginPage.username.sendKeys("user30000");
24 | loginPage.password.sendKeys("UserUser123");
25 | loginPage.logIn.click();
26 |
27 | String actual = loginPage.errorMessage.getText();
28 |
29 | Assert.assertTrue(loginPage.errorMessage.isDisplayed());
30 | Assert.assertEquals(actual, "Invalid user name or password.");
31 | }
32 |
33 | @Test
34 | public void wrongPasswordTest() {
35 | loginPage.username.sendKeys("SalesManager110");
36 | loginPage.password.sendKeys("LC");
37 | loginPage.logIn.click();
38 |
39 | String actual = loginPage.errorMessage.getText();
40 | Assert.assertEquals(actual, "Invalid user name or password.");
41 | Assert.assertTrue(loginPage.errorMessage.isDisplayed());
42 |
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day16_page_object_model/PageHeadersTests.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day16_page_object_model;
2 |
3 | import com.cybertek.base.VytrackTestBase;
4 | import com.cybertek.utilities.ConfigurationReader;
5 | import org.openqa.selenium.support.ui.ExpectedConditions;
6 | import org.testng.annotations.Test;
7 |
8 | import static org.testng.Assert.assertEquals;
9 |
10 |
11 | public class PageHeadersTests extends VytrackTestBase {
12 | // go to vyrack
13 | // login as driver
14 | // verify header is "Quick Launchpad"
15 |
16 | @Test
17 | public void dashboardPageTest(){
18 |
19 | test = report.createTest("Dashboard page title test");
20 |
21 | String username = ConfigurationReader.getProperty("driver_username");
22 | String password = ConfigurationReader.getProperty("driver_password");
23 | test.info("Logging in to application");
24 | loginPage.login(username, password);
25 |
26 | wait.until(ExpectedConditions.textToBePresentInElement(dashboardPage.pageHeader, "Quick Launchpad"));
27 | String actual = dashboardPage.pageHeader.getText();
28 | test.info("Verifying page header text");
29 | assertEquals(actual, "Quick Launchpad");
30 | test.pass("PASS: Dashboard page title test");
31 |
32 | }
33 |
34 |
35 | // go to vyrack
36 | // go to Fleet vehicles
37 | // login as driver
38 | // verify header is "Cars"
39 |
40 | @Test
41 | public void fleetVehiclesTest() throws InterruptedException {
42 | test = report.createTest("Vehicles page title test");
43 |
44 | // use login to login
45 | String username = ConfigurationReader.getProperty("driver_username");
46 | String password = ConfigurationReader.getProperty("driver_password");
47 | test.info("Logging in to application");
48 | test.info("Username: " + username);
49 | test.info("Password: " + password);
50 | loginPage.login(username, password);
51 | // use dashbaord change page
52 |
53 | test.info("Going to Fleet -> Vehicles");
54 | wait.until(ExpectedConditions.elementToBeClickable(dashboardPage.fleet));
55 | dashboardPage.fleet.click();
56 | wait.until(ExpectedConditions.elementToBeClickable(dashboardPage.vehicles));
57 | dashboardPage.vehicles.click();
58 |
59 | // use the fllet / vehicles page to get text
60 | wait.until(ExpectedConditions.textToBePresentInElement(vehiclesPage.pageHeader, "Cars"));
61 | test.info("Verifying page header");
62 | String actual = vehiclesPage.pageHeader.getText();
63 | assertEquals(actual, "Carros");
64 | test.pass("PASS: Vehicles page title test");
65 |
66 | }
67 |
68 | // go to vyrack
69 | // go to Customer Contacts
70 | // login as driver
71 | // verify header is "Cars"
72 |
73 | @Test
74 | public void customersContacts() throws InterruptedException {
75 | test = report.createTest("Contacts page title test");
76 |
77 | // use login to login
78 | String username = ConfigurationReader.getProperty("driver_username");
79 | String password = ConfigurationReader.getProperty("driver_password");
80 | test.info("Logging in to application");
81 | test.info("Username: " + username);
82 | test.info("Password: " + password);
83 | loginPage.login(username, password);
84 | // use dashbaord change page
85 |
86 | test.info("Going to Customers -> Contacts");
87 | dashboardPage.changeMenu("Customers", "Contacts");
88 |
89 | // use the fllet / vehicles page to get text
90 | wait.until(ExpectedConditions.textToBePresentInElement(vehiclesPage.pageHeader, "Contacts"));
91 | test.info("Verifying page header");
92 | String actual = vehiclesPage.pageHeader.getText();
93 | assertEquals(actual, "Contacts");
94 | test.pass("PASS: Contacts page title test");
95 |
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day16_page_object_model/PositiveLoginTests.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day16_page_object_model;
2 |
3 | import com.cybertek.base.TestBase;
4 | import com.cybertek.pages.LoginPage;
5 | import com.cybertek.utilities.ConfigurationReader;
6 | import org.openqa.selenium.support.ui.ExpectedConditions;
7 | import org.openqa.selenium.support.ui.WebDriverWait;
8 | import org.testng.annotations.BeforeMethod;
9 | import org.testng.annotations.Test;
10 |
11 | import static org.testng.Assert.*;
12 |
13 | public class PositiveLoginTests extends TestBase {
14 |
15 | LoginPage loginPage;
16 | WebDriverWait wait;
17 |
18 | @BeforeMethod
19 | public void setUpTests() {
20 | driver.get(ConfigurationReader.getProperty("vytrack_url"));
21 | loginPage = new LoginPage();
22 | wait = new WebDriverWait(driver, 5);
23 |
24 | }
25 |
26 | @Test
27 | public void loginAsDrivers(){
28 | String username = ConfigurationReader.getProperty("driver_username");
29 | String password = ConfigurationReader.getProperty("driver_password");
30 | loginPage.login(username, password);
31 | wait.until(ExpectedConditions.titleIs("Dashboard"));
32 | String actualTitle = driver.getTitle();
33 | assertEquals(actualTitle, "Dashboard");
34 |
35 | }
36 |
37 | @Test
38 | public void loginAsSalesManger(){
39 | String username = ConfigurationReader.getProperty("sales_manager_username");
40 | String password = ConfigurationReader.getProperty("sales_manager_password");
41 | loginPage.login(username, password);
42 | wait.until(ExpectedConditions.titleIs("Dashboard"));
43 | String actualTitle = driver.getTitle();
44 | assertEquals(actualTitle, "Dashboard");
45 |
46 | }
47 |
48 | @Test
49 | public void loginAsStoreManager(){
50 | String username = ConfigurationReader.getProperty("store_manager_username");
51 | String password = ConfigurationReader.getProperty("store_manager_password");
52 | loginPage.login(username, password);
53 |
54 | wait.until(ExpectedConditions.titleIs("Dashboard"));
55 | assertEquals(driver.getTitle(), "Dashboard");
56 |
57 | }
58 |
59 |
60 |
61 |
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day17_ddt_dataprovider_pom2/CreateCalendarEventTests.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day17_ddt_dataprovider_pom2;
2 |
3 | import com.cybertek.base.VytrackTestBase;
4 | import com.cybertek.utilities.ConfigurationReader;
5 | import org.testng.annotations.Test;
6 |
7 | import static org.testng.Assert.assertFalse;
8 |
9 | public class CreateCalendarEventTests extends VytrackTestBase {
10 |
11 | @Test
12 | public void allDayEventCheckBoxTest(){
13 | loginPage.login(ConfigurationReader.getProperty("driver_username"),
14 | ConfigurationReader.getProperty("driver_password"));
15 | driver.get("https://qa3.vytrack.com/calendar/event/create");
16 | assertFalse(createCalendarEventsPage.allDayEventCheckbox.isSelected());
17 |
18 | }
19 |
20 | @Test
21 | public void repeatCheckBoxTest(){
22 | loginPage.login(ConfigurationReader.getProperty("driver_username"),
23 | ConfigurationReader.getProperty("driver_password"));
24 | driver.get("https://qa3.vytrack.com/calendar/event/create");
25 | assertFalse(createCalendarEventsPage.repeatCheckbox.isSelected());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day17_ddt_dataprovider_pom2/MenuOptionsTests.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day17_ddt_dataprovider_pom2;
2 |
3 | import com.cybertek.base.VytrackTestBase;
4 | import com.cybertek.utilities.BrowserUtils;
5 | import com.cybertek.utilities.ConfigurationReader;
6 | import org.openqa.selenium.support.ui.ExpectedConditions;
7 | import org.testng.Assert;
8 | import org.testng.annotations.DataProvider;
9 | import org.testng.annotations.Test;
10 |
11 | import java.util.Arrays;
12 | import java.util.List;
13 |
14 | import static org.testng.Assert.assertEquals;
15 | import static org.testng.Assert.assertTrue;
16 |
17 | public class MenuOptionsTests extends VytrackTestBase {
18 |
19 |
20 | @Test
21 | public void test() {
22 | loginPage.login(ConfigurationReader.getProperty("driver_username"),
23 | ConfigurationReader.getProperty("driver_password"));
24 | dashboardPage.changeMenu("Activities", "Calendar Events");
25 | wait.until(ExpectedConditions.titleIs("Calendar Events - Activities"));
26 | assertEquals(driver.getTitle(), "Calendar Events - Activities");
27 |
28 | }
29 |
30 | // DDT test
31 | @Test(dataProvider = "test-data")
32 | public void ddtTest(String menu1, String menu2, String expectedTitle){
33 | loginPage.login(ConfigurationReader.getProperty("driver_username"),
34 | ConfigurationReader.getProperty("driver_password"));
35 | dashboardPage.changeMenu(menu1, menu2);
36 | wait.until(ExpectedConditions.titleContains(expectedTitle));
37 | assertTrue(driver.getTitle().contains(expectedTitle));
38 |
39 | }
40 |
41 | @DataProvider(name = "test-data")
42 | public Object[][] getData(){
43 | return new Object[][]{
44 | {"Fleet", "Vehicles", "Car"},
45 | {"Fleet", "Vehicle Costs", "Vehicle Costs"},
46 | {"Customers", "Contacts", "Contacts - Customers"},
47 | {"Activities", "Calendar Events", "Calendar Events - Activities"},
48 | {"System", "System Calendars", "System Calendars - System"}
49 | };
50 | }
51 |
52 | // login as driver
53 | // verify that driven can see menu options Fleet, Customers, Activities, System
54 |
55 | @Test
56 | public void testAllOptionsDriver(){
57 | loginPage.login(ConfigurationReader.getProperty("driver_username"),
58 | ConfigurationReader.getProperty("driver_password"));
59 | List expected = Arrays.asList("Fleet", "Customers", "Activities", "System");
60 | List actualList = BrowserUtils.getElementsText(dashboardPage.menu1Options);
61 | assertEquals(actualList, expected);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day17_ddt_dataprovider_pom2/UserInfoDataDrivenTests.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day17_ddt_dataprovider_pom2;
2 |
3 | import org.testng.annotations.DataProvider;
4 | import org.testng.annotations.Test;
5 |
6 | public class UserInfoDataDrivenTests {
7 |
8 | @Test(dataProvider = "users")
9 | public void test(String username, String password, int number) {
10 | System.out.println("opening application");
11 | System.out.println("login as: " + username);
12 | System.out.println("number is: " + number);
13 | System.out.println("verify info");
14 | }
15 |
16 | @DataProvider(name = "users")
17 | public Object[][] getUsers() {
18 | return new Object[][]
19 | {
20 | {"user1", "UserUser123", 25},
21 | {"salesmanager355", "UserUser123", 26},
22 | {"storemanager355", "UserUser123", 236},
23 | {"salesmanager4000", "UserUser123", 262},
24 | };
25 | }
26 |
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day17_ddt_dataprovider_pom2/UserInfoDataDrivenTests2.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day17_ddt_dataprovider_pom2;
2 |
3 | import com.cybertek.base.VytrackTestBase;
4 | import com.cybertek.pages.LoginPage;
5 | import org.apache.commons.lang3.exception.ExceptionContext;
6 | import org.openqa.selenium.support.ui.ExpectedConditions;
7 | import org.testng.annotations.DataProvider;
8 | import org.testng.annotations.Test;
9 |
10 | import static org.testng.Assert.assertEquals;
11 |
12 | public class UserInfoDataDrivenTests2 extends VytrackTestBase {
13 |
14 | @Test(dataProvider = "usersList")
15 | public void test(String username, String password, String expectedName){
16 | loginPage.login(username, password);
17 | wait.until(ExpectedConditions.titleIs("Dashboard"));
18 | String actualName = dashboardPage.accountHolderName.getText();
19 | assertEquals(actualName, expectedName);
20 |
21 | }
22 |
23 | @DataProvider(name = "usersList")
24 | public Object[][] getUsers() {
25 | return new Object[][]
26 | {
27 | {"user1", "UserUser123", "John Doe"},
28 | {"user2", "UserUser123", "John Doe"},
29 | {"user3", "UserUser123", "John Doe"},
30 | {"user4", "UserUser123", "Kyleigh Reichert"},
31 | {"user5", "UserUser123", "Nona Carroll"},
32 | {"user6", "UserUser123", "Raphael Gusikowski"},
33 | {"user7", "UserUser123", "Dominique Deckow"},
34 | {"user8", "UserUser123", "Valentine Bode"},
35 | {"user9", "UserUser123", "Deborah Wolf"},
36 | {"user10", "UserUser123", "Toney Hegmann"},
37 | };
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day18_html_report/ExtentReportExample.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day18_html_report;
2 |
3 | import com.aventstack.extentreports.ExtentReports;
4 | import com.aventstack.extentreports.ExtentTest;
5 | import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
6 | import org.testng.annotations.AfterMethod;
7 | import org.testng.annotations.BeforeMethod;
8 | import org.testng.annotations.Test;
9 |
10 | public class ExtentReportExample {
11 |
12 | // used to set up a new report and build the reports
13 | ExtentReports report;
14 |
15 | // used to create the html report
16 | ExtentHtmlReporter htmlReporter;
17 |
18 | // used to define a test in report, do logging, mark test results
19 | ExtentTest test;
20 |
21 | @BeforeMethod
22 | public void setUp(){
23 | // initialize the report
24 | report = new ExtentReports();
25 |
26 | // i need to point to the location where report will be create
27 | // System.getProperty("user.dir") --> gets my current folder
28 | // + "/test-output/report.html" --> create folder test-output and in it create file report.html
29 | String path = System.getProperty("user.dir")+"/test-output/report.html";
30 | // initialize the html reporter with the given path
31 | htmlReporter = new ExtentHtmlReporter(path);
32 |
33 | // set name for the report
34 | htmlReporter.config().setReportName("Vytrack Automated Tests");
35 |
36 | // attach the html reporter to the report object
37 | report.attachReporter(htmlReporter);
38 |
39 | // set environment information
40 | report.setSystemInfo("Environment", "QA");
41 | report.setSystemInfo("Browser", "Chrome");
42 |
43 | }
44 |
45 | @Test
46 | public void test(){
47 | // we have to create a test for every test case
48 | test = report.createTest("VYT-123 Title verification test");
49 | test.info("Opening browser");
50 | // driver = new Chromedriver
51 | test.info("going to website");
52 | // driver.get(goole.com)
53 | test.info("verifying title");
54 | // assertEquals(google, google)
55 | test.pass("VYT-123 Title verification test");
56 |
57 | }
58 |
59 | @AfterMethod
60 | public void tearDown(){
61 | // the report will be created when we call this line.
62 | // if we dont call flush method it will not be generated.
63 | // we do this at the end of everything.
64 | report.flush();
65 | }
66 |
67 |
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/test/java/com/cybertek/tests/day19_excel_io/ExcelUtilityDemo.java:
--------------------------------------------------------------------------------
1 | package com.cybertek.tests.day19_excel_io;
2 |
3 |
4 | import com.cybertek.utilities.ExcelUtil;
5 | import org.testng.annotations.Test;
6 |
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | public class ExcelUtilityDemo {
11 | private String filePath = "src/test/resources/Vytrack testusers.xlsx";
12 | private String sheetName = "QA3-short";
13 | @Test
14 | public void test() {
15 |
16 | ExcelUtil qa3Short = new ExcelUtil(filePath, sheetName);
17 | System.out.println(qa3Short.getColumnsNames());
18 |
19 | String data [][] = qa3Short.getDataArray();
20 | List