├── .idea ├── .gitignore ├── encodings.xml ├── misc.xml └── uiDesigner.xml ├── resources └── screenshots │ ├── (2024-08-06) testProgressBar.png │ ├── (2024-08-06) testSliderResult.png │ ├── (2024-08-04) testVisibleAfterButtonText.png │ ├── (2024-08-07) testApplicationUsingKeyboard.png │ └── (2024-08-03) testClickingSubmitButtonWithoutJavaScriptExecutor.png ├── src ├── test │ └── java │ │ ├── part3_4 │ │ └── com │ │ │ └── demoqa │ │ │ ├── tests │ │ │ ├── part3 │ │ │ │ ├── javascript │ │ │ │ │ └── JavaScriptTest.java │ │ │ │ ├── forms │ │ │ │ │ ├── RadioButtonTest.java │ │ │ │ │ └── CheckboxTest.java │ │ │ │ ├── elements │ │ │ │ │ ├── LinksTest.java │ │ │ │ │ └── WebTableTest.java │ │ │ │ └── widgets │ │ │ │ │ ├── DateTest.java │ │ │ │ │ └── SelectDropDownTests.java │ │ │ └── part4 │ │ │ │ ├── screenshot │ │ │ │ └── CaptureFailedScreenshotTest.java │ │ │ │ ├── interactions │ │ │ │ ├── SliderTest.java │ │ │ │ └── KeyboardTest.java │ │ │ │ ├── modals │ │ │ │ └── ModalTest.java │ │ │ │ ├── windows │ │ │ │ └── WindowsTest.java │ │ │ │ ├── dynamic_wait │ │ │ │ └── DynamicWaitTests.java │ │ │ │ ├── frames │ │ │ │ └── FramesTest.java │ │ │ │ └── alerts │ │ │ │ └── AlertsTest.java │ │ │ └── base │ │ │ └── BaseTest.java │ │ ├── part2 │ │ └── com │ │ │ └── saucedemo │ │ │ ├── tests │ │ │ ├── login │ │ │ │ └── LoginTests.java │ │ │ └── products │ │ │ │ └── ProductsTest.java │ │ │ └── base │ │ │ └── BaseTest.java │ │ └── part1 │ │ ├── FirstSeleniumTest.java │ │ └── LogInShouldFailTest.java └── main │ └── java │ ├── utilities │ ├── Utility.java │ ├── ActionsUtility.java │ ├── GetUtility.java │ ├── JavaScriptUtility.java │ ├── WaitUtility.java │ ├── SwitchToUtility.java │ └── DropDownUtility.java │ └── com │ ├── saucedemo │ └── pages │ │ ├── ProductsPage.java │ │ └── LoginPage.java │ ├── demoqa │ └── pages │ │ ├── forms │ │ ├── FormsPage.java │ │ └── PracticeFormPage.java │ │ ├── elements │ │ ├── LinksPage.java │ │ ├── DynamicPropertiesPage.java │ │ ├── WebTablesPage.java │ │ ├── ElementsPage.java │ │ └── TextBoxPage.java │ │ ├── widgets │ │ ├── ProgressBarPage.java │ │ ├── SliderPage.java │ │ ├── SelectMenuPage.java │ │ ├── WidgetsPage.java │ │ └── DatePickerMenuPage.java │ │ ├── alerts_frames_windows │ │ ├── ModalDialogsPage.java │ │ ├── AlertsPage.java │ │ ├── BrowserWindowsPage.java │ │ ├── FramesPage.java │ │ └── Alerts_Frames_WindowsPage.java │ │ └── HomePage.java │ └── base │ └── BasePage.java ├── .gitignore └── pom.xml /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /resources/screenshots/(2024-08-06) testProgressBar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RexJonesII/FreeCodeCampSeleniumJava/HEAD/resources/screenshots/(2024-08-06) testProgressBar.png -------------------------------------------------------------------------------- /resources/screenshots/(2024-08-06) testSliderResult.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RexJonesII/FreeCodeCampSeleniumJava/HEAD/resources/screenshots/(2024-08-06) testSliderResult.png -------------------------------------------------------------------------------- /resources/screenshots/(2024-08-04) testVisibleAfterButtonText.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RexJonesII/FreeCodeCampSeleniumJava/HEAD/resources/screenshots/(2024-08-04) testVisibleAfterButtonText.png -------------------------------------------------------------------------------- /resources/screenshots/(2024-08-07) testApplicationUsingKeyboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RexJonesII/FreeCodeCampSeleniumJava/HEAD/resources/screenshots/(2024-08-07) testApplicationUsingKeyboard.png -------------------------------------------------------------------------------- /resources/screenshots/(2024-08-03) testClickingSubmitButtonWithoutJavaScriptExecutor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RexJonesII/FreeCodeCampSeleniumJava/HEAD/resources/screenshots/(2024-08-03) testClickingSubmitButtonWithoutJavaScriptExecutor.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/tests/part3/javascript/JavaScriptTest.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.tests.part3.javascript; 2 | 3 | import org.testng.annotations.Test; 4 | import part3_4.com.demoqa.base.BaseTest; 5 | 6 | public class JavaScriptTest extends BaseTest { 7 | 8 | @Test 9 | public void testScrollingToElement() { 10 | homePage.goToForms(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/utilities/Utility.java: -------------------------------------------------------------------------------- 1 | package utilities; 2 | 3 | import com.base.BasePage; 4 | import org.openqa.selenium.WebDriver; 5 | 6 | public class Utility { 7 | 8 | public static WebDriver driver; 9 | 10 | public static void setUtilityDriver() { 11 | driver = BasePage.driver; 12 | } 13 | 14 | // Generate A Random Number 15 | 16 | // Return Strings To UpperCase 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/saucedemo/pages/ProductsPage.java: -------------------------------------------------------------------------------- 1 | package com.saucedemo.pages; 2 | 3 | import com.base.BasePage; 4 | import org.openqa.selenium.By; 5 | 6 | public class ProductsPage extends BasePage { 7 | 8 | private By productsHeader = By.xpath("//span[text()='Products']"); 9 | 10 | public boolean isProductsHeaderDisplayed() { 11 | return find(productsHeader).isDisplayed(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/tests/part4/screenshot/CaptureFailedScreenshotTest.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.tests.part4.screenshot; 2 | 3 | import org.testng.annotations.Test; 4 | import part3_4.com.demoqa.base.BaseTest; 5 | 6 | public class CaptureFailedScreenshotTest extends BaseTest { 7 | 8 | @Test 9 | public void testClickingSubmitButtonWithoutJavaScriptExecutor() { 10 | var practiceFormPage = homePage.goToForms().clickPracticeForm(); 11 | practiceFormPage.clickSubmitButton(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/forms/FormsPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.forms; 2 | 3 | import com.demoqa.pages.HomePage; 4 | import org.openqa.selenium.By; 5 | 6 | import static utilities.JavaScriptUtility.scrollToElementJS; 7 | 8 | public class FormsPage extends HomePage { 9 | 10 | private By practiceFormMenuItem = By.xpath("//li[@id='item-0']/span[text()='Practice Form']"); 11 | 12 | public PracticeFormPage clickPracticeForm() { 13 | scrollToElementJS(practiceFormMenuItem); 14 | click(practiceFormMenuItem); 15 | return new PracticeFormPage(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/utilities/ActionsUtility.java: -------------------------------------------------------------------------------- 1 | package utilities; 2 | 3 | import org.openqa.selenium.WebElement; 4 | import org.openqa.selenium.interactions.Actions; 5 | 6 | public class ActionsUtility extends Utility { 7 | 8 | private static Actions act() { 9 | return new Actions(driver); 10 | } 11 | 12 | public static void dragAndDropBy(WebElement source, int x, int y) { 13 | act().dragAndDropBy(source, x, y).perform(); 14 | } 15 | 16 | public static void sendKeys(WebElement source, CharSequence keys) { 17 | act().sendKeys(source, keys).perform(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/part2/com/saucedemo/tests/login/LoginTests.java: -------------------------------------------------------------------------------- 1 | package part2.com.saucedemo.tests.login; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | import part2.com.saucedemo.base.BaseTest; 6 | 7 | public class LoginTests extends BaseTest { 8 | 9 | @Test 10 | public void testLoginErrorMessage() { 11 | loginPage.setUsername("standard_user"); 12 | loginPage.setPassword("xyz3400"); 13 | loginPage.clickLoginButton(); 14 | String actualMessage = loginPage.getErrorMessage(); 15 | Assert.assertTrue(actualMessage.contains("Epic sadface")); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/elements/LinksPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.elements; 2 | 3 | import org.openqa.selenium.By; 4 | 5 | import static utilities.JavaScriptUtility.scrollToElementJS; 6 | 7 | public class LinksPage extends ElementsPage { 8 | 9 | private By badRequestLink = By.id("bad-request"); 10 | private By responseLink = By.id("linkResponse"); 11 | 12 | public void clickBadRequestLink() { 13 | scrollToElementJS(badRequestLink); 14 | click(badRequestLink); 15 | } 16 | 17 | public String getResponse() { 18 | delay(2000); 19 | return find(responseLink).getText(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/elements/DynamicPropertiesPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.elements; 2 | 3 | import org.openqa.selenium.By; 4 | 5 | import static utilities.GetUtility.getText; 6 | import static utilities.WaitUtility.*; 7 | 8 | public class DynamicPropertiesPage extends ElementsPage { 9 | 10 | private By visibleAfterButton = By.id("visibleAfter"); 11 | 12 | public String getVisibleAfterButtonText() { 13 | explicitWaitUntilVisible(5, visibleAfterButton); 14 | String visibleText = getText(visibleAfterButton); 15 | System.out.println("Button Text: " + visibleText); 16 | return visibleText; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/part2/com/saucedemo/tests/products/ProductsTest.java: -------------------------------------------------------------------------------- 1 | package part2.com.saucedemo.tests.products; 2 | 3 | import com.saucedemo.pages.ProductsPage; 4 | import static org.testng.Assert.*; 5 | import org.testng.annotations.Test; 6 | import part2.com.saucedemo.base.BaseTest; 7 | 8 | public class ProductsTest extends BaseTest { 9 | 10 | @Test 11 | public void testProductsHeaderIsDisplayed() { 12 | ProductsPage productsPage = loginPage. 13 | logIntoApplication("standard_user", "secret_sauce"); 14 | assertTrue(productsPage.isProductsHeaderDisplayed(), 15 | "\n Products Header Is Not Displayed \n"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/tests/part3/forms/RadioButtonTest.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.tests.part3.forms; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | import part3_4.com.demoqa.base.BaseTest; 6 | 7 | public class RadioButtonTest extends BaseTest { 8 | 9 | @Test 10 | public void testRadioButton() { 11 | var formsPage = homePage.goToForms().clickPracticeForm(); 12 | formsPage.clickFemaleRadioButton(); 13 | boolean isFemaleRadioButtonSelected = formsPage.isFemaleSelected(); 14 | Assert.assertTrue(isFemaleRadioButtonSelected, 15 | "\n Female Radio Button Is Not Selected \n"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/widgets/ProgressBarPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.widgets; 2 | 3 | import org.openqa.selenium.By; 4 | 5 | import static utilities.GetUtility.getText; 6 | import static utilities.WaitUtility.fluentWaitUntilVisible; 7 | 8 | public class ProgressBarPage extends WidgetsPage { 9 | 10 | private By startButton = By.id("startStopButton"); 11 | private By progressValue = By.xpath("//div[@id='progressBar']/div[@aria-valuenow='100']"); 12 | 13 | public String getProgressValue() { 14 | fluentWaitUntilVisible(30, progressValue); 15 | return getText(progressValue); 16 | } 17 | 18 | public void clickStartButton() { 19 | click(startButton); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/tests/part4/interactions/SliderTest.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.tests.part4.interactions; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | import part3_4.com.demoqa.base.BaseTest; 6 | 7 | public class SliderTest extends BaseTest { 8 | 9 | @Test 10 | public void testSliderResult() { 11 | int x = 180; 12 | int y = 0; 13 | var sliderPage = homePage.goToWidgets().clickSlider(); 14 | sliderPage.moveSlider(x, y); 15 | String actualValue = sliderPage.getSliderValue(); 16 | String expectedValue = "85"; 17 | Assert.assertEquals(actualValue, expectedValue, 18 | "\n Actual & Expected Values Do Not Match \n"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/alerts_frames_windows/ModalDialogsPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.alerts_frames_windows; 2 | 3 | import org.openqa.selenium.By; 4 | 5 | public class ModalDialogsPage extends Alerts_Frames_WindowsPage { 6 | 7 | private By smallModalButton = By.id("showSmallModal"); 8 | private By smallModalText = By.xpath("//div[contains(text(),'small modal')]"); 9 | private By closeButton = By.id("closeSmallModal"); 10 | 11 | public void clickSmallModalButton() { 12 | click(smallModalButton); 13 | } 14 | 15 | public String getSmallModalText() { 16 | return find(smallModalText).getText(); 17 | } 18 | 19 | public void clickCloseButton() { 20 | click(closeButton); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/utilities/GetUtility.java: -------------------------------------------------------------------------------- 1 | package utilities; 2 | 3 | import org.openqa.selenium.By; 4 | 5 | import java.util.Set; 6 | 7 | public class GetUtility extends Utility { 8 | 9 | public static String getWindowHandle() { 10 | return driver.getWindowHandle(); 11 | } 12 | 13 | public static Set getWindowHandles() { 14 | return driver.getWindowHandles(); 15 | } 16 | 17 | public static String getText(By locator) { 18 | return driver.findElement(locator).getText(); 19 | } 20 | 21 | public static String getAttribute(By locator, String attribute) { 22 | return driver.findElement(locator).getAttribute(attribute); 23 | } 24 | 25 | public static String getURL() { 26 | return driver.getCurrentUrl(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/tests/part3/elements/LinksTest.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.tests.part3.elements; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | import part3_4.com.demoqa.base.BaseTest; 6 | 7 | public class LinksTest extends BaseTest { 8 | 9 | @Test 10 | public void testLinks() { 11 | var linksPage = homePage.goToElements().clickLinks(); 12 | linksPage.clickBadRequestLink(); 13 | String actualResponse = linksPage.getResponse(); 14 | Assert.assertTrue(actualResponse.contains("400") 15 | && actualResponse.contains("Bad Request"), 16 | "\n Actual Response (" + actualResponse + 17 | ")\n Does Not Contain '400' and 'Bad Request' \n"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/tests/part4/modals/ModalTest.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.tests.part4.modals; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | import part3_4.com.demoqa.base.BaseTest; 6 | 7 | public class ModalTest extends BaseTest { 8 | 9 | @Test 10 | public void testModalDialog() { 11 | var afwPage = homePage.goToAlertsFramesWindowsCard(); 12 | var modalDialogsPage = afwPage.clickModalDialogs(); 13 | modalDialogsPage.clickSmallModalButton(); 14 | String actualText = modalDialogsPage.getSmallModalText(); 15 | Assert.assertTrue(actualText.contains("small modal"), 16 | "\n The Message Does Not Contain 'small modal' \n"); 17 | modalDialogsPage.clickCloseButton(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/utilities/JavaScriptUtility.java: -------------------------------------------------------------------------------- 1 | package utilities; 2 | 3 | import org.openqa.selenium.By; 4 | import org.openqa.selenium.JavascriptExecutor; 5 | import org.openqa.selenium.WebElement; 6 | 7 | public class JavaScriptUtility extends Utility { 8 | 9 | public static void scrollToElementJS(By locator) { 10 | WebElement element = driver.findElement(locator); 11 | String jsScript = "arguments[0].scrollIntoView();"; 12 | ((JavascriptExecutor)driver).executeScript(jsScript, element); 13 | } 14 | 15 | public static void clickJS(By locator) { 16 | WebElement element = driver.findElement(locator); 17 | JavascriptExecutor executor = (JavascriptExecutor) driver; 18 | executor.executeScript("arguments[0].click();", element); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/tests/part3/forms/CheckboxTest.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.tests.part3.forms; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | import part3_4.com.demoqa.base.BaseTest; 6 | 7 | public class CheckboxTest extends BaseTest { 8 | 9 | @Test 10 | public void testCheckbox() { 11 | var formsPage = homePage.goToForms().clickPracticeForm(); 12 | formsPage.clickSportsCheckbox(); 13 | formsPage.clickReadingCheckbox(); 14 | formsPage.clickMusicCheckbox(); 15 | formsPage.unclickReadingCheckbox(); 16 | 17 | boolean isReadingCheckboxSelected = formsPage.isReadingSelected(); 18 | Assert.assertFalse(isReadingCheckboxSelected, 19 | "\n Reading Checkbox Is Selected \n"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/tests/part4/windows/WindowsTest.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.tests.part4.windows; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | import part3_4.com.demoqa.base.BaseTest; 6 | 7 | import static utilities.GetUtility.getURL; 8 | 9 | public class WindowsTest extends BaseTest { 10 | 11 | @Test 12 | public void testNewWindowURL() { 13 | var windowsPage = homePage.goToAlertsFramesWindowsCard().clickBrowserWindows(); 14 | windowsPage.clickNewWindowButton(); 15 | windowsPage.switchToNewWindow(); 16 | String actualURL = getURL(); 17 | String expectedURL = "https://demoqa.com/sample"; 18 | Assert.assertEquals(actualURL, expectedURL, 19 | "\n Actual & Expected URL's Do Not Match \n"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/tests/part3/elements/WebTableTest.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.tests.part3.elements; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | import part3_4.com.demoqa.base.BaseTest; 6 | 7 | public class WebTableTest extends BaseTest { 8 | 9 | @Test 10 | public void testWebTable() { 11 | String email = "kierra@example.com"; 12 | String expectedAge = "34"; 13 | 14 | var webTablePage = homePage.goToElements().clickWebTables(); 15 | webTablePage.clickEdit(email); 16 | webTablePage.setAge("34"); 17 | webTablePage.clickSubmitButton(); 18 | String actualAge = webTablePage.getTableAge(email); 19 | Assert.assertEquals(actualAge, expectedAge, 20 | "\n Actual & Expected Ages Do Not Match \n"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/widgets/SliderPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.widgets; 2 | 3 | import org.openqa.selenium.By; 4 | import org.openqa.selenium.interactions.Actions; 5 | 6 | import static utilities.ActionsUtility.dragAndDropBy; 7 | import static utilities.GetUtility.getAttribute; 8 | 9 | public class SliderPage extends WidgetsPage { 10 | 11 | private By slider = By.xpath("//div[@id='sliderContainer']//input[@type='range']"); 12 | private By sliderValue = By.id("sliderValue"); 13 | 14 | public String getSliderValue() { 15 | return getAttribute(sliderValue, "value"); 16 | } 17 | 18 | public void moveSlider(int x, int y) { 19 | // Actions act = new Actions(driver); 20 | // act.dragAndDropBy(find(slider), x, y).perform(); 21 | dragAndDropBy(find(slider), x, y); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/elements/WebTablesPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.elements; 2 | 3 | import org.openqa.selenium.By; 4 | 5 | public class WebTablesPage extends ElementsPage { 6 | 7 | private By registrationAgeField = By.id("age"); 8 | private By submitButton = By.id("submit"); 9 | 10 | public void clickEdit(String email) { 11 | By edit = By.xpath("//div[text()='"+ email +"']//following::span[@title='Edit']"); 12 | click(edit); 13 | } 14 | 15 | public void setAge(String age) { 16 | set(registrationAgeField, age); 17 | } 18 | 19 | public void clickSubmitButton() { 20 | click(submitButton); 21 | } 22 | 23 | public String getTableAge(String email) { 24 | By tableAge = By.xpath("//div[text()='"+ email +"']//preceding::div[1]"); 25 | return find(tableAge).getText(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/base/BasePage.java: -------------------------------------------------------------------------------- 1 | package com.base; 2 | 3 | import org.openqa.selenium.By; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.WebElement; 6 | 7 | public class BasePage { 8 | 9 | public static WebDriver driver; 10 | 11 | public void setDriver(WebDriver driver) { 12 | BasePage.driver = driver; 13 | } 14 | 15 | protected WebElement find(By locator) { 16 | return driver.findElement(locator); 17 | } 18 | 19 | protected void set(By locator, String text) { 20 | find(locator).clear(); 21 | find(locator).sendKeys(text); 22 | } 23 | 24 | protected void click(By locator) { 25 | find(locator).click(); 26 | } 27 | 28 | public static void delay(int milliseconds) { 29 | // Demo Purpose 30 | try { 31 | Thread.sleep(milliseconds); 32 | } catch(InterruptedException exc) { 33 | exc.printStackTrace(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/part2/com/saucedemo/base/BaseTest.java: -------------------------------------------------------------------------------- 1 | package part2.com.saucedemo.base; 2 | 3 | import com.base.BasePage; 4 | import com.saucedemo.pages.LoginPage; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.chrome.ChromeDriver; 7 | import org.testng.annotations.AfterClass; 8 | import org.testng.annotations.BeforeClass; 9 | 10 | public class BaseTest { 11 | 12 | protected WebDriver driver; 13 | protected BasePage basePage; 14 | protected LoginPage loginPage; 15 | private String url = "https://www.saucedemo.com"; 16 | 17 | @BeforeClass 18 | public void setUp() { 19 | driver = new ChromeDriver(); 20 | driver.manage().window().maximize(); 21 | driver.get(url); 22 | basePage = new BasePage(); 23 | basePage.setDriver(driver); 24 | loginPage = new LoginPage(); 25 | } 26 | 27 | @AfterClass 28 | public void tearDown() { 29 | driver.quit(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/tests/part4/interactions/KeyboardTest.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.tests.part4.interactions; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | import part3_4.com.demoqa.base.BaseTest; 6 | 7 | public class KeyboardTest extends BaseTest { 8 | 9 | @Test 10 | public void testApplicationUsingKeyboard() { 11 | var textBoxPage = homePage.goToElements().clickTextBox(); 12 | textBoxPage.setFullName("Rex Allen Jones II"); 13 | textBoxPage.setEmail("RexAllenJones@GMail.com"); 14 | textBoxPage.setCurrentAddress("1234 Selenium Avenue"); 15 | textBoxPage.setCurrentAddress("Suite 3400"); 16 | textBoxPage.setCurrentAddress("Dallas, Texas"); 17 | textBoxPage.clickSubmitButton(); 18 | String actualAddress = textBoxPage.getCurrentAddress(); 19 | Assert.assertTrue(actualAddress.contains("Suite 3400"), 20 | "\n Actual Address Does Not Contain Suite 3400 \n"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/alerts_frames_windows/AlertsPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.alerts_frames_windows; 2 | 3 | import org.openqa.selenium.By; 4 | 5 | public class AlertsPage extends Alerts_Frames_WindowsPage { 6 | 7 | private By informationAlertButton = By.id("alertButton"); 8 | private By confirmationAlertButton = By.id("confirmButton"); 9 | private By confirmationResult = By.id("confirmResult"); 10 | private By promptAlertButton = By.id("promtButton"); 11 | private By promptResult = By.id("promptResult"); 12 | 13 | public String getPromptAlertResult() { 14 | return find(promptResult).getText(); 15 | } 16 | 17 | public void clickPromptAlertButton() { 18 | click(promptAlertButton); 19 | } 20 | 21 | public void clickInformationAlertButton() { 22 | click(informationAlertButton); 23 | } 24 | 25 | public void clickConfirmationAlertButton() { 26 | click(confirmationAlertButton); 27 | } 28 | 29 | public String getConfirmationResult() { 30 | return find(confirmationResult).getText(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/saucedemo/pages/LoginPage.java: -------------------------------------------------------------------------------- 1 | package com.saucedemo.pages; 2 | 3 | import com.base.BasePage; 4 | import org.openqa.selenium.By; 5 | 6 | public class LoginPage extends BasePage { 7 | 8 | private By usernameField = By.id("user-name"); 9 | private By passwordField = By.id("password"); 10 | private By loginButton = By.id("login-button"); 11 | private By errorMessage = By.cssSelector("#login_button_container h3"); 12 | 13 | public void setUsername(String username) { 14 | set(usernameField, username); 15 | } 16 | 17 | public void setPassword(String password) { 18 | set(passwordField, password); 19 | } 20 | 21 | public ProductsPage clickLoginButton() { 22 | click(loginButton); 23 | return new ProductsPage(); 24 | } 25 | 26 | public ProductsPage logIntoApplication(String username, String password) { 27 | setUsername(username); 28 | setPassword(password); 29 | return clickLoginButton(); 30 | } 31 | 32 | public String getErrorMessage() { 33 | return find(errorMessage).getText(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/tests/part3/widgets/DateTest.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.tests.part3.widgets; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | import part3_4.com.demoqa.base.BaseTest; 6 | 7 | public class DateTest extends BaseTest { 8 | 9 | @Test 10 | public void testSelectingDate() { 11 | String month = "December"; 12 | String monthNumber = "12"; 13 | String day = "31"; 14 | String year = "2034"; 15 | 16 | var datePickerPage = homePage.goToWidgets().clickDatePicker(); 17 | datePickerPage.clickSelectDate(); 18 | datePickerPage.selectMonth(month); 19 | datePickerPage.selectYear(year); 20 | datePickerPage.clickDay(day); 21 | 22 | String actualDate = datePickerPage.getDate(); 23 | String expectedDate = monthNumber + "/" + day + "/" + year; 24 | Assert.assertEquals(actualDate, expectedDate, 25 | "\n Actual & Expected Dates Do Not Match" + 26 | "\n Actual Date: " + actualDate + 27 | "\n Expected Date: " + expectedDate + "\n"); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | SeleniumFreeCodeCamp 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.seleniumhq.selenium 20 | selenium-java 21 | 4.23.0 22 | 23 | 24 | 25 | org.testng 26 | testng 27 | 7.10.2 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/tests/part4/dynamic_wait/DynamicWaitTests.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.tests.part4.dynamic_wait; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | import part3_4.com.demoqa.base.BaseTest; 6 | 7 | import static org.testng.Assert.assertEquals; 8 | 9 | @Test 10 | public class DynamicWaitTests extends BaseTest { 11 | 12 | public void testVisibleAfterButtonText() { 13 | var dynamicPage = homePage.goToElements().clickDynamicProperties(); 14 | String actualText = dynamicPage.getVisibleAfterButtonText(); 15 | String expectedText = "Visible After 5 Seconds"; 16 | assertEquals(actualText, expectedText, 17 | "\n Actual & Expected Text Do Not Match \n"); 18 | } 19 | 20 | public void testProgressBar() { 21 | var progressBarPage = homePage.goToWidgets().clickProgressBar(); 22 | progressBarPage.clickStartButton(); 23 | String actualValue = progressBarPage.getProgressValue(); 24 | String expectedValue = "100%"; 25 | assertEquals(actualValue, expectedValue, 26 | "\n Value Is Not 100% \n"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/tests/part3/widgets/SelectDropDownTests.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.tests.part3.widgets; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | import part3_4.com.demoqa.base.BaseTest; 6 | 7 | import java.util.List; 8 | 9 | public class SelectDropDownTests extends BaseTest { 10 | 11 | @Test 12 | public void testMultiSelectDropDown() { 13 | var selectMenuPage = homePage.goToWidgets().clickSelectMenu(); 14 | selectMenuPage.selectStandardMulti("Volvo"); 15 | selectMenuPage.selectStandardMulti(1); 16 | selectMenuPage.selectStandardMulti("Audi"); 17 | selectMenuPage.selectStandardMulti(2); 18 | 19 | selectMenuPage.deselectStandardMulti("saab"); 20 | List actualSelectedOptions = 21 | selectMenuPage.getAllSelectedStandardMultiOptions(); 22 | Assert.assertTrue(actualSelectedOptions.contains("Volvo")); 23 | Assert.assertTrue(actualSelectedOptions.contains("Opel")); 24 | Assert.assertTrue(actualSelectedOptions.contains("Audi")); 25 | Assert.assertFalse(actualSelectedOptions.contains("Saab"), 26 | "\n Saab Is Selected As An Option \n"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/utilities/WaitUtility.java: -------------------------------------------------------------------------------- 1 | package utilities; 2 | 3 | import org.openqa.selenium.By; 4 | import org.openqa.selenium.NoSuchElementException; 5 | import org.openqa.selenium.StaleElementReferenceException; 6 | import org.openqa.selenium.support.ui.ExpectedConditions; 7 | import org.openqa.selenium.support.ui.FluentWait; 8 | import org.openqa.selenium.support.ui.WebDriverWait; 9 | 10 | import java.time.Duration; 11 | 12 | public class WaitUtility extends Utility { 13 | 14 | public static void explicitWaitUntilVisible(int seconds, By locator) { 15 | WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(seconds)); 16 | wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); 17 | } 18 | 19 | public static void fluentWaitUntilVisible(int seconds, By locator) { 20 | FluentWait fluentWait = new FluentWait(driver) 21 | .withTimeout(Duration.ofSeconds(seconds)) 22 | .pollingEvery(Duration.ofMillis(500)) 23 | .ignoring(NoSuchElementException.class, 24 | StaleElementReferenceException.class); 25 | fluentWait.until(ExpectedConditions.visibilityOfElementLocated(locator)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/alerts_frames_windows/BrowserWindowsPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.alerts_frames_windows; 2 | 3 | import org.openqa.selenium.By; 4 | 5 | import java.util.Set; 6 | 7 | import static utilities.SwitchToUtility.switchToWindow; 8 | 9 | public class BrowserWindowsPage extends Alerts_Frames_WindowsPage { 10 | private By newWindowButton = By.id("windowButton"); 11 | 12 | public void clickNewWindowButton() { 13 | click(newWindowButton); 14 | } 15 | 16 | public void switchToNewWindow() { 17 | // Step 1: Get The Current "Main" Window Handle 18 | String currentHandle = driver.getWindowHandle(); 19 | System.out.println("Main Window ID: " + currentHandle + "\n"); 20 | 21 | // Step 2: Get All Window Handles 22 | Set allHandles = driver.getWindowHandles(); 23 | System.out.println("# of Open Windows: " + allHandles.size()); 24 | 25 | // Step 3: Switch To The New Window Using The Window Handle 26 | for (String handle : allHandles) { 27 | if (currentHandle.equals(handle)) { 28 | System.out.println("1st Window ID: " + handle); 29 | } else { 30 | switchToWindow(handle); 31 | System.out.println("2nd Window ID: " + handle); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/utilities/SwitchToUtility.java: -------------------------------------------------------------------------------- 1 | package utilities; 2 | 3 | import org.openqa.selenium.WebDriver; 4 | import org.openqa.selenium.WebElement; 5 | 6 | public class SwitchToUtility extends Utility { 7 | 8 | private static WebDriver.TargetLocator switchTo() { 9 | return driver.switchTo(); 10 | } 11 | 12 | public static String getAlertText() { 13 | return switchTo().alert().getText(); 14 | } 15 | 16 | public static void acceptAlert() { 17 | switchTo().alert().accept(); 18 | } 19 | 20 | public static void dismissAlert() { 21 | switchTo().alert().dismiss(); 22 | } 23 | 24 | public static void setAlertText(String text) { 25 | switchTo().alert().sendKeys(text); 26 | } 27 | 28 | public static void switchToFrameString(String value) { 29 | switchTo().frame(value); 30 | } 31 | 32 | public static void switchToDefaultContent() { 33 | switchTo().defaultContent(); 34 | } 35 | 36 | public static void switchToFrameIndex(int index) { 37 | switchTo().frame(index); 38 | } 39 | 40 | public static void switchToFrameElement(WebElement element) { 41 | switchTo().frame(element); 42 | } 43 | 44 | public static void switchToWindow(String handle) { 45 | switchTo().window(handle); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/widgets/SelectMenuPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.widgets; 2 | 3 | import org.openqa.selenium.By; 4 | import org.openqa.selenium.support.ui.Select; 5 | 6 | import java.util.List; 7 | 8 | import static utilities.DropDownUtility.*; 9 | import static utilities.JavaScriptUtility.*; 10 | 11 | public class SelectMenuPage extends WidgetsPage { 12 | 13 | private By standardMultiSelect = By.id("cars"); 14 | 15 | public void selectStandardMulti(String text) { 16 | scrollToElementJS(standardMultiSelect); 17 | // Select select = new Select(find(standardMultiSelect)); 18 | // select.selectByVisibleText(text); 19 | selectByVisibleText(standardMultiSelect, text); 20 | } 21 | 22 | public void selectStandardMulti(int index) { 23 | scrollToElementJS(standardMultiSelect); 24 | selectByIndex(standardMultiSelect, index); 25 | } 26 | 27 | public void deselectStandardMulti(String value) { 28 | scrollToElementJS(standardMultiSelect); 29 | deselectByValue(standardMultiSelect, value); 30 | } 31 | 32 | public List getAllSelectedStandardMultiOptions() { 33 | return getAllSelectedOptions(standardMultiSelect); 34 | } 35 | } 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/main/java/utilities/DropDownUtility.java: -------------------------------------------------------------------------------- 1 | package utilities; 2 | 3 | import org.openqa.selenium.By; 4 | import org.openqa.selenium.support.ui.Select; 5 | import org.openqa.selenium.WebElement; 6 | import java.util.stream.Collectors; 7 | import java.util.List; 8 | 9 | public class DropDownUtility extends Utility { 10 | 11 | private static Select findDropDown(By locator) { 12 | return new Select(driver.findElement(locator)); 13 | } 14 | 15 | public static void selectByVisibleText(By locator, String text) { 16 | findDropDown(locator).selectByVisibleText(text); 17 | } 18 | 19 | public static void selectByIndex(By locator, int index) { 20 | findDropDown(locator).selectByIndex(index); 21 | } 22 | 23 | public static void selectByValue(By locator, String value) { 24 | findDropDown(locator).selectByValue(value); 25 | } 26 | 27 | public static void deselectByValue(By locator, String value) { 28 | findDropDown(locator).deselectByValue(value); 29 | } 30 | 31 | public static List getAllSelectedOptions(By locator) { 32 | List allSelectedOptions = 33 | findDropDown(locator).getAllSelectedOptions(); 34 | return allSelectedOptions.stream(). 35 | map(WebElement::getText).collect(Collectors.toList()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/elements/ElementsPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.elements; 2 | 3 | import com.demoqa.pages.HomePage; 4 | import org.openqa.selenium.By; 5 | 6 | import static utilities.JavaScriptUtility.scrollToElementJS; 7 | 8 | public class ElementsPage extends HomePage { 9 | 10 | private By webTablesMenuItem = By.xpath("//li[@id='item-3']/span[text()='Web Tables']"); 11 | private By linksMenuItem = By.xpath("//li[@id='item-5']/span[text()='Links']"); 12 | private By dynamicPropertiesMenuItem = By.xpath("//li[@id='item-8']/span[text()='Dynamic Properties']"); 13 | private By textBoxMenuItem = By.xpath("//li[@id='item-0']/span[text()='Text Box']"); 14 | 15 | public TextBoxPage clickTextBox() { 16 | scrollToElementJS(textBoxMenuItem); 17 | click(textBoxMenuItem); 18 | return new TextBoxPage(); 19 | } 20 | 21 | public DynamicPropertiesPage clickDynamicProperties() { 22 | scrollToElementJS(dynamicPropertiesMenuItem); 23 | click(dynamicPropertiesMenuItem); 24 | return new DynamicPropertiesPage(); 25 | } 26 | 27 | public WebTablesPage clickWebTables () { 28 | click(webTablesMenuItem); 29 | return new WebTablesPage(); 30 | } 31 | 32 | public LinksPage clickLinks() { 33 | click(linksMenuItem); 34 | return new LinksPage(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/widgets/WidgetsPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.widgets; 2 | 3 | import com.demoqa.pages.HomePage; 4 | import org.openqa.selenium.By; 5 | 6 | import static utilities.JavaScriptUtility.scrollToElementJS; 7 | 8 | public class WidgetsPage extends HomePage { 9 | 10 | private By selectMenuItem = By.xpath("//li[@id='item-8']/span[text()='Select Menu']"); 11 | private By datePickerMenuItem = By.xpath("//li[@id='item-2']/span[text()='Date Picker']"); 12 | private By progressBarMenuItem = By.xpath("//li[@id='item-4']/span[text()='Progress Bar']"); 13 | private By sliderMenuItem = By.xpath("//li[@id='item-3']/span[text()='Slider']"); 14 | 15 | public SliderPage clickSlider() { 16 | scrollToElementJS(sliderMenuItem); 17 | click(sliderMenuItem); 18 | return new SliderPage(); 19 | } 20 | 21 | public ProgressBarPage clickProgressBar() { 22 | scrollToElementJS(progressBarMenuItem); 23 | click(progressBarMenuItem); 24 | return new ProgressBarPage(); 25 | } 26 | 27 | public SelectMenuPage clickSelectMenu() { 28 | scrollToElementJS(selectMenuItem); 29 | click(selectMenuItem); 30 | return new SelectMenuPage(); 31 | } 32 | 33 | public DatePickerMenuPage clickDatePicker() { 34 | scrollToElementJS(datePickerMenuItem); 35 | click(datePickerMenuItem); 36 | return new DatePickerMenuPage(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/part1/FirstSeleniumTest.java: -------------------------------------------------------------------------------- 1 | package part1; 2 | 3 | import org.openqa.selenium.By; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.WebElement; 6 | import org.openqa.selenium.chrome.ChromeDriver; 7 | import org.testng.Assert; 8 | import org.testng.annotations.AfterClass; 9 | import org.testng.annotations.BeforeClass; 10 | import org.testng.annotations.Test; 11 | 12 | public class FirstSeleniumTest { 13 | 14 | WebDriver driver; 15 | 16 | @BeforeClass 17 | public void setUp() { 18 | driver = new ChromeDriver(); 19 | driver.manage().window().maximize(); 20 | driver.get("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login"); 21 | } 22 | 23 | @AfterClass 24 | public void tearDown() { 25 | // driver.quit(); 26 | } 27 | 28 | @Test 29 | public void testLoggingIntoApplication() throws InterruptedException { 30 | Thread.sleep(2000); 31 | WebElement username = driver.findElement(By.name("username")); 32 | username.sendKeys("Admin"); 33 | 34 | var password = driver.findElement(By.name("password")); 35 | password.sendKeys("admin123"); 36 | 37 | driver.findElement(By.tagName("button")).click(); 38 | Thread.sleep(2000); 39 | String actualResult = driver.findElement(By.tagName("h6")).getText(); 40 | String expectedResult = "Dashboard"; 41 | Assert.assertEquals(actualResult, expectedResult); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/part1/LogInShouldFailTest.java: -------------------------------------------------------------------------------- 1 | package part1; 2 | 3 | import org.openqa.selenium.By; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.WebElement; 6 | import org.openqa.selenium.chrome.ChromeDriver; 7 | import org.testng.Assert; 8 | import org.testng.annotations.AfterClass; 9 | import org.testng.annotations.BeforeClass; 10 | import org.testng.annotations.Test; 11 | 12 | public class LogInShouldFailTest { 13 | 14 | WebDriver driver; 15 | 16 | @BeforeClass 17 | public void setUp() { 18 | driver = new ChromeDriver(); 19 | driver.manage().window().maximize(); 20 | driver.get("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login"); 21 | } 22 | 23 | @AfterClass 24 | public void tearDown() { 25 | // driver.quit(); 26 | } 27 | 28 | @Test 29 | public void testLoggingIntoApplication() throws InterruptedException { 30 | Thread.sleep(2000); 31 | WebElement username = driver.findElement(By.name("username")); 32 | username.sendKeys("Admin"); 33 | 34 | var password = driver.findElement(By.name("password")); 35 | password.sendKeys("admin123"); 36 | 37 | driver.findElement(By.tagName("button")).click(); 38 | Thread.sleep(2000); 39 | String actualResult = driver.findElement(By.tagName("h6")).getText(); 40 | String expectedResult = "Dashboard"; 41 | Assert.assertNotEquals(actualResult, expectedResult); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/elements/TextBoxPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.elements; 2 | 3 | import org.openqa.selenium.By; 4 | import org.openqa.selenium.Keys; 5 | 6 | import static utilities.ActionsUtility.sendKeys; 7 | import static utilities.GetUtility.getText; 8 | import static utilities.JavaScriptUtility.scrollToElementJS; 9 | import static utilities.WaitUtility.explicitWaitUntilVisible; 10 | 11 | public class TextBoxPage extends ElementsPage { 12 | private By fullNameField = By.id("userName"); 13 | private By currentAddressField = By.xpath("//textarea[@id='currentAddress']"); 14 | private By submitButton = By.id("submit"); 15 | private By currentAddressResult =By.xpath("//p[@id='currentAddress']"); 16 | 17 | public String getCurrentAddress() { 18 | explicitWaitUntilVisible(5, currentAddressResult); 19 | return getText(currentAddressResult); 20 | } 21 | 22 | public void clickSubmitButton() { 23 | scrollToElementJS(submitButton); 24 | click(submitButton); 25 | } 26 | 27 | public void setCurrentAddress(String address) { 28 | find(currentAddressField).sendKeys(address + Keys.ENTER); 29 | } 30 | 31 | public void setFullName(String name) { 32 | delay(1000); 33 | scrollToElementJS(fullNameField); 34 | sendKeys(find(fullNameField), Keys.chord(name)); 35 | } 36 | 37 | public void setEmail(String email) { 38 | setFullName(Keys.chord(Keys.TAB, email)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/alerts_frames_windows/FramesPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.alerts_frames_windows; 2 | 3 | import org.openqa.selenium.By; 4 | 5 | import static utilities.SwitchToUtility.*; 6 | 7 | public class FramesPage extends Alerts_Frames_WindowsPage{ 8 | 9 | private By textInFrame = By.id("sampleHeading"); 10 | private String iFrameBigBox = "frame1"; 11 | private By headerFramesText = By.xpath("//div[@id='app']//h1[text()='Frames']"); 12 | private By iFrameSmallBox = By.xpath("//div[@id='frame2Wrapper']/iframe"); 13 | 14 | public String getHeaderFramesText() { 15 | return find(headerFramesText).getText(); 16 | } 17 | 18 | private void switchToBigBox() { 19 | switchToFrameString(iFrameBigBox); 20 | } 21 | 22 | private void switchToSmallBox() { 23 | // switchToFrameIndex(3); 24 | switchToFrameElement(find(iFrameSmallBox)); 25 | } 26 | 27 | public String getTextInBigFrame() { 28 | switchToBigBox(); 29 | String bigFrameText = find(textInFrame).getText(); 30 | System.out.println("Big Frame Text: " + bigFrameText); 31 | switchToDefaultContent(); 32 | return bigFrameText; 33 | } 34 | 35 | public String getTextInSmallFrame() { 36 | switchToSmallBox(); 37 | String smallFrameText = find(textInFrame).getText(); 38 | System.out.println("Small Frame Text: " + smallFrameText); 39 | switchToDefaultContent(); 40 | return smallFrameText; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/alerts_frames_windows/Alerts_Frames_WindowsPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.alerts_frames_windows; 2 | 3 | import com.demoqa.pages.HomePage; 4 | import org.openqa.selenium.By; 5 | 6 | import static utilities.JavaScriptUtility.scrollToElementJS; 7 | 8 | public class Alerts_Frames_WindowsPage extends HomePage { 9 | 10 | private By modalDialogsMenuItem = By.xpath("//li[@id='item-4']/span[text()='Modal Dialogs']"); 11 | private By alertsMenuItem = By.xpath("//li[@id='item-1']/span[text()='Alerts']"); 12 | private By framesMenuItem = By.xpath("//li[@id='item-2']/span[text()='Frames']"); 13 | private By browserWindowsMenuItem = By.xpath("//li[@id='item-0']/span[text()='Browser Windows']"); 14 | 15 | public BrowserWindowsPage clickBrowserWindows() { 16 | scrollToElementJS(browserWindowsMenuItem); 17 | click(browserWindowsMenuItem); 18 | return new BrowserWindowsPage(); 19 | } 20 | 21 | public FramesPage clickFrames() { 22 | scrollToElementJS(framesMenuItem); 23 | click(framesMenuItem); 24 | return new FramesPage(); 25 | } 26 | 27 | public AlertsPage clickAlerts() { 28 | scrollToElementJS(alertsMenuItem); 29 | click(alertsMenuItem); 30 | return new AlertsPage(); 31 | } 32 | 33 | public ModalDialogsPage clickModalDialogs() { 34 | scrollToElementJS(modalDialogsMenuItem); 35 | click(modalDialogsMenuItem); 36 | return new ModalDialogsPage(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/HomePage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages; 2 | 3 | import com.demoqa.pages.alerts_frames_windows.Alerts_Frames_WindowsPage; 4 | import com.demoqa.pages.elements.ElementsPage; 5 | import com.demoqa.pages.forms.FormsPage; 6 | import com.base.BasePage; 7 | import com.demoqa.pages.widgets.WidgetsPage; 8 | import org.openqa.selenium.By; 9 | 10 | import static utilities.JavaScriptUtility.scrollToElementJS; 11 | 12 | public class HomePage extends BasePage { 13 | 14 | private By formsCard = By.xpath("//div[@id='app']//h5[text()='Forms']"); 15 | private By elementsCard = By.xpath("//div[@id='app']//h5[text()='Elements']"); 16 | private By widgetsCard = By.xpath("//div[@id='app']//h5[text()='Widgets']"); 17 | private By alertsFrameWindowsCard = By.xpath("//div[@id='app']//h5[contains(text(),'Alerts')]"); 18 | 19 | public FormsPage goToForms() { 20 | scrollToElementJS(formsCard); 21 | click(formsCard); 22 | return new FormsPage(); 23 | } 24 | 25 | public ElementsPage goToElements () { 26 | scrollToElementJS(elementsCard); 27 | click(elementsCard); 28 | return new ElementsPage(); 29 | } 30 | 31 | public WidgetsPage goToWidgets() { 32 | scrollToElementJS(widgetsCard); 33 | click(widgetsCard); 34 | return new WidgetsPage(); 35 | } 36 | 37 | public Alerts_Frames_WindowsPage goToAlertsFramesWindowsCard() { 38 | scrollToElementJS(alertsFrameWindowsCard); 39 | click(alertsFrameWindowsCard); 40 | return new Alerts_Frames_WindowsPage(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/tests/part4/frames/FramesTest.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.tests.part4.frames; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | import part3_4.com.demoqa.base.BaseTest; 6 | 7 | public class FramesTest extends BaseTest { 8 | 9 | @Test 10 | public void testFramesBigBox() { 11 | var framesPage = homePage.goToAlertsFramesWindowsCard().clickFrames(); 12 | String actualBigBoxText = framesPage.getTextInBigFrame(); 13 | String expectedBigBoxText = "This is a sample page"; 14 | Assert.assertEquals(actualBigBoxText, expectedBigBoxText, 15 | "\n Actual & Expected Text Do Not Match \n"); 16 | String actualHeaderText = framesPage.getHeaderFramesText(); 17 | String expectedHeaderText = "Frames"; 18 | Assert.assertEquals(actualHeaderText, expectedHeaderText, 19 | "\n Acutal & Expected Header Text Do Not Match \n"); 20 | } 21 | 22 | @Test 23 | public void testFramesSmallBox() { 24 | var framesPage = homePage.goToAlertsFramesWindowsCard().clickFrames(); 25 | String actualSmallBoxText = framesPage.getTextInSmallFrame(); 26 | String expectedSmallBoxText = "This is a sample page"; 27 | Assert.assertEquals(actualSmallBoxText,expectedSmallBoxText, 28 | "\n Actual & Expected Text Do Not Match \n"); 29 | String actualHeaderText = framesPage.getHeaderFramesText(); 30 | String expectedHeaderText = "Frames"; 31 | Assert.assertEquals(actualHeaderText, expectedHeaderText, 32 | "\n Actual & Expected Header Text Do Not Match \n"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/widgets/DatePickerMenuPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.widgets; 2 | 3 | import org.openqa.selenium.By; 4 | 5 | import static utilities.DropDownUtility.selectByVisibleText; 6 | 7 | public class DatePickerMenuPage extends WidgetsPage { 8 | 9 | private By selectDateField = By.id("datePickerMonthYearInput"); 10 | private By monthDropDown = By.className("react-datepicker__month-select"); 11 | private By yearDropDown = By.cssSelector(".react-datepicker__year-select"); 12 | 13 | private By dayValue(String day) { 14 | return By.xpath("//div[contains(@class,'react-datepicker__day react-datepicker__day--')][text()='"+ day +"']"); 15 | } 16 | 17 | public void clickDay(String day) { 18 | // By dayValue = By.xpath("//div[contains(@class,'react-datepicker__day react-datepicker__day--')][text()='"+ day +"']"); 19 | // click(dayValue); 20 | click(dayValue(day)); 21 | } 22 | 23 | public boolean isDayInMonth(String day) { 24 | // By dayValue = By.xpath("//div[contains(@class,'react-datepicker__day react-datepicker__day--')][text()='"+ day +"']"); 25 | // return find(dayValue).isDisplayed(); 26 | return find(dayValue(day)).isDisplayed(); 27 | } 28 | 29 | public void clickSelectDate() { 30 | click(selectDateField); 31 | } 32 | 33 | public String getDate() { 34 | return find(selectDateField).getAttribute("value"); 35 | } 36 | 37 | public void selectMonth(String month) { 38 | selectByVisibleText(monthDropDown, month); 39 | } 40 | 41 | public void selectYear(String year) { 42 | selectByVisibleText(yearDropDown, year); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/tests/part4/alerts/AlertsTest.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.tests.part4.alerts; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | import part3_4.com.demoqa.base.BaseTest; 6 | 7 | import static utilities.SwitchToUtility.*; 8 | 9 | @Test 10 | public class AlertsTest extends BaseTest { 11 | 12 | public void testInformationAlert() { 13 | String expectedAlertText = "You clicked a button"; 14 | var alertsPage = homePage.goToAlertsFramesWindowsCard().clickAlerts(); 15 | alertsPage.clickInformationAlertButton(); 16 | 17 | Assert.assertEquals(getAlertText(), expectedAlertText, 18 | "\n Actual & Expected Messages Do Not Match \n"); 19 | acceptAlert(); 20 | } 21 | 22 | public void testConfirmationAlert() { 23 | var alertsPage = homePage.goToAlertsFramesWindowsCard().clickAlerts(); 24 | alertsPage.clickConfirmationAlertButton(); 25 | dismissAlert(); 26 | String actualConfirmationResult = alertsPage.getConfirmationResult(); 27 | String expectedConfirmationResult = "You selected Cancel"; 28 | Assert.assertEquals(actualConfirmationResult, expectedConfirmationResult, 29 | "\n You Did Not Select Cancel \n"); 30 | } 31 | 32 | public void testPromptAlert() { 33 | String alertText = "Selenium With Java"; 34 | String expectedResult = "You entered " + alertText; 35 | 36 | var alertsPage = homePage.goToAlertsFramesWindowsCard().clickAlerts(); 37 | alertsPage.clickPromptAlertButton(); 38 | setAlertText(alertText); 39 | acceptAlert(); 40 | String actualResult = alertsPage.getPromptAlertResult(); 41 | Assert.assertEquals(actualResult, expectedResult, 42 | "\n Actual & Expected Results Do Not Match \n"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/demoqa/pages/forms/PracticeFormPage.java: -------------------------------------------------------------------------------- 1 | package com.demoqa.pages.forms; 2 | 3 | import org.openqa.selenium.By; 4 | 5 | import static utilities.JavaScriptUtility.*; 6 | 7 | public class PracticeFormPage extends FormsPage { 8 | 9 | private By femaleRadioButton = By.id("gender-radio-2"); 10 | private By sportsHobbyCheckbox = By.id("hobbies-checkbox-1"); 11 | private By readingHobbyCheckbox = By.id("hobbies-checkbox-2"); 12 | private By musicHobbyCheckbox = By.id("hobbies-checkbox-3"); 13 | private By submitButton = By.id("submit"); 14 | 15 | public void clickFemaleRadioButton() { 16 | scrollToElementJS(femaleRadioButton); 17 | clickJS(femaleRadioButton); 18 | } 19 | 20 | public boolean isFemaleSelected() { 21 | return find(femaleRadioButton).isSelected(); 22 | } 23 | 24 | public void clickSportsCheckbox() { 25 | if (!find(sportsHobbyCheckbox).isSelected()) { 26 | scrollToElementJS(sportsHobbyCheckbox); 27 | clickJS(sportsHobbyCheckbox); 28 | } 29 | } 30 | 31 | public void clickReadingCheckbox() { 32 | if (!find(readingHobbyCheckbox).isSelected()) { 33 | scrollToElementJS(readingHobbyCheckbox); 34 | clickJS(readingHobbyCheckbox); 35 | } 36 | } 37 | 38 | public void clickMusicCheckbox() { 39 | if (!find(musicHobbyCheckbox).isSelected()) { 40 | scrollToElementJS(musicHobbyCheckbox); 41 | clickJS(musicHobbyCheckbox); 42 | } 43 | } 44 | 45 | public void unclickReadingCheckbox() { 46 | if (find(readingHobbyCheckbox).isSelected()) { 47 | scrollToElementJS(readingHobbyCheckbox); 48 | clickJS(readingHobbyCheckbox); 49 | } 50 | } 51 | 52 | public boolean isReadingSelected() { 53 | return find(readingHobbyCheckbox).isSelected(); 54 | } 55 | 56 | public void clickSubmitButton() { 57 | // scrollToElementJS(submitButton); 58 | click(submitButton); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/part3_4/com/demoqa/base/BaseTest.java: -------------------------------------------------------------------------------- 1 | package part3_4.com.demoqa.base; 2 | 3 | import com.demoqa.pages.HomePage; 4 | import com.base.BasePage; 5 | import org.openqa.selenium.OutputType; 6 | import org.openqa.selenium.TakesScreenshot; 7 | import org.openqa.selenium.WebDriver; 8 | import org.openqa.selenium.chrome.ChromeDriver; 9 | import org.openqa.selenium.io.FileHandler; 10 | import org.testng.ITestResult; 11 | import org.testng.annotations.AfterClass; 12 | import org.testng.annotations.AfterMethod; 13 | import org.testng.annotations.BeforeClass; 14 | import org.testng.annotations.BeforeMethod; 15 | 16 | import java.io.File; 17 | import java.io.IOException; 18 | 19 | import static com.base.BasePage.delay; 20 | import static utilities.Utility.setUtilityDriver; 21 | 22 | public class BaseTest { 23 | 24 | private WebDriver driver; 25 | protected BasePage basePage; 26 | protected HomePage homePage; 27 | private String DEMOQA_URL = "https://demoqa.com/"; 28 | 29 | @BeforeClass 30 | public void setUp() { 31 | driver = new ChromeDriver(); 32 | driver.manage().window().maximize(); 33 | // driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5)); 34 | } 35 | 36 | @BeforeMethod 37 | public void loadApplication() { 38 | driver.get(DEMOQA_URL); 39 | basePage = new BasePage(); 40 | basePage.setDriver(driver); 41 | setUtilityDriver(); 42 | homePage = new HomePage(); 43 | } 44 | 45 | @AfterMethod 46 | public void takeFailedResultScreenshot(ITestResult testResult) { 47 | if (ITestResult.FAILURE == testResult.getStatus()) { 48 | TakesScreenshot screenshot = (TakesScreenshot) driver; 49 | File source = screenshot.getScreenshotAs(OutputType.FILE); 50 | File destination = new File(System.getProperty("user.dir") + 51 | "/resources/screenshots/(" + 52 | java.time.LocalDate.now() + ") " + 53 | testResult.getName() + ".png"); 54 | try { 55 | FileHandler.copy(source, destination); 56 | } catch (IOException e) { 57 | throw new RuntimeException(e); 58 | } 59 | System.out.println("Screenshot Located At " + destination); 60 | } 61 | } 62 | 63 | @AfterClass 64 | public void tearDown() { 65 | delay(3000); 66 | driver.quit(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | --------------------------------------------------------------------------------