├── .gitignore
├── README.md
├── SECURITY.md
├── _config.yml
├── logs
└── jwaf.log
├── pom.xml
└── src
├── main
└── resources
│ └── log4j2.properties
└── test
└── java
├── auto
├── pages
│ ├── AlertPage.java
│ ├── BasicAuthPage.java
│ ├── ChallengingDomPage.java
│ ├── CheckboxesPage.java
│ ├── ContextMenuPage.java
│ ├── DisappearingElementsPage.java
│ ├── DragAndDropPage.java
│ ├── DropdownPage.java
│ ├── DynamicControlsPage.java
│ ├── DynamicLoadingsPage.java
│ ├── FileDownloaderPage.java
│ ├── FileUploaderPage.java
│ ├── FramesPage.java
│ ├── HorizontalSliderPage.java
│ ├── HoverPage.java
│ ├── InfiniteScrollPage.java
│ ├── KeyPressesPage.java
│ ├── LargeDeepDOMPage.java
│ ├── LoginPage.java
│ ├── MultipleWindowsPage.java
│ └── WelcomePage.java
├── testcases
│ ├── TestAlert.java
│ ├── TestBasicAuth.java
│ ├── TestChallengingDomPage.java
│ ├── TestCheckboxPage.java
│ ├── TestContextMenuPage.java
│ ├── TestDisappearingElementsPage.java
│ ├── TestDragAndDrop.java
│ ├── TestDropdownPage.java
│ ├── TestDynamicControls.java
│ ├── TestDynamicLoadings.java
│ ├── TestFileDownloader.java
│ ├── TestFileUploader.java
│ ├── TestFrame.java
│ ├── TestHorizontalSlider.java
│ ├── TestHover.java
│ ├── TestInfiniteScroll.java
│ ├── TestKeyPresses.java
│ ├── TestLargeDeepDOM.java
│ ├── TestLogin.java
│ ├── TestMultipleWindows.java
│ └── TestWelcomePage.java
└── utility
│ ├── DriverFactory.java
│ ├── Init.java
│ └── Services.java
└── log4j.properties
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | /.classpath
3 | /.project
4 | /test-output/
5 | .settings/
6 | /log/
7 | /drivers/
8 | .DS_Store
9 | .idea
10 | JWAF.iml
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # JWAF (Java Webdriver Automation Framework)
2 |
3 | This is web automation framework, implemented using Java, Selenium/Webdriver, TestNG & Maven.
4 | Page Object Model (POM) is used to make the code more readable, maintainable, and reusable.
5 |
6 | ## _Prerequisite:_
7 |
8 | 1. Java
9 | 2. Maven
10 | 3. Selenium/WebDriver
11 | 4. TestNg
12 | 5. Browsers (Firefox, Chrome, IE)
13 | 6. Respective Browser drivers
14 | 7. Intellij or Eclipse
15 |
16 | ## _Coverage Plan:_
17 |
18 | | Contents | | Status |
19 | |---------------------------|---------------------------------|--------|
20 | | | | |
21 | | Framework level | Page Object Model | Done |
22 | | | Profiles | Done |
23 | | | Grids | |
24 | | | Cross browsers & cross platform | |
25 | | | | |
26 | | Locators | Learning how to get locators. | |
27 | | | | |
28 | | Functionality To Automate | Challenging DOM | Done |
29 | | | Checkboxes | Done |
30 | | | Context Menu | Done |
31 | | | Disappearing Elements | Done |
32 | | | Drag and Drop | Done |
33 | | | Dropdown | Done |
34 | | | Dynamic Content | Done |
35 | | | Dynamic Controls | Done |
36 | | | Dynamic Loading | Done |
37 | | | File Download | Done |
38 | | | File Upload | Done |
39 | | | Floating Menu | Done |
40 | | | Frames | Done |
41 | | | Horizontal Slider | Done |
42 | | | Hovers | Done |
43 | | | Infinite Scroll | Done |
44 | | | JQuery UI Menus | Done |
45 | | | JavaScript Alerts | Done |
46 | | | Key Presses | Done |
47 | | | Large & Deep DOM | Done |
48 | | | Multiple Windows | Done |
49 | | | Nested Frames | Done |
50 | | | Notification Messages | |
51 | | | Redirect Link | |
52 | | | Shifting Content | |
53 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | ## Supported Versions
4 |
5 | Use this section to tell people about which versions of your project are
6 | currently being supported with security updates.
7 |
8 | | Version | Supported |
9 | | ------- | ------------------ |
10 | | 5.1.x | :white_check_mark: |
11 | | 5.0.x | :x: |
12 | | 4.0.x | :white_check_mark: |
13 | | < 4.0 | :x: |
14 |
15 | ## Reporting a Vulnerability
16 |
17 | Use this section to tell people how to report a vulnerability.
18 |
19 | Tell them where to go, how often they can expect to get an update on a
20 | reported vulnerability, what to expect if the vulnerability is accepted or
21 | declined, etc.
22 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-cayman
--------------------------------------------------------------------------------
/logs/jwaf.log:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anujkumar21/JWAF/57f1473c38fad897554fd7fca145420c158f5abf/logs/jwaf.log
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | auto
6 | JWAF
7 | jar
8 | 1.0-SNAPSHOT
9 | JWAF
10 | http://maven.apache.org
11 |
12 |
13 | ${project.basedir}/drivers/chromedriver
14 | chrome
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | org.seleniumhq.selenium
23 | selenium-java
24 | 4.27.0
25 |
26 |
27 |
28 |
29 |
30 | org.testng
31 | testng
32 | 7.7.0
33 |
34 |
35 |
36 |
37 | org.apache.logging.log4j
38 | log4j-core
39 | 2.17.1
40 |
41 |
42 |
43 |
44 | org.apache.logging.log4j
45 | log4j-api
46 | 2.17.1
47 |
48 |
49 |
50 |
51 |
52 |
54 |
55 |
56 |
57 | maven-clean-plugin
58 | 3.1.0
59 |
60 |
61 |
62 | maven-resources-plugin
63 | 3.0.2
64 |
65 |
66 | maven-compiler-plugin
67 | 3.8.0
68 |
69 |
70 | maven-surefire-plugin
71 | 2.22.1
72 |
73 |
74 | ${chromedriver}
75 |
76 | ${browser}
77 |
78 |
79 |
80 |
81 | maven-jar-plugin
82 | 3.0.2
83 |
84 |
85 | maven-install-plugin
86 | 2.5.2
87 |
88 |
89 | maven-deploy-plugin
90 | 2.8.2
91 |
92 |
93 |
94 | maven-site-plugin
95 | 3.7.1
96 |
97 |
98 | maven-project-info-reports-plugin
99 | 3.0.0
100 |
101 |
102 | org.apache.maven.plugins
103 | maven-eclipse-plugin
104 |
105 | true
106 | true
107 |
108 |
109 |
110 |
111 |
112 |
113 | org.apache.maven.plugins
114 | maven-compiler-plugin
115 |
116 | 8
117 | 8
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/src/main/resources/log4j2.properties:
--------------------------------------------------------------------------------
1 | status = warn
2 |
3 | appender.console.type = Console
4 | appender.console.name = LogToConsole
5 | appender.console.layout.type = PatternLayout
6 | appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
7 |
8 | #appender.file.type = File
9 | #appender.file.name = LogToFile
10 | #appender.file.fileName=logs/app.log
11 | #appender.file.layout.type=PatternLayout
12 | #appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
13 |
14 | # Rotate log file
15 | appender.rolling.type = RollingFile
16 | appender.rolling.name = LogToRollingFile
17 | appender.rolling.fileName = logs/jwaf.log
18 | appender.rolling.filePattern = logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz
19 | appender.rolling.layout.type = PatternLayout
20 | appender.rolling.layout.pattern = %d %p %C{1.} [%t] %m%n
21 | appender.rolling.policies.type = Policies
22 | appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
23 | appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
24 | appender.rolling.policies.size.size=10MB
25 | appender.rolling.strategy.type = DefaultRolloverStrategy
26 | appender.rolling.strategy.max = 10
27 |
28 | # Log to console and rolling file
29 | logger.app.name = JWAF
30 | logger.app.level = debug
31 | logger.app.additivity = false
32 | logger.app.appenderRef.rolling.ref = LogToRollingFile
33 | logger.app.appenderRef.console.ref = LogToConsole
34 |
35 | rootLogger.level = info
36 | rootLogger.appenderRef.stdout.ref = LogToConsole
--------------------------------------------------------------------------------
/src/test/java/auto/pages/AlertPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.apache.logging.log4j.Logger;
5 | import org.openqa.selenium.Alert;
6 | import org.openqa.selenium.By;
7 | import org.openqa.selenium.WebDriver;
8 | import org.openqa.selenium.WebElement;
9 | import org.testng.Assert;
10 |
11 | import static org.apache.logging.log4j.LogManager.getLogger;
12 | import static org.testng.Assert.assertEquals;
13 |
14 | /**
15 | * Created by: Anuj Kumar
16 | * Email: cdac.anuj@gmail.com
17 | * Date: 21-May-18
18 | */
19 | public class AlertPage extends Services {
20 |
21 | private static Logger logger = getLogger(AlertPage.class.getName());
22 |
23 | private final static String HEADING = "JavaScript Alerts";
24 | private static final String SUCCESS_MSG = "You successfuly clicked an alert";
25 | private static final String CANCEL_MSG = "You clicked: Cancel";
26 | private static final String HELLO_MSG = "You entered: Hello";
27 | private String xpathHeading = "//h3";
28 | private String xpathButtons = "//button[text()='**dummy**']";
29 | private String xpathResult = "//p[@id='result']";
30 |
31 | public AlertPage(WebDriver driver) {
32 | super(driver);
33 | }
34 |
35 | public void verifyAlertPageHeader() {
36 | waitForElement(xpathHeading);
37 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
38 | String actualHeading = headerEle.getText();
39 | logger.info("# Actual Heading: " + actualHeading);
40 | assertEquals(actualHeading, HEADING,
41 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
42 | }
43 |
44 | public void clickOnButton(String btn) {
45 | String xpath = xpathButtons.replace("**dummy**", btn);
46 | getWebElement(xpath).click();
47 | }
48 |
49 | public void accept() {
50 | Alert alert = driver.switchTo().alert();
51 | logger.info("# Text on alert: " + alert.getText());
52 | alert.accept();
53 |
54 | String actual = getWebElement(xpathResult).getText();
55 | Assert.assertEquals(actual, SUCCESS_MSG);
56 | }
57 |
58 | public void cancel() {
59 | Alert alert = driver.switchTo().alert();
60 | alert.dismiss();
61 | String actual = getWebElement(xpathResult).getText();
62 | Assert.assertEquals(actual, CANCEL_MSG);
63 | }
64 |
65 | public void typeAndAccept() {
66 | Alert alert = driver.switchTo().alert();
67 | alert.sendKeys("Hello");
68 | alert.accept();
69 |
70 | String actual = getWebElement(xpathResult).getText();
71 | Assert.assertEquals(actual, HELLO_MSG);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/BasicAuthPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.apache.logging.log4j.Logger;
5 | import org.openqa.selenium.WebDriver;
6 |
7 | import static org.apache.logging.log4j.LogManager.getLogger;
8 |
9 | public class BasicAuthPage {
10 | private static Logger logger = getLogger(BasicAuthPage.class);
11 | Services services;
12 |
13 | public static final String HEADING = "Basic Auth";
14 | String xpathHeading = "//h3";
15 |
16 | public BasicAuthPage(WebDriver driver) {
17 | this.services = new Services(driver);
18 | }
19 |
20 | public String getHeading() {
21 | String heading = services.getText(xpathHeading);
22 | logger.info("Heading: " + heading);
23 | return heading;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/ChallengingDomPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 | import java.util.stream.Collectors;
11 |
12 | import static org.testng.Assert.assertEquals;
13 | import static org.testng.Assert.fail;
14 |
15 | /**
16 | * Created by: Anuj Kumar
17 | * Email: cdac.anuj@gmail.com
18 | * Date: 12-May-18
19 | */
20 | public class ChallengingDomPage extends Services {
21 |
22 | final static String HEADING = "Challenging DOM";
23 |
24 | String xpathHeading = "//h3";
25 | String xpathButtons = "//div[@class='large-2 columns']/a";
26 | String xpathButtonsViaContains = "//div[contains(@class,'large-2')]/a";
27 | String xpathButtonsViaStartsWith = "//div[starts-with(@class,'large-2')]/a";
28 |
29 | String xpathTable = "//div[contains(@class,'large-10')]";
30 | String xpathTableHeader = xpathTable + "/table//th";
31 | String xpathTableCell = xpathTable + "//tbody//tr[**row**]/td[**col**]";
32 |
33 | public ChallengingDomPage(WebDriver driver) {
34 | super(driver);
35 | }
36 |
37 | public void verifyChallengingDomPageHeader() {
38 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
39 | String actualHeading = headerEle.getText();
40 | assertEquals(actualHeading, HEADING,
41 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
42 | }
43 |
44 | public List getAllButtonText() {
45 | waitForElement(xpathButtonsViaContains);
46 | List lstBtns = driver.findElements(By.xpath(xpathButtonsViaContains));
47 | List buttons = new ArrayList<>();
48 | for (WebElement btn : lstBtns) {
49 | buttons.add(btn.getText());
50 | }
51 | return buttons;
52 | }
53 |
54 | public List getAllButtonTextJava8() {
55 | waitForElement(xpathButtonsViaContains);
56 | return driver.findElements(By.xpath(xpathButtonsViaContains))
57 | .stream()
58 | .map(WebElement::getText)
59 | .collect(Collectors.toList());
60 | }
61 |
62 | public void clickOnFirstButton() {
63 | String xpath = xpathButtons + "[1]";
64 | click(xpath);
65 | }
66 |
67 | public int getColumnIndex(String columnName) {
68 | waitForElement(xpathTableHeader);
69 | List lstCols = driver.findElements(By.xpath(xpathTableHeader));
70 | int index = 0;
71 | for (WebElement col : lstCols) {
72 | String actualCol = col.getText();
73 | index++;
74 | if (actualCol.equals(columnName)) {
75 | return index;
76 | }
77 | }
78 |
79 | fail("Given column name " + columnName + " is not present.");
80 | return index;
81 | }
82 |
83 | public String getCellText(int row, String columnName) {
84 | int col = getColumnIndex(columnName);
85 | String xpath = xpathTableCell.replace("**row**", row + "").replace("**col**", col + "");
86 | waitForElement(xpath);
87 | return driver.findElement(By.xpath(xpath)).getText();
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/CheckboxesPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 |
7 | import java.util.List;
8 |
9 | import static org.testng.Assert.*;
10 |
11 | /**
12 | * Created by: Anuj Kumar
13 | * Email: cdac.anuj@gmail.com
14 | * Date: 12-May-18
15 | */
16 | public class CheckboxesPage {
17 |
18 | final static String HEADING = "Checkboxes";
19 | WebDriver driver;
20 | String xpathHeading = "//h3";
21 | private String xpathCheckbox = "//form[@id='checkboxes']/input[**index**]";
22 | private String xpathCheckboxes = "//form[@id='checkboxes']/input";
23 |
24 | public CheckboxesPage(WebDriver driver) {
25 | this.driver = driver;
26 | }
27 |
28 | public void verifyCheckboxPageHeader() {
29 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
30 | String actualHeading = headerEle.getText();
31 | assertEquals(actualHeading, HEADING,
32 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
33 | }
34 |
35 | public void clickOnCheckbox(int index) {
36 | String xpath = xpathCheckbox.replace("**index**", index + "");
37 | driver.findElement(By.xpath(xpath)).click();
38 | }
39 |
40 | public void clickOnCheckbox(int index, boolean toSelect) {
41 | String xpath = xpathCheckbox.replace("**index**", index + "");
42 | WebElement checkboxEle = driver.findElement(By.xpath(xpath));
43 | changeStatus(checkboxEle, toSelect);
44 | }
45 |
46 | private void changeStatus(WebElement checkboxEle, boolean toSelect) {
47 | if (toSelect) {
48 | if (!checkboxEle.isSelected())
49 | checkboxEle.click();
50 | assertTrue(checkboxEle.isSelected(), "Check box is not selected.");
51 | } else {
52 | if (checkboxEle.isSelected())
53 | checkboxEle.click();
54 | assertFalse(checkboxEle.isSelected(), "Check box is selected.");
55 | }
56 | }
57 |
58 | public void toSelectAllCheckboxes(boolean toSelect) {
59 | List checkboxEles = driver.findElements(By.xpath(xpathCheckboxes));
60 | for (WebElement ch : checkboxEles)
61 | changeStatus(ch, toSelect);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/ContextMenuPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.openqa.selenium.*;
5 | import org.openqa.selenium.interactions.Actions;
6 |
7 | import static org.testng.Assert.assertEquals;
8 |
9 | /**
10 | * Created by: Anuj Kumar
11 | * Email: cdac.anuj@gmail.com
12 | * Date: 16-May-18
13 | */
14 | public class ContextMenuPage extends Services {
15 |
16 | private final static String HEADING = "Context Menu";
17 | private String xpathHeading = "//h3";
18 | private String xpathHotSpot = "//div[@id='hot-spot']";
19 |
20 | public ContextMenuPage(WebDriver driver) {
21 | super(driver);
22 | }
23 |
24 | public void verifyContextMenuPageHeader() {
25 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
26 | String actualHeading = headerEle.getText();
27 | assertEquals(actualHeading, HEADING,
28 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
29 | }
30 |
31 | public void verifyContextMenu() throws InterruptedException {
32 | waitForElement(xpathHotSpot);
33 | WebElement hotSpotEle = driver.findElement(By.xpath(xpathHotSpot));
34 |
35 | Actions actions = new Actions(driver);
36 | actions.contextClick(hotSpotEle).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN)
37 | .sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN)
38 | .sendKeys(Keys.ENTER).build().perform();
39 | Thread.sleep(2000);
40 | Alert alert = driver.switchTo().alert();
41 | alert.accept();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/DisappearingElementsPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | import static org.testng.Assert.assertEquals;
12 |
13 | /**
14 | * Created by: Anuj Kumar
15 | * Email: cdac.anuj@gmail.com
16 | * Date: 21-May-18
17 | */
18 | public class DisappearingElementsPage extends Services {
19 |
20 | final static String HEADING = "Disappearing Elements";
21 |
22 | String xpathHeading = "//h3";
23 | private String xpathMenu = "//ul//li//a";
24 | private String xpathMenuByTxt = xpathMenu + "[text()='**txt**']";
25 |
26 | public DisappearingElementsPage(WebDriver driver) {
27 | super(driver);
28 | }
29 |
30 | public void verifyDisappearingElementsPageHeader() {
31 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
32 | String actualHeading = headerEle.getText();
33 | assertEquals(actualHeading, HEADING,
34 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
35 | }
36 |
37 | public List getAllTabsName() {
38 | List tabNames = new ArrayList();
39 |
40 | List lstTabs = driver.findElements(By.xpath(xpathMenu));
41 | for (WebElement tab : lstTabs) {
42 | tabNames.add(tab.getText());
43 | }
44 | return tabNames;
45 | }
46 |
47 | public void verifyDisappearTab(String tabName) {
48 | String temp = xpathMenuByTxt.replace("**txt**", tabName);
49 | do {
50 | driver.navigate().refresh();
51 | System.out.println("Is Present: " + isElementPresent(temp));
52 | } while (!isElementPresent(temp));
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/DragAndDropPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 | import org.openqa.selenium.interactions.Actions;
8 |
9 | import static org.testng.Assert.assertEquals;
10 |
11 | /**
12 | * Created by: Anuj Kumar
13 | * Email: cdac.anuj@gmail.com
14 | * Date: 21-May-18
15 | */
16 | public class DragAndDropPage extends Services {
17 |
18 | private final static String HEADING = "Drag and Drop";
19 | private String xpathHeading = "//h3";
20 | private String xpathA = "//div[@id='column-a']";
21 | private String xpathB = "//div[@id='column-b']";
22 |
23 |
24 | public DragAndDropPage(WebDriver driver) {
25 | super(driver);
26 | }
27 |
28 | public void verifyDragAndDropPageHeader() {
29 | waitForElement(xpathHeading);
30 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
31 | String actualHeading = headerEle.getText();
32 | assertEquals(actualHeading, HEADING,
33 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
34 | }
35 |
36 | public void dragAtoB() {
37 | WebElement eleA = driver.findElement(By.xpath(xpathA));
38 | WebElement eleB = driver.findElement(By.xpath(xpathB));
39 | Actions actions = new Actions(driver);
40 | actions.dragAndDrop(eleA, eleB).build().perform();
41 | actions.clickAndHold(eleA).moveToElement(eleB).build().perform();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/DropdownPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
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 |
9 | import static org.testng.Assert.assertEquals;
10 |
11 | /**
12 | * Created by: Anuj Kumar
13 | * Email: cdac.anuj@gmail.com
14 | * Date: 12-May-18
15 | */
16 | public class DropdownPage extends Services {
17 |
18 | final static String HEADING = "Dropdown List";
19 | WebDriver driver;
20 | String xpathHeading = "//h3";
21 | String xpathDropdown = "//select[@id='dropdown']";
22 |
23 | public DropdownPage(WebDriver driver) {
24 | super(driver);
25 | this.driver = driver;
26 | }
27 |
28 | public void verifyDropdownPageHeader() {
29 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
30 | String actualHeading = headerEle.getText();
31 | assertEquals(actualHeading, HEADING,
32 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
33 | }
34 |
35 | public void selectDropDown(int index) {
36 | waitForElement(xpathDropdown);
37 | WebElement ele = driver.findElement(By.xpath(xpathDropdown));
38 | Select select = new Select(ele);
39 | select.selectByIndex(index);
40 | }
41 |
42 | public void selectDropDown(String text) {
43 | waitForElement(xpathDropdown);
44 | WebElement ele = driver.findElement(By.xpath(xpathDropdown));
45 |
46 | Select select = new Select(ele);
47 | select.selectByVisibleText(text);
48 | String actual = select.getFirstSelectedOption().getText();
49 |
50 | assertEquals(actual, text, "Actual " + actual + " should be same as expected " + text);
51 | }
52 |
53 | public void selectDropDownByValue(String text) {
54 | waitForElement(xpathDropdown);
55 | WebElement ele = driver.findElement(By.xpath(xpathDropdown));
56 |
57 | Select select = new Select(ele);
58 | select.selectByValue(text);
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/DynamicControlsPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 |
8 | import static org.testng.Assert.assertEquals;
9 |
10 | /**
11 | * Created by: Anuj Kumar
12 | * Email: cdac.anuj@gmail.com
13 | * Date: 21-May-18
14 | */
15 | public class DynamicControlsPage extends Services {
16 |
17 | private final static String HEADING = "Dynamic Controls";
18 | private String xpathHeading = "//h4";
19 | private String xpathBtn = "//button[@id='btn']";
20 | private String xpathCheckbox = "//div[@id='checkbox']";
21 | private String xpathLoading = "//div[@id='loading']";
22 |
23 |
24 | public DynamicControlsPage(WebDriver driver) {
25 | super(driver);
26 | }
27 |
28 | public void verifyDynamicControlsPageHeader() {
29 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
30 | String actualHeading = headerEle.getText();
31 | assertEquals(actualHeading, HEADING,
32 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
33 | }
34 |
35 | public void verifyRemove() {
36 | assertElementPresentByXpath(xpathCheckbox);
37 | click(xpathBtn);
38 | waitForLoading();
39 | assertElementNotPresentByXpath(xpathCheckbox);
40 | }
41 |
42 | public void verifyAdd() {
43 | verifyRemove();
44 | click(xpathBtn);
45 | waitForLoading();
46 | assertElementPresentByXpath(xpathCheckbox);
47 | }
48 |
49 | private void waitForLoading() {
50 | waitForElement(xpathLoading);
51 | waitForElementVisible(xpathLoading);
52 | assertElementVisible(xpathLoading, true);
53 | waitForElementInVisible(xpathLoading);
54 | assertElementVisible(xpathLoading, false);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/DynamicLoadingsPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 | import org.testng.Assert;
8 |
9 | import static org.testng.Assert.assertEquals;
10 |
11 | /**
12 | * Created by: Anuj Kumar
13 | * Email: cdac.anuj@gmail.com
14 | * Date: 21-May-18
15 | */
16 | public class DynamicLoadingsPage extends Services {
17 |
18 | private final static String HEADING = "Dynamically Loaded Page Elements";
19 | private final static String SUB_HEADING_1 = "Example 1: Element on page that is hidden";
20 | private final static String SUB_HEADING_2 = "Example 2: Element rendered after the fact";
21 | private String xpathHeading = "//h3";
22 | private String xpathSubHeading = "//h4";
23 | private String xpathBtn = "//div[@id='start']/button";
24 | private String xpathLoading = "//div[@id='loading']";
25 | private String xpathLinks = "//a[contains(text(),'**link**')]";
26 | private String xpathFinish = "//div[@id='finish']";
27 |
28 |
29 | public DynamicLoadingsPage(WebDriver driver) {
30 | super(driver);
31 | }
32 |
33 | public void verifyDynamicControlsPageHeader() {
34 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
35 | String actualHeading = headerEle.getText();
36 | assertEquals(actualHeading, HEADING,
37 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
38 | }
39 |
40 | public void clickOnLink(String link) {
41 |
42 | String xpath = xpathLinks.replace("**link**", link);
43 | click(xpath);
44 | waitForElement(xpathSubHeading);
45 | String actualHeading = driver.findElement(By.xpath(xpathSubHeading)).getText();
46 |
47 | if (link.contains("Example 1")) {
48 | Assert.assertEquals(actualHeading, SUB_HEADING_1);
49 | } else {
50 | Assert.assertEquals(actualHeading, SUB_HEADING_2);
51 | }
52 | }
53 |
54 | public void makeHiddenElementVisible() {
55 | assertElementPresentByXpath(xpathFinish);
56 | assertElementVisible(xpathFinish, false);
57 | click(xpathBtn);
58 | waitForLoading();
59 | assertElementPresentByXpath(xpathFinish);
60 | assertElementVisible(xpathFinish, true);
61 | }
62 |
63 | public void renderNewElement() {
64 | assertElementNotPresentByXpath(xpathFinish);
65 | click(xpathBtn);
66 | waitForLoading();
67 | assertElementPresentByXpath(xpathFinish);
68 | assertElementVisible(xpathFinish, true);
69 | }
70 |
71 |
72 | private void waitForLoading() {
73 | waitForElement(xpathLoading);
74 | waitForElementVisible(xpathLoading);
75 | assertElementVisible(xpathLoading, true);
76 | waitForElementInVisible(xpathLoading);
77 | assertElementVisible(xpathLoading, false);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/FileDownloaderPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 |
8 | import static org.testng.Assert.assertEquals;
9 |
10 | /**
11 | * Created by: Anuj Kumar
12 | * Email: cdac.anuj@gmail.com
13 | * Date: 12-May-18
14 | */
15 | public class FileDownloaderPage extends Services {
16 |
17 | final static String HEADING = "File Downloader";
18 | WebDriver driver;
19 | String xpathHeading = "//h3";
20 | String xpathLink = "//a[text()='some-file.txt']";
21 |
22 |
23 | public FileDownloaderPage(WebDriver driver) {
24 | super(driver);
25 | this.driver = driver;
26 | }
27 |
28 | public void verifyFileDownloaderHeader() {
29 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
30 | String actualHeading = headerEle.getText();
31 | assertEquals(actualHeading, HEADING,
32 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
33 | }
34 |
35 | public void verifyFileDownload() {
36 | click(xpathLink);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/FileUploaderPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 |
8 | import static org.testng.Assert.assertEquals;
9 |
10 | /**
11 | * Created by: Anuj Kumar
12 | * Email: cdac.anuj@gmail.com
13 | * Date: 12-May-18
14 | */
15 | public class FileUploaderPage extends Services {
16 |
17 | final static String HEADING = "File Uploader";
18 | WebDriver driver;
19 | String xpathHeading = "//h3";
20 | String xpathChooseFile = "//input[@id='file-upload']";
21 | String xpathBtn = "//input[@id='file-submit']";
22 | String xpathResult = "//div[@id='uploaded-files']";
23 |
24 |
25 | public FileUploaderPage(WebDriver driver) {
26 | super(driver);
27 | this.driver = driver;
28 | }
29 |
30 | public void verifyFileUploaderHeader() {
31 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
32 | String actualHeading = headerEle.getText();
33 | assertEquals(actualHeading, HEADING,
34 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
35 | }
36 |
37 | public void verifyFileUpload() {
38 | type(xpathChooseFile, "E:\\eclipse\\selLearning\\download\\menu.pdf");
39 | click(xpathBtn);
40 | waitForElement(xpathResult);
41 | assertEquals("menu.pdf", getWebElement(xpathResult).getText().trim());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/FramesPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 |
8 | import static org.testng.Assert.assertEquals;
9 |
10 | /**
11 | * Created by: Anuj Kumar
12 | * Email: cdac.anuj@gmail.com
13 | * Date: 21-May-18
14 | */
15 | public class FramesPage extends Services {
16 |
17 | private final static String HEADING = "Frames";
18 | private String xpathHeading = "//h3";
19 |
20 | private String xpathLinks = "//a[contains(text(),'**link**')]";
21 | private String xpathFrameTop = "//frame[@name='frame-top']";
22 | private String xpathFrameBottom = "//frame[@name='frame-bottom']";
23 | private String xpathFrameLeft = "//frame[@name='frame-left']";
24 | private String xpathFrameMiddle = "//frame[@name='frame-middle']";
25 | private String xpathIFrame = "//iframe";
26 |
27 |
28 | public FramesPage(WebDriver driver) {
29 | super(driver);
30 | }
31 |
32 | public void verifyFramesPageHeader() {
33 | waitForElement(xpathHeading);
34 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
35 | String actualHeading = headerEle.getText();
36 | assertEquals(actualHeading, HEADING,
37 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
38 | }
39 |
40 | public void clickOnLink(String link) {
41 | String xpath = xpathLinks.replace("**link**", link);
42 | click(xpath);
43 | }
44 |
45 | public void getFrameText() {
46 | waitForElement(xpathFrameBottom);
47 | WebElement bottomFrame = driver.findElement(By.xpath(xpathFrameBottom));
48 | driver.switchTo().frame(bottomFrame);
49 |
50 | System.out.println(driver.findElement(By.xpath("//body")).getText());
51 | driver.switchTo().parentFrame();
52 |
53 | WebElement topFrame = driver.findElement(By.xpath(xpathFrameTop));
54 | driver.switchTo().frame(topFrame);
55 |
56 | WebElement leftFrame = driver.findElement(By.xpath(xpathFrameLeft));
57 | driver.switchTo().frame(leftFrame);
58 |
59 | System.out.println(driver.findElement(By.xpath("//body")).getText());
60 | driver.switchTo().parentFrame();
61 |
62 | WebElement middleFrame = driver.findElement(By.xpath(xpathFrameMiddle));
63 | driver.switchTo().frame(middleFrame);
64 |
65 | System.out.println(driver.findElement(By.xpath("//body")).getText());
66 | }
67 |
68 |
69 | public void getIFrame() throws InterruptedException {
70 | waitForElement(xpathIFrame);
71 | WebElement iFrame = driver.findElement(By.xpath(xpathIFrame));
72 | driver.switchTo().frame(iFrame);
73 | WebElement editor = driver.findElement(By.xpath("//p"));
74 | System.out.println(editor.getText());
75 | editor.clear();
76 | editor.click();
77 | Thread.sleep(2000);
78 | editor.sendKeys("Anuj Kumar");
79 | Thread.sleep(2000);
80 | System.out.println(editor.getText());
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/HorizontalSliderPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.Dimension;
6 | import org.openqa.selenium.WebDriver;
7 | import org.openqa.selenium.WebElement;
8 | import org.openqa.selenium.interactions.Actions;
9 |
10 | import static org.testng.Assert.assertEquals;
11 |
12 | /**
13 | * Created by: Anuj Kumar
14 | * Email: cdac.anuj@gmail.com
15 | * Date: 21-May-18
16 | */
17 | public class HorizontalSliderPage extends Services {
18 |
19 | private final static String HEADING = "Horizontal Slider";
20 | private String xpathHeading = "//h3";
21 |
22 | private String xpathSlider = "//input";
23 |
24 |
25 | public HorizontalSliderPage(WebDriver driver) {
26 | super(driver);
27 | }
28 |
29 | public void verifyHorizontalSliderPageHeader() {
30 | waitForElement(xpathHeading);
31 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
32 | String actualHeading = headerEle.getText();
33 | assertEquals(actualHeading, HEADING,
34 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
35 | }
36 |
37 | public void horizontalSlide() throws InterruptedException {
38 | WebElement ele = getWebElement(xpathSlider);
39 |
40 | Dimension dimension = ele.getSize();
41 | System.out.println(dimension);
42 | System.out.println(dimension.getWidth());
43 | System.out.println(dimension.getHeight());
44 |
45 | Actions actions = new Actions(driver);
46 | actions.dragAndDropBy(ele, dimension.getWidth(), 0).build().perform();
47 | Thread.sleep(3000);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/HoverPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 | import org.openqa.selenium.interactions.Actions;
8 |
9 | import static org.testng.Assert.assertEquals;
10 |
11 | /**
12 | * Created by: Anuj Kumar
13 | * Email: cdac.anuj@gmail.com
14 | * Date: 21-May-18
15 | */
16 | public class HoverPage extends Services {
17 |
18 | private final static String HEADING = "Hovers";
19 | private String xpathHeading = "//h3";
20 |
21 | private String xpathImage1 = "//div[@class='figure'][2]";
22 | private String xpathName1 = xpathImage1 + "//div[@class='figcaption']/h5";
23 |
24 | public HoverPage(WebDriver driver) {
25 | super(driver);
26 | }
27 |
28 | public void verifyHoversPageHeader() {
29 | waitForElement(xpathHeading);
30 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
31 | String actualHeading = headerEle.getText();
32 | assertEquals(actualHeading, HEADING,
33 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
34 | }
35 |
36 | public void hoverOnImage() {
37 | WebElement img1 = driver.findElement(By.xpath(xpathImage1));
38 | Actions actions = new Actions(driver);
39 | actions.moveToElement(img1).build().perform();
40 | waitForElementVisible(xpathName1);
41 | assertElementPresentByXpath(xpathName1);
42 | System.out.println(driver.findElement(By.xpath(xpathName1)).getText());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/InfiniteScrollPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
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 |
9 | import static org.testng.Assert.assertEquals;
10 |
11 | /**
12 | * Created by: Anuj Kumar
13 | * Email: cdac.anuj@gmail.com
14 | * Date: 21-May-18
15 | */
16 | public class InfiniteScrollPage extends Services {
17 |
18 | private final static String HEADING = "Infinite Scroll";
19 | private String xpathHeading = "//h3";
20 |
21 | private String xpathImage1 = "//div[@class='figure'][2]";
22 |
23 | public InfiniteScrollPage(WebDriver driver) {
24 | super(driver);
25 | }
26 |
27 | public void verifyInfiniteScrollPageHeader() {
28 | waitForElement(xpathHeading);
29 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
30 | String actualHeading = headerEle.getText();
31 | assertEquals(actualHeading, HEADING,
32 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
33 | }
34 |
35 |
36 | public void scrollVerticallyPage() {
37 | String myScript = "window.scrollTo(0,document.body.scrollHeight)";
38 | ((JavascriptExecutor) driver).executeScript(myScript);
39 | }
40 |
41 | public void scrollHorizontallyPage() {
42 | String myScript = "window.scrollBy(400,0)";
43 | ((JavascriptExecutor) driver).executeScript(myScript);
44 | }
45 |
46 |
47 | public void scrollWithinParticularEle() {
48 | String myScript = "arguments[0].scrollIntoView();";
49 | WebElement element = driver.findElement(By.xpath("//td[@class='column-49' and text()='9.49']"));
50 | ((JavascriptExecutor) driver).executeScript(myScript, element);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/KeyPressesPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
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 |
10 | import static org.testng.Assert.assertEquals;
11 |
12 | /**
13 | * Created by: Anuj Kumar
14 | * Email: cdac.anuj@gmail.com
15 | * Date: 21-May-18
16 | */
17 | public class KeyPressesPage extends Services {
18 |
19 | private final static String HEADING = "Key Presses";
20 | private String xpathHeading = "//h3";
21 |
22 | public KeyPressesPage(WebDriver driver) {
23 | super(driver);
24 | }
25 |
26 | public void verifyKeyPressesPageHeader() {
27 | waitForElement(xpathHeading);
28 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
29 | String actualHeading = headerEle.getText();
30 | assertEquals(actualHeading, HEADING,
31 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
32 | }
33 |
34 | public void pressAnyKey() {
35 | Actions actions = new Actions(driver);
36 | actions.sendKeys(Keys.NUMPAD5).build().perform();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/LargeDeepDOMPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 |
8 | import static org.testng.Assert.assertEquals;
9 |
10 | /**
11 | * Created by: Anuj Kumar
12 | * Email: cdac.anuj@gmail.com
13 | * Date: 16-May-18
14 | */
15 | public class LargeDeepDOMPage extends Services {
16 |
17 | static final String FOLLOWING_SIBLINGS_XPATH =
18 | "//div[@id='sibling-1.2']/following-sibling::div[not(contains(@class,'parent'))]";
19 | static final String PRECEDING_SIBLINGS_XPATH =
20 | "//div[@id='sibling-1.3']/preceding-sibling::div[not(contains(@class,'parent'))]";
21 | static final String PARENT_XPATH = "//div[@id='sibling-2.2']/parent::div";
22 | static final String ANCESTOR_XPATH =
23 | "//div[@id='sibling-2.2']/ancestor::div[contains(@id,'sib')]";
24 | static final String DOM_ELE_XPATH = "//div[text()='**dynamic**']";
25 | private final static String HEADING = "Large & Deep DOM";
26 | private String xpathHeading = "//h3";
27 |
28 | public LargeDeepDOMPage(WebDriver driver) {
29 | super(driver);
30 | }
31 |
32 | public void verifyLargeDeepDOMPageHeader() {
33 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
34 | String actualHeading = headerEle.getText();
35 | assertEquals(actualHeading, HEADING,
36 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
37 | }
38 |
39 | public void getLargeDOMText() {
40 |
41 | System.out.println(getText(FOLLOWING_SIBLINGS_XPATH));
42 | System.out.println(getText(PRECEDING_SIBLINGS_XPATH));
43 |
44 | }
45 |
46 | public String getText(String locator) {
47 | return driver.findElement(By.xpath(locator)).getText();
48 | }
49 |
50 |
51 | public void getParent(String cellText) {
52 | String xpath = DOM_ELE_XPATH.replace("**dynamic**", cellText);
53 | WebElement currEle = driver.findElement(By.xpath(xpath));
54 | WebElement parent =
55 | driver.findElement(By.xpath(xpath + "/parent::div[contains(@class,'parent')]"));
56 | System.out.println("Parent of " + currEle.getText() + ": " + parent.getText());
57 | }
58 |
59 | public void getAncestor(String cellText) {
60 | String xpath = DOM_ELE_XPATH.replace("**dynamic**", cellText);
61 | WebElement currEle = driver.findElement(By.xpath(xpath));
62 | WebElement parent = driver.findElement(By.xpath(xpath + "/ancestor::div[@class='row']//h3"));
63 | System.out.println("Ancestor of " + currEle.getText() + ": " + parent.getText());
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/LoginPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 |
8 | import static org.testng.Assert.assertEquals;
9 | import static org.testng.Assert.assertTrue;
10 |
11 | /**
12 | * Created by: Anuj Kumar
13 | * Email: cdac.anuj@gmail.com
14 | * Date: 21-May-18
15 | */
16 | public class LoginPage extends Services {
17 |
18 | private final static String HEADING = "Login Page";
19 | public static final String MSG_SUCCESS = "You logged into a secure area!";
20 | private static final String MSG_ERROR = "Your username is invalid!";
21 | private static final String MSG_LOGOUT = "You logged out of the secure area!";
22 | private String xpathHeading = "//h2";
23 |
24 | //XPATH
25 | private String xpathUsername = "//input[@name='username']";
26 | private String xpathPassword = "//input[@name='password']";
27 | private String xpathLoginBtn = "//button[@type='submit']";
28 |
29 | //CSS
30 | private String cssUsername = "input[name='username']";
31 | private String cssPassword = "input[name='password']";
32 | private String cssLoginBtn = "button[type='submit']";
33 |
34 | private String xpathLogoutBtn = "//a[contains(@class,'button')]";
35 | private String xpathMsg = "//div[@id='flash']";
36 |
37 |
38 | public LoginPage(WebDriver driver) {
39 | super(driver);
40 | }
41 |
42 | public void verifyLoginPageHeader() {
43 | waitForElement(xpathHeading);
44 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
45 | String actualHeading = headerEle.getText();
46 | assertEquals(actualHeading, HEADING,
47 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
48 | }
49 |
50 | public void verifyLogin(String username, String password) {
51 | loginAction(username, password);
52 | waitForElementVisible(xpathMsg);
53 | String actualMsg = driver.findElement(By.xpath(xpathMsg)).getText().trim();
54 | assertTrue(actualMsg.contains(MSG_SUCCESS),
55 | "Actual '" + actualMsg + "' should be same as expected '" + MSG_SUCCESS + "'.");
56 | }
57 |
58 | public String getMsgSuccess() {
59 | waitForElementVisible(xpathMsg);
60 | return driver.findElement(By.xpath(xpathMsg)).getText().trim();
61 | }
62 |
63 | public void loginAction(String username, String password) {
64 | type(xpathUsername, username);
65 | type(xpathPassword, password);
66 | click(xpathLoginBtn);
67 | }
68 |
69 | public void loginActionUsingCssSelector(String username, String password) {
70 | typeViaCss(cssUsername, username);
71 | typeViaCss(cssPassword, password);
72 | clickViaCss(cssLoginBtn);
73 | }
74 |
75 | public void loginActionJava8(String username, String password) {
76 | type(By::xpath, xpathUsername, username);
77 | type(By::cssSelector, cssPassword, password);
78 | click(xpathLoginBtn);
79 | }
80 |
81 | public void verifyLoginAndLogout(String username, String password) {
82 | verifyLogin(username, password);
83 | waitForElementVisible(xpathLogoutBtn);
84 | click(xpathLogoutBtn);
85 | waitForElementVisible(xpathMsg);
86 | String actualMsg = driver.findElement(By.xpath(xpathMsg)).getText().trim();
87 | assertTrue(actualMsg.contains(MSG_LOGOUT),
88 | "Actual '" + actualMsg + "' should be same as expected '" + MSG_LOGOUT + "'.");
89 | }
90 |
91 | public void verifyLoginWithInvalidUser(String username, String password) {
92 | type(xpathUsername, username);
93 | type(xpathPassword, password);
94 | click(xpathLoginBtn);
95 |
96 | waitForElementVisible(xpathMsg);
97 | String actualMsg = driver.findElement(By.xpath(xpathMsg)).getText().trim();
98 |
99 | assertTrue(actualMsg.contains(MSG_ERROR),
100 | "Actual '" + actualMsg + "' should be same as expected '" + MSG_ERROR + "'.");
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/MultipleWindowsPage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import auto.utility.Services;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 |
8 | import java.util.Iterator;
9 | import java.util.Set;
10 |
11 | import static org.testng.Assert.assertEquals;
12 |
13 | /**
14 | * Created by: Anuj Kumar
15 | * Email: cdac.anuj@gmail.com
16 | * Date: 21-May-18
17 | */
18 | public class MultipleWindowsPage extends Services {
19 |
20 | private final static String HEADING = "Opening a new window";
21 | private String xpathHeading = "//h3";
22 |
23 | private String xpathLink = "//a[text()='Click Here']";
24 |
25 |
26 | public MultipleWindowsPage(WebDriver driver) {
27 | super(driver);
28 | }
29 |
30 | public void verifyMultipleWindowsPageHeader() {
31 | waitForElement(xpathHeading);
32 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
33 | String actualHeading = headerEle.getText();
34 | assertEquals(actualHeading, HEADING,
35 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
36 | }
37 |
38 | public void clickOnLink() {
39 | click(xpathLink);
40 | }
41 |
42 | public void getTextOnNewWindow() throws InterruptedException {
43 | Set windowHandles = driver.getWindowHandles();
44 | System.out.println(windowHandles);
45 | Iterator itr = windowHandles.iterator();
46 | while (itr.hasNext()) {
47 | String win = itr.next();
48 | driver.switchTo().window(win);
49 | Thread.sleep(3000);
50 | if (driver.getTitle().equals("New Window")) {
51 | System.out.println(getWebElement("//h3").getText());
52 | driver.close();
53 | }
54 | }
55 |
56 | windowHandles = driver.getWindowHandles();
57 | System.out.println(windowHandles);
58 | itr = windowHandles.iterator();
59 |
60 | while (itr.hasNext()) {
61 | String win = itr.next();
62 | driver.switchTo().window(win);
63 | Thread.sleep(3000);
64 | if (driver.getTitle().equals("The Internet")) {
65 | System.out.println(getWebElement("//h3").getText());
66 | }
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/test/java/auto/pages/WelcomePage.java:
--------------------------------------------------------------------------------
1 | package auto.pages;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 |
7 | import static org.testng.Assert.assertEquals;
8 |
9 | /**
10 | * Created by: Anuj Kumar
11 | * Email: cdac.anuj@gmail.com
12 | * Date: 12-May-18
13 | */
14 | public class WelcomePage {
15 |
16 | final static String TITLE = "The Internet";
17 | final static String HEADING = "Welcome to the-internet";
18 | WebDriver driver;
19 | String xpathHeading = "//h1";
20 | String xpathLink = "//ul/li/a[text()='**link**']";
21 |
22 | public WelcomePage(WebDriver driver) {
23 | this.driver = driver;
24 | }
25 |
26 | public void verifyWelcomePageTitle() {
27 | String actualTitle = driver.getTitle();
28 | assertEquals(actualTitle, TITLE,
29 | "Actual title " + actualTitle + " should be same as expected " + TITLE);
30 | }
31 |
32 | public void verifyWelcomePageHeader() {
33 | WebElement headerEle = driver.findElement(By.xpath(xpathHeading));
34 | String actualHeading = headerEle.getText();
35 | assertEquals(actualHeading, HEADING,
36 | "Actual heading '" + actualHeading + "' should be same as expected '" + HEADING + "'.");
37 | }
38 |
39 | public void clickOnLinkViaLinkText(String link) {
40 | driver.findElement(By.linkText(link)).click();
41 | }
42 |
43 | public void clickOnLinkViaPartialText(String link) {
44 | driver.findElement(By.partialLinkText(link)).click();
45 | }
46 |
47 | public Object clickOnLink(String link) {
48 | xpathLink = xpathLink.replace("**link**", link);
49 | driver.findElement(By.xpath(xpathLink)).click();
50 | return this;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestAlert.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.AlertPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 |
8 | /**
9 | * Created by: Anuj Kumar
10 | * Email: cdac.anuj@gmail.com
11 | * Date: 21-May-18
12 | */
13 | public class TestAlert extends Init {
14 |
15 | @Test(groups = {"smoke", "regression"})
16 | public void testClickForJSAlert() {
17 | WelcomePage welcomePage = new WelcomePage(driver);
18 | welcomePage.verifyWelcomePageTitle();
19 | welcomePage.verifyWelcomePageHeader();
20 | welcomePage.clickOnLink("JavaScript Alerts");
21 |
22 | AlertPage alertPage = new AlertPage(driver);
23 | alertPage.verifyAlertPageHeader();
24 | alertPage.clickOnButton("Click for JS Alert");
25 | alertPage.accept();
26 |
27 | }
28 |
29 | @Test(groups = {"regression"})
30 | public void testClickForJSConfirm() {
31 | WelcomePage welcomePage = new WelcomePage(driver);
32 | welcomePage.verifyWelcomePageTitle();
33 | welcomePage.verifyWelcomePageHeader();
34 | welcomePage.clickOnLink("JavaScript Alerts");
35 |
36 | AlertPage alertPage = new AlertPage(driver);
37 | alertPage.verifyAlertPageHeader();
38 | alertPage.clickOnButton("Click for JS Confirm");
39 | alertPage.cancel();
40 | }
41 |
42 | @Test(groups = {"alert"})
43 | public void testClickForJSPrompt() {
44 | WelcomePage welcomePage = new WelcomePage(driver);
45 | welcomePage.verifyWelcomePageTitle();
46 | welcomePage.verifyWelcomePageHeader();
47 | welcomePage.clickOnLink("JavaScript Alerts");
48 |
49 | AlertPage alertPage = new AlertPage(driver);
50 | alertPage.verifyAlertPageHeader();
51 | alertPage.clickOnButton("Click for JS Prompt");
52 | alertPage.typeAndAccept();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestBasicAuth.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.BasicAuthPage;
4 | import auto.utility.Init;
5 | import org.testng.annotations.Test;
6 |
7 | import static auto.pages.BasicAuthPage.HEADING;
8 | import static org.testng.Assert.assertEquals;
9 |
10 | public class TestBasicAuth extends Init {
11 |
12 | @Test
13 | public void testBasicAuth() throws InterruptedException {
14 | driver.get("https://admin:admin@the-internet.herokuapp.com/basic_auth");
15 | BasicAuthPage basicAuthPage = new BasicAuthPage(driver);
16 | String actual = basicAuthPage.getHeading();
17 | assertEquals(actual, HEADING);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestChallengingDomPage.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.ChallengingDomPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 |
8 | import java.util.List;
9 |
10 | import static org.testng.Assert.assertEquals;
11 |
12 | /**
13 | * Created by: Anuj Kumar
14 | * Email: cdac.anuj@gmail.com
15 | * Date: 12-May-18
16 | */
17 | public class TestChallengingDomPage extends Init {
18 |
19 | @Test
20 | public void testChallengingPage() {
21 | WelcomePage welcomePage = new WelcomePage(driver);
22 | welcomePage.verifyWelcomePageTitle();
23 | welcomePage.verifyWelcomePageHeader();
24 | welcomePage.clickOnLink("Challenging DOM");
25 |
26 | ChallengingDomPage challengingDomPage = new ChallengingDomPage(driver);
27 | challengingDomPage.verifyChallengingDomPageHeader();
28 | }
29 |
30 | @Test
31 | public void testListOfButtons() {
32 | WelcomePage welcomePage = new WelcomePage(driver);
33 | welcomePage.verifyWelcomePageTitle();
34 | welcomePage.verifyWelcomePageHeader();
35 | welcomePage.clickOnLink("Challenging DOM");
36 |
37 | ChallengingDomPage challengingDomPage = new ChallengingDomPage(driver);
38 | challengingDomPage.verifyChallengingDomPageHeader();
39 | List buttons = challengingDomPage.getAllButtonText();
40 | assertEquals(buttons.size(), 3);
41 | }
42 |
43 | @Test
44 | public void testChallengingPageViaJava8() {
45 | WelcomePage welcomePage = new WelcomePage(driver);
46 | welcomePage.verifyWelcomePageTitle();
47 | welcomePage.verifyWelcomePageHeader();
48 | welcomePage.clickOnLink("Challenging DOM");
49 |
50 | ChallengingDomPage challengingDomPage = new ChallengingDomPage(driver);
51 | challengingDomPage.verifyChallengingDomPageHeader();
52 | List lst = challengingDomPage.getAllButtonTextJava8();
53 | System.out.println(lst);
54 | assertEquals(lst.size(), 3);
55 | }
56 |
57 | @Test
58 | public void testCellText() {
59 | WelcomePage welcomePage = new WelcomePage(driver);
60 | welcomePage.verifyWelcomePageTitle();
61 | welcomePage.verifyWelcomePageHeader();
62 | welcomePage.clickOnLink("Challenging DOM");
63 |
64 | ChallengingDomPage challengingDomPage = new ChallengingDomPage(driver);
65 | challengingDomPage.verifyChallengingDomPageHeader();
66 |
67 | assertEquals(challengingDomPage.getCellText(3, "Sit"), "Definiebas2");
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestCheckboxPage.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.CheckboxesPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 |
8 | /**
9 | * Created by: Anuj Kumar
10 | * Email: cdac.anuj@gmail.com
11 | * Date: 12-May-18
12 | */
13 | public class TestCheckboxPage extends Init {
14 |
15 | @Test
16 | public void testCheckboxPage() {
17 | WelcomePage welcomePage = new WelcomePage(driver);
18 | welcomePage.verifyWelcomePageTitle();
19 | welcomePage.verifyWelcomePageHeader();
20 | welcomePage.clickOnLink("Checkboxes");
21 |
22 | CheckboxesPage checkboxesPage = new CheckboxesPage(driver);
23 | checkboxesPage.verifyCheckboxPageHeader();
24 | checkboxesPage.clickOnCheckbox(3);
25 | }
26 |
27 | @Test
28 | public void testCheckboxViaSmartWay() throws InterruptedException {
29 | WelcomePage welcomePage = new WelcomePage(driver);
30 | welcomePage.verifyWelcomePageTitle();
31 | welcomePage.verifyWelcomePageHeader();
32 | welcomePage.clickOnLink("Checkboxes");
33 |
34 | CheckboxesPage checkboxesPage = new CheckboxesPage(driver);
35 | checkboxesPage.verifyCheckboxPageHeader();
36 | checkboxesPage.clickOnCheckbox(2, false);
37 | }
38 |
39 | @Test
40 | public void testToSelectAllCheckboxes() throws InterruptedException {
41 | WelcomePage welcomePage = new WelcomePage(driver);
42 | welcomePage.verifyWelcomePageTitle();
43 | welcomePage.verifyWelcomePageHeader();
44 | welcomePage.clickOnLink("Checkboxes");
45 |
46 | CheckboxesPage checkboxesPage = new CheckboxesPage(driver);
47 | checkboxesPage.verifyCheckboxPageHeader();
48 | checkboxesPage.toSelectAllCheckboxes(false);
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestContextMenuPage.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.ContextMenuPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 |
8 | /**
9 | * Created by: Anuj Kumar
10 | * Email: cdac.anuj@gmail.com
11 | * Date: 16-May-18
12 | */
13 | public class TestContextMenuPage extends Init {
14 |
15 | @Test
16 | public void testChallengingPage() throws InterruptedException {
17 |
18 | WelcomePage welcomePage = new WelcomePage(driver);
19 | welcomePage.verifyWelcomePageTitle();
20 | welcomePage.verifyWelcomePageHeader();
21 | welcomePage.clickOnLink("Context Menu");
22 |
23 | ContextMenuPage contextMenuPage = new ContextMenuPage(driver);
24 | contextMenuPage.verifyContextMenuPageHeader();
25 | contextMenuPage.verifyContextMenu();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestDisappearingElementsPage.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.DisappearingElementsPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 |
8 | import java.util.List;
9 | /**
10 | * Created by: Anuj Kumar
11 | * Email: cdac.anuj@gmail.com
12 | * Date: 21-May-18
13 | */
14 | public class TestDisappearingElementsPage extends Init {
15 |
16 | @Test
17 | public void testChallengingPage() throws InterruptedException {
18 | WelcomePage welcomePage = new WelcomePage(driver);
19 | welcomePage.verifyWelcomePageTitle();
20 | welcomePage.verifyWelcomePageHeader();
21 | welcomePage.clickOnLink("Disappearing Elements");
22 |
23 | DisappearingElementsPage disappearingElementsPage = new DisappearingElementsPage(driver);
24 | disappearingElementsPage.verifyDisappearingElementsPageHeader();
25 | List tabNames = disappearingElementsPage.getAllTabsName();
26 | System.out.println(tabNames);
27 | disappearingElementsPage.verifyDisappearTab("Gallery");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestDragAndDrop.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.DragAndDropPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 | /**
8 | * Created by: Anuj Kumar
9 | * Email: cdac.anuj@gmail.com
10 | * Date: 21-May-18
11 | */
12 | public class TestDragAndDrop extends Init {
13 |
14 | @Test
15 | public void testDragAndDrop() {
16 | WelcomePage welcomePage = new WelcomePage(driver);
17 | welcomePage.verifyWelcomePageTitle();
18 | welcomePage.verifyWelcomePageHeader();
19 | welcomePage.clickOnLink("Drag and Drop");
20 |
21 | DragAndDropPage dragAndDropPage = new DragAndDropPage(driver);
22 | dragAndDropPage.verifyDragAndDropPageHeader();
23 | dragAndDropPage.dragAtoB();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestDropdownPage.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.DropdownPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 | /**
8 | * Created by: Anuj Kumar
9 | * Email: cdac.anuj@gmail.com
10 | * Date: 12-May-18
11 | */
12 | public class TestDropdownPage extends Init {
13 |
14 | @Test
15 | public void testDropdownPage() throws InterruptedException {
16 | System.out.println("testMe");
17 | WelcomePage welcomePage = new WelcomePage(driver);
18 | welcomePage.verifyWelcomePageTitle();
19 | welcomePage.verifyWelcomePageHeader();
20 | welcomePage.clickOnLink("Dropdown");
21 |
22 | DropdownPage dropdownPage = new DropdownPage(driver);
23 | dropdownPage.verifyDropdownPageHeader();
24 | //dropdownPage.selectDropDown(1);
25 | dropdownPage.selectDropDown("Option 2");
26 | //dropdownPage.selectDropDownByValue("2");
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestDynamicControls.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.DynamicControlsPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 |
8 | /**
9 | * Created by: Anuj Kumar
10 | * Email: cdac.anuj@gmail.com
11 | * Date: 21-May-18
12 | */
13 | public class TestDynamicControls extends Init {
14 |
15 | @Test
16 | public void testDynamicControlsRemove() {
17 | WelcomePage welcomePage = new WelcomePage(driver);
18 | welcomePage.verifyWelcomePageTitle();
19 | welcomePage.verifyWelcomePageHeader();
20 | welcomePage.clickOnLink("Dynamic Controls");
21 |
22 | DynamicControlsPage controlsPage = new DynamicControlsPage(driver);
23 | controlsPage.verifyDynamicControlsPageHeader();
24 | controlsPage.verifyRemove();
25 | }
26 |
27 | @Test
28 | public void testDynamicControlsAdd() {
29 | WelcomePage welcomePage = new WelcomePage(driver);
30 | welcomePage.verifyWelcomePageTitle();
31 | welcomePage.verifyWelcomePageHeader();
32 | welcomePage.clickOnLink("Dynamic Controls");
33 |
34 | DynamicControlsPage controlsPage = new DynamicControlsPage(driver);
35 | controlsPage.verifyDynamicControlsPageHeader();
36 | controlsPage.verifyAdd();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestDynamicLoadings.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.DynamicLoadingsPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 |
8 | /**
9 | * Created by: Anuj Kumar
10 | * Email: cdac.anuj@gmail.com
11 | * Date: 21-May-18
12 | */
13 | public class TestDynamicLoadings extends Init {
14 |
15 | @Test
16 | public void testDynamicLoadingsHidden() {
17 | WelcomePage welcomePage = new WelcomePage(driver);
18 | welcomePage.verifyWelcomePageTitle();
19 | welcomePage.verifyWelcomePageHeader();
20 | welcomePage.clickOnLink("Dynamic Loading");
21 |
22 | DynamicLoadingsPage dynamicloadingsPage = new DynamicLoadingsPage(driver);
23 | dynamicloadingsPage.verifyDynamicControlsPageHeader();
24 | dynamicloadingsPage.clickOnLink("Example 1");
25 | dynamicloadingsPage.makeHiddenElementVisible();
26 | }
27 |
28 | @Test
29 | public void testDynamicLoadingsRender() {
30 | WelcomePage welcomePage = new WelcomePage(driver);
31 | welcomePage.verifyWelcomePageTitle();
32 | welcomePage.verifyWelcomePageHeader();
33 | welcomePage.clickOnLink("Dynamic Loading");
34 |
35 | DynamicLoadingsPage dynamicloadingsPage = new DynamicLoadingsPage(driver);
36 | dynamicloadingsPage.verifyDynamicControlsPageHeader();
37 | dynamicloadingsPage.clickOnLink("Example 2");
38 | dynamicloadingsPage.renderNewElement();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestFileDownloader.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.FileDownloaderPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 |
8 | /**
9 | * Created by: Anuj Kumar
10 | * Email: cdac.anuj@gmail.com
11 | * Date: 21-May-18
12 | */
13 | public class TestFileDownloader extends Init {
14 |
15 | @Test
16 | public void testFrame() throws InterruptedException {
17 | WelcomePage welcomePage = new WelcomePage(driver);
18 | welcomePage.verifyWelcomePageTitle();
19 | welcomePage.verifyWelcomePageHeader();
20 | welcomePage.clickOnLink("File Download");
21 |
22 | FileDownloaderPage downloaderPage = new FileDownloaderPage(driver);
23 | downloaderPage.verifyFileDownloaderHeader();
24 | downloaderPage.verifyFileDownload();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestFileUploader.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.FileUploaderPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 |
8 | /**
9 | * Created by: Anuj Kumar
10 | * Email: cdac.anuj@gmail.com
11 | * Date: 21-May-18
12 | */
13 | public class TestFileUploader extends Init {
14 |
15 | @Test
16 | public void testFrame() {
17 | WelcomePage welcomePage = new WelcomePage(driver);
18 | welcomePage.verifyWelcomePageTitle();
19 | welcomePage.verifyWelcomePageHeader();
20 | welcomePage.clickOnLink("File Upload");
21 |
22 | FileUploaderPage fileUploaderPage = new FileUploaderPage(driver);
23 | fileUploaderPage.verifyFileUploaderHeader();
24 | fileUploaderPage.verifyFileUpload();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestFrame.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.FramesPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 |
8 | /**
9 | * Created by: Anuj Kumar
10 | * Email: cdac.anuj@gmail.com
11 | * Date: 21-May-18
12 | */
13 | public class TestFrame extends Init {
14 |
15 | @Test
16 | public void testFrame() {
17 | WelcomePage welcomePage = new WelcomePage(driver);
18 | welcomePage.verifyWelcomePageTitle();
19 | welcomePage.verifyWelcomePageHeader();
20 | welcomePage.clickOnLink("Frames");
21 |
22 | FramesPage framesPage = new FramesPage(driver);
23 | framesPage.verifyFramesPageHeader();
24 | framesPage.clickOnLink("Nested Frames");
25 | framesPage.getFrameText();
26 | }
27 |
28 | @Test
29 | public void testIFrame() throws InterruptedException {
30 | WelcomePage welcomePage = new WelcomePage(driver);
31 | welcomePage.verifyWelcomePageTitle();
32 | welcomePage.verifyWelcomePageHeader();
33 | welcomePage.clickOnLink("Frames");
34 |
35 | FramesPage framesPage = new FramesPage(driver);
36 | framesPage.verifyFramesPageHeader();
37 | framesPage.clickOnLink("iFrame");
38 | framesPage.getIFrame();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestHorizontalSlider.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.HorizontalSliderPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 |
8 | /**
9 | * Created by: Anuj Kumar
10 | * Email: cdac.anuj@gmail.com
11 | * Date: 21-May-18
12 | */
13 | public class TestHorizontalSlider extends Init {
14 |
15 | @Test
16 | public void testFrame() throws InterruptedException {
17 | WelcomePage welcomePage = new WelcomePage(driver);
18 | welcomePage.verifyWelcomePageTitle();
19 | welcomePage.verifyWelcomePageHeader();
20 | welcomePage.clickOnLink("Horizontal Slider");
21 |
22 | HorizontalSliderPage horizontalSliderPage = new HorizontalSliderPage(driver);
23 | horizontalSliderPage.verifyHorizontalSliderPageHeader();
24 | horizontalSliderPage.horizontalSlide();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestHover.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.HoverPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 |
8 | /**
9 | * Created by: Anuj Kumar
10 | * Email: cdac.anuj@gmail.com
11 | * Date: 21-May-18
12 | */
13 | public class TestHover extends Init {
14 |
15 | @Test
16 | public void testFrame() {
17 | WelcomePage welcomePage = new WelcomePage(driver);
18 | welcomePage.verifyWelcomePageTitle();
19 | welcomePage.verifyWelcomePageHeader();
20 | welcomePage.clickOnLink("Hovers");
21 |
22 | HoverPage hoverPage = new HoverPage(driver);
23 | hoverPage.verifyHoversPageHeader();
24 | hoverPage.hoverOnImage();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestInfiniteScroll.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.InfiniteScrollPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 |
8 | /**
9 | * Created by: Anuj Kumar
10 | * Email: cdac.anuj@gmail.com
11 | * Date: 21-May-18
12 | */
13 | public class TestInfiniteScroll extends Init {
14 |
15 | @Test
16 | public void testFrame() throws InterruptedException {
17 | WelcomePage welcomePage = new WelcomePage(driver);
18 | InfiniteScrollPage infiniteScrollPage = new InfiniteScrollPage(driver);
19 | welcomePage.verifyWelcomePageTitle();
20 | welcomePage.verifyWelcomePageHeader();
21 | welcomePage.clickOnLink("Large & Deep DOM");
22 |
23 | //infiniteScrollPage.verifyInfiniteScrollPageHeader();
24 | infiniteScrollPage.scrollWithinParticularEle();
25 | Thread.sleep(5000);
26 | infiniteScrollPage.scrollVerticallyPage();
27 | infiniteScrollPage.scrollHorizontallyPage();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestKeyPresses.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.KeyPressesPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 | /**
8 | * Created by: Anuj Kumar
9 | * Email: cdac.anuj@gmail.com
10 | * Date: 21-May-18
11 | */
12 | public class TestKeyPresses extends Init {
13 |
14 | @Test
15 | public void testKeyPresses() {
16 | WelcomePage welcomePage = new WelcomePage(driver);
17 | welcomePage.verifyWelcomePageTitle();
18 | welcomePage.verifyWelcomePageHeader();
19 | welcomePage.clickOnLink("Key Presses");
20 |
21 | KeyPressesPage keyPressesPage = new KeyPressesPage(driver);
22 | keyPressesPage.verifyKeyPressesPageHeader();
23 | keyPressesPage.pressAnyKey();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestLargeDeepDOM.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.LargeDeepDOMPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 |
8 | /**
9 | * Created by: Anuj Kumar
10 | * Email: cdac.anuj@gmail.com
11 | * Date: 21-May-18
12 | */
13 | public class TestLargeDeepDOM extends Init {
14 |
15 | @Test
16 | public void testLargeDeepDOM() {
17 | WelcomePage welcomePage = new WelcomePage(driver);
18 | welcomePage.verifyWelcomePageTitle();
19 | welcomePage.verifyWelcomePageHeader();
20 | welcomePage.clickOnLink("Large & Deep DOM");
21 |
22 | LargeDeepDOMPage deepDOMPage = new LargeDeepDOMPage(driver);
23 | deepDOMPage.verifyLargeDeepDOMPageHeader();
24 | deepDOMPage.getLargeDOMText();
25 |
26 | deepDOMPage.getParent("2.3");
27 | deepDOMPage.getAncestor("2.3");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestLogin.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.LoginPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.DataProvider;
7 | import org.testng.annotations.Test;
8 |
9 | import static auto.pages.LoginPage.MSG_SUCCESS;
10 | import static org.testng.Assert.assertTrue;
11 |
12 | /**
13 | * Created by: Anuj Kumar
14 | * Email: cdac.anuj@gmail.com
15 | * Date: 21-May-18
16 | */
17 | public class TestLogin extends Init {
18 |
19 | @DataProvider
20 | public static Object[][] validCredentials() {
21 | return new Object[][]{{"tomsmith", "SuperSecretPassword!"}};
22 | }
23 |
24 | @DataProvider
25 | public static Object[][] invalidCredentials() {
26 | return new Object[][]{{"abc", "abc"}};
27 | }
28 |
29 | @Test(dataProvider = "validCredentials")
30 | public void testLoginUsingXpath(String username, String password) {
31 | WelcomePage welcomePage = new WelcomePage(driver);
32 | welcomePage.verifyWelcomePageTitle();
33 | welcomePage.verifyWelcomePageHeader();
34 | welcomePage.clickOnLink("Form Authentication");
35 |
36 | LoginPage loginPage = new LoginPage(driver);
37 | loginPage.verifyLoginPageHeader();
38 |
39 | // loginAction method - in which xpath is used as locator
40 | loginPage.loginAction(username, password);
41 |
42 | String actualMsg = loginPage.getMsgSuccess();
43 | assertTrue(actualMsg.contains(MSG_SUCCESS),
44 | "Actual '" + actualMsg + "' should be same as expected '" + MSG_SUCCESS + "'.");
45 | }
46 |
47 |
48 | @Test(dataProvider = "validCredentials")
49 | public void testLoginUsingCssSelector(String username, String password) {
50 | WelcomePage welcomePage = new WelcomePage(driver);
51 | welcomePage.verifyWelcomePageTitle();
52 | welcomePage.verifyWelcomePageHeader();
53 | welcomePage.clickOnLink("Form Authentication");
54 |
55 | LoginPage loginPage = new LoginPage(driver);
56 | loginPage.verifyLoginPageHeader();
57 |
58 | // loginActionUsingCssSelector method - in which cssSelector is used as locator
59 | loginPage.loginActionUsingCssSelector(username, password);
60 |
61 | String actualMsg = loginPage.getMsgSuccess();
62 | assertTrue(actualMsg.contains(MSG_SUCCESS),
63 | "Actual '" + actualMsg + "' should be same as expected '" + MSG_SUCCESS + "'.");
64 | }
65 |
66 | @Test(dataProvider = "validCredentials")
67 | public void testLoginByJava8Way(String username, String password) {
68 | WelcomePage welcomePage = new WelcomePage(driver);
69 | welcomePage.verifyWelcomePageTitle();
70 | welcomePage.verifyWelcomePageHeader();
71 | welcomePage.clickOnLink("Form Authentication");
72 |
73 | LoginPage loginPage = new LoginPage(driver);
74 | loginPage.verifyLoginPageHeader();
75 |
76 | // loginActionJava8 method - in which we can use any way XPATH or CSS or ID etc.
77 | loginPage.loginActionJava8(username, password);
78 |
79 | String actualMsg = loginPage.getMsgSuccess();
80 | assertTrue(actualMsg.contains(MSG_SUCCESS),
81 | "Actual '" + actualMsg + "' should be same as expected '" + MSG_SUCCESS + "'.");
82 | }
83 |
84 | @Test(dataProvider = "invalidCredentials")
85 | public void testLoginWithInvalidUser(String username, String password) {
86 | WelcomePage welcomePage = new WelcomePage(driver);
87 | welcomePage.verifyWelcomePageTitle();
88 | welcomePage.verifyWelcomePageHeader();
89 | welcomePage.clickOnLink("Form Authentication");
90 |
91 | LoginPage loginPage = new LoginPage(driver);
92 | loginPage.verifyLoginPageHeader();
93 | loginPage.verifyLoginWithInvalidUser(username, password);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestMultipleWindows.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.MultipleWindowsPage;
4 | import auto.pages.WelcomePage;
5 | import auto.utility.Init;
6 | import org.testng.annotations.Test;
7 |
8 | /**
9 | * Created by: Anuj Kumar
10 | * Email: cdac.anuj@gmail.com
11 | * Date: 21-May-18
12 | */
13 | public class TestMultipleWindows extends Init {
14 |
15 | @Test
16 | public void testFrame() throws InterruptedException {
17 | WelcomePage welcomePage = new WelcomePage(driver);
18 | welcomePage.verifyWelcomePageTitle();
19 | welcomePage.verifyWelcomePageHeader();
20 | welcomePage.clickOnLink("Multiple Windows");
21 |
22 | MultipleWindowsPage multipleWindowsPage = new MultipleWindowsPage(driver);
23 | multipleWindowsPage.verifyMultipleWindowsPageHeader();
24 | multipleWindowsPage.clickOnLink();
25 | Thread.sleep(3000);
26 | multipleWindowsPage.getTextOnNewWindow();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/java/auto/testcases/TestWelcomePage.java:
--------------------------------------------------------------------------------
1 | package auto.testcases;
2 |
3 | import auto.pages.WelcomePage;
4 | import auto.utility.Init;
5 | import org.testng.annotations.Test;
6 |
7 | /**
8 | * Created by: Anuj Kumar
9 | * Email: cdac.anuj@gmail.com
10 | * Date: 12-May-18
11 | */
12 | public class TestWelcomePage extends Init {
13 |
14 | @Test
15 | public void testWelcomePage() {
16 | WelcomePage welcomePage = new WelcomePage(driver);
17 | welcomePage.verifyWelcomePageTitle();
18 | welcomePage.verifyWelcomePageHeader();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/test/java/auto/utility/DriverFactory.java:
--------------------------------------------------------------------------------
1 | package auto.utility;
2 |
3 | import org.apache.logging.log4j.Logger;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.chrome.ChromeDriver;
6 | import org.openqa.selenium.firefox.FirefoxDriver;
7 | import org.openqa.selenium.firefox.FirefoxProfile;
8 | import org.openqa.selenium.ie.InternetExplorerDriver;
9 |
10 | import static org.apache.logging.log4j.LogManager.getLogger;
11 |
12 | /**
13 | * Created by: Anuj Kumar
14 | * Email: cdac.anuj@gmail.com
15 | * Date: 19-Apr-19
16 | */
17 | public class DriverFactory {
18 | private static Logger logger = getLogger(DriverFactory.class.getName());
19 |
20 | public WebDriver getDriver() {
21 | String browser = System.getProperty("browser");
22 | if (browser == null)
23 | browser = "chrome";
24 | logger.info("# WebDriver instance for browser: " + browser);
25 |
26 | if (browser.equalsIgnoreCase("chrome"))
27 | return new ChromeDriver();
28 | else if (browser.equalsIgnoreCase("ie"))
29 | return new InternetExplorerDriver();
30 | else {
31 | //FirefoxProfile ffprofile = createFirefoxProfile();
32 | return new FirefoxDriver();
33 | }
34 | }
35 |
36 | private FirefoxProfile createFirefoxProfile() {
37 | logger.info("# Setting up Firefox profile.");
38 | FirefoxProfile firefoxProfile = new FirefoxProfile();
39 | firefoxProfile.setPreference("browser.download.folderList", 2);
40 | firefoxProfile.setPreference("browser.download.dir", "E:\\git_projects\\download");
41 | firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk",
42 | "text/csv,application/pdf,application/vnd.ms-excel,application/octet-stream");
43 | firefoxProfile.setPreference("pdfjs.disabled", true);
44 | return firefoxProfile;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/java/auto/utility/Init.java:
--------------------------------------------------------------------------------
1 | package auto.utility;
2 |
3 | import org.apache.logging.log4j.Logger;
4 | import org.openqa.selenium.WebDriver;
5 | import org.testng.annotations.AfterMethod;
6 | import org.testng.annotations.BeforeMethod;
7 |
8 | import static java.util.concurrent.TimeUnit.SECONDS;
9 | import static org.apache.logging.log4j.LogManager.getLogger;
10 |
11 | /**
12 | * Created by: Anuj Kumar
13 | * Email: cdac.anuj@gmail.com
14 | * Date: 12-May-18
15 | */
16 | public class Init extends DriverFactory {
17 |
18 | private static final String URL = "http://the-internet.herokuapp.com/";
19 |
20 | protected WebDriver driver = null;
21 | private static final long IMPLICIT_TIME = 5;
22 | private static Logger logger = getLogger(Init.class.getName());
23 |
24 | /**
25 | * This function is used for doing web driver setup.
26 | */
27 | @BeforeMethod(alwaysRun = true)
28 | public void setUp() {
29 | logger.info("# Setup.");
30 | driver = getDriver();
31 | driver.get(URL);
32 | driver.manage().timeouts().implicitlyWait(IMPLICIT_TIME, SECONDS);
33 | driver.manage().window().maximize();
34 | }
35 |
36 | /**
37 | * This function is quit the driver instance.
38 | */
39 | @AfterMethod(alwaysRun = true)
40 | public void teardown() {
41 | logger.info("# Teardown.");
42 | if (driver != null)
43 | driver.quit();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/java/auto/utility/Services.java:
--------------------------------------------------------------------------------
1 | package auto.utility;
2 |
3 | import org.apache.logging.log4j.Logger;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.NoSuchElementException;
6 | import org.openqa.selenium.WebDriver;
7 | import org.openqa.selenium.WebElement;
8 | import org.openqa.selenium.support.ui.ExpectedConditions;
9 | import org.openqa.selenium.support.ui.WebDriverWait;
10 |
11 | import java.time.Duration;
12 | import java.util.function.Function;
13 |
14 | import static java.time.Duration.ofSeconds;
15 | import static org.apache.logging.log4j.LogManager.getLogger;
16 | import static org.testng.Assert.assertFalse;
17 | import static org.testng.Assert.assertTrue;
18 |
19 | /**
20 | * Created by: Anuj Kumar
21 | * Email: cdac.anuj@gmail.com
22 | * Date: 14-May-18
23 | * Time: 8:19 PM
24 | */
25 |
26 | public class Services {
27 |
28 | private static Logger logger = getLogger(Services.class.getName());
29 | protected WebDriver driver;
30 |
31 | public Services(WebDriver driver) {
32 | this.driver = driver;
33 | }
34 |
35 | public void waitForElement(String locator) {
36 | new WebDriverWait(driver, ofSeconds(20)).until(ExpectedConditions.presenceOfElementLocated(By.xpath(locator)));
37 | }
38 |
39 | protected void click(String locator) {
40 | driver.findElement(By.xpath(locator)).click();
41 | }
42 |
43 | protected void clickViaCss(String locator) {
44 | driver.findElement(By.cssSelector(locator)).click();
45 | }
46 |
47 | protected void type(String locator, String text) {
48 | driver.findElement(By.xpath(locator)).sendKeys(text);
49 | }
50 |
51 | protected void typeViaCss(String locator, String text) {
52 | driver.findElement(By.cssSelector(locator)).sendKeys(text);
53 | }
54 |
55 | protected void type(String method, String locator, String text) {
56 | if (method.equalsIgnoreCase("xpath"))
57 | driver.findElement(By.xpath(locator)).sendKeys(text);
58 | else if (method.equalsIgnoreCase("css"))
59 | driver.findElement(By.cssSelector(locator)).sendKeys(text);
60 | else
61 | driver.findElement(By.id(locator)).sendKeys(text);
62 | }
63 |
64 | //Java8 way - by same method we can pass all types of locators.
65 | protected void type(Function locate, String locator, String text) {
66 | driver.findElement(locate.apply(locator)).sendKeys(text);
67 | }
68 |
69 | protected void assertElementPresentByXpath(String locator) {
70 | logger.info("# Verifying element.");
71 | assertTrue(isElementPresent(locator), "Element " + locator + " not found.");
72 | }
73 |
74 | protected void assertElementNotPresentByXpath(String locator) {
75 | logger.info("# Verifying element.");
76 | assertFalse(isElementPresent(locator), "Element " + locator + " is found.");
77 | }
78 |
79 | protected boolean isElementPresent(String locator) {
80 | try {
81 | driver.findElement(By.xpath(locator));
82 | return true;
83 | } catch (NoSuchElementException e) {
84 | return false;
85 | }
86 | }
87 |
88 | private boolean isElementVisible(String locator) {
89 | try {
90 | return driver.findElement(By.xpath(locator)).isDisplayed();
91 | } catch (NoSuchElementException e) {
92 | return false;
93 | }
94 | }
95 |
96 | protected void assertElementVisible(String locator, boolean isVisible) {
97 | logger.info("# Verifying element visibility.");
98 | if (isVisible)
99 | assertTrue(isElementVisible(locator), "Element " + locator + " should be visible.");
100 | else
101 | assertFalse(isElementVisible(locator), "Element " + locator + " should not be visible.");
102 | }
103 |
104 | protected void waitForElementVisible(String locator) {
105 | new WebDriverWait(driver, ofSeconds(20)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator)));
106 | }
107 |
108 | protected void waitForElementInVisible(String locator) {
109 | new WebDriverWait(driver, ofSeconds(20)).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(locator)));
110 | }
111 |
112 | protected WebElement getWebElement(String xpath) {
113 | return driver.findElement(By.xpath(xpath));
114 | }
115 |
116 | public String getText(String xpath) {
117 | return driver.findElement(By.xpath(xpath)).getText();
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/src/test/java/log4j.properties:
--------------------------------------------------------------------------------
1 | # Root logger option
2 | log4j.rootLogger=INFO, file, stdout
3 | # configuration to print into file
4 | log4j.appender.file=org.apache.log4j.RollingFileAppender
5 | log4j.appender.file.File=.\\log\\logging.log
6 | log4j.appender.file.MaxFileSize=12MB
7 | log4j.appender.file.MaxBackupIndex=10
8 | log4j.appender.file.layout=org.apache.log4j.PatternLayout
9 | log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
10 | # configuration to print on console
11 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
12 | log4j.appender.stdout.Target=System.out
13 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
14 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
--------------------------------------------------------------------------------