├── src
└── test
│ ├── resources
│ └── chromedriver
│ │ └── chromedriver.exe
│ └── java
│ └── com
│ └── qualitystream
│ └── tutorial
│ ├── GoogleSearchTest.java
│ ├── DataDrivenTesting_SWD_Test.java
│ ├── ReadExcelFile.java
│ ├── WriteExcelFile.java
│ └── MercuryTours_AutomatedTest.java
├── target
└── test-classes
│ └── com
│ └── qualitystream
│ └── tutorial
│ ├── ReadExcelFile.class
│ ├── WriteExcelFile.class
│ ├── DataDrivenTesting_SWD_Test.class
│ └── MercuryTours_AutomatedTest.class
├── .gitignore
└── pom.xml
/src/test/resources/chromedriver/chromedriver.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qualitystream/selenium-webdriver-tutorial/HEAD/src/test/resources/chromedriver/chromedriver.exe
--------------------------------------------------------------------------------
/src/test/java/com/qualitystream/tutorial/GoogleSearchTest.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qualitystream/selenium-webdriver-tutorial/HEAD/src/test/java/com/qualitystream/tutorial/GoogleSearchTest.java
--------------------------------------------------------------------------------
/target/test-classes/com/qualitystream/tutorial/ReadExcelFile.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qualitystream/selenium-webdriver-tutorial/HEAD/target/test-classes/com/qualitystream/tutorial/ReadExcelFile.class
--------------------------------------------------------------------------------
/target/test-classes/com/qualitystream/tutorial/WriteExcelFile.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qualitystream/selenium-webdriver-tutorial/HEAD/target/test-classes/com/qualitystream/tutorial/WriteExcelFile.class
--------------------------------------------------------------------------------
/src/test/java/com/qualitystream/tutorial/DataDrivenTesting_SWD_Test.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qualitystream/selenium-webdriver-tutorial/HEAD/src/test/java/com/qualitystream/tutorial/DataDrivenTesting_SWD_Test.java
--------------------------------------------------------------------------------
/target/test-classes/com/qualitystream/tutorial/DataDrivenTesting_SWD_Test.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qualitystream/selenium-webdriver-tutorial/HEAD/target/test-classes/com/qualitystream/tutorial/DataDrivenTesting_SWD_Test.class
--------------------------------------------------------------------------------
/target/test-classes/com/qualitystream/tutorial/MercuryTours_AutomatedTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qualitystream/selenium-webdriver-tutorial/HEAD/target/test-classes/com/qualitystream/tutorial/MercuryTours_AutomatedTest.class
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #
2 | # Project specific excludes
3 | #
4 |
5 | tomcat
6 |
7 | #
8 | # Default excludes
9 | #
10 |
11 | # Binaries
12 | *.7z
13 | *.dmg
14 | *.gz
15 | *.iso
16 | *.jar
17 | *.rar
18 | *.tar
19 | *.zip
20 | *.war
21 | *.ear
22 | *.sar
23 | *.class
24 |
25 | # Maven
26 | target/
27 |
28 | # IntelliJ project files
29 | *.iml
30 | *.iws
31 | *.ipr
32 | .idea/
33 |
34 | # eclipse project file
35 | .settings/
36 | .classpath
37 | .project
38 |
39 | # NetBeans specific
40 | nbproject/private/
41 | build/
42 | nbbuild/
43 | dist/
44 | nbdist/
45 | nbactions.xml
46 | nb-configuration.xml
47 |
48 |
49 | # OS
50 | .DS_Store
51 |
52 | # Misc
53 | *.swp
54 | release.properties
55 | pom.xml.releaseBackup
56 | pom.xml.tag
57 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | com.qualitystream.tutorial
6 | QualityStreamTutorial
7 | 0.0.1-SNAPSHOT
8 |
9 |
10 | org.seleniumhq.selenium
11 | selenium-java
12 | 3.141.59
13 |
14 |
15 | junit
16 | junit
17 | 4.12
18 | test
19 |
20 |
21 |
22 | org.apache.poi
23 | poi
24 | 4.0.1
25 |
26 |
27 |
28 | org.apache.poi
29 | poi-ooxml
30 | 4.0.1
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/test/java/com/qualitystream/tutorial/ReadExcelFile.java:
--------------------------------------------------------------------------------
1 | package com.qualitystream.tutorial;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileNotFoundException;
6 | import java.io.IOException;
7 |
8 | import org.apache.poi.xssf.usermodel.XSSFCell;
9 | import org.apache.poi.xssf.usermodel.XSSFRow;
10 | import org.apache.poi.xssf.usermodel.XSSFSheet;
11 | import org.apache.poi.xssf.usermodel.XSSFWorkbook;
12 |
13 | public class ReadExcelFile {
14 |
15 | public ReadExcelFile() {
16 | // TODO Auto-generated constructor stub
17 | }
18 |
19 | public void readExcel( String filepath, String sheetName) throws IOException {
20 |
21 | File file = new File(filepath);
22 |
23 | FileInputStream inputStream = new FileInputStream(file);
24 |
25 | XSSFWorkbook newWorkbook = new XSSFWorkbook(inputStream);
26 |
27 | XSSFSheet newSheet = newWorkbook.getSheet(sheetName);
28 |
29 | int rowCount = newSheet.getLastRowNum() - newSheet.getFirstRowNum();
30 |
31 | for (int i = 0; i <= rowCount; i++) {
32 | XSSFRow row = newSheet.getRow(i);
33 |
34 | for (int j = 0; j < row.getLastCellNum(); j++) {
35 | System.out.println(row.getCell(j).getStringCellValue() + "||");
36 | }
37 | }
38 | }
39 |
40 |
41 | public String getCellValue(String filepath, String sheetName, int rowNumber, int cellNumber) throws IOException {
42 |
43 | File file = new File(filepath);
44 |
45 | FileInputStream inputStream = new FileInputStream(file);
46 |
47 | XSSFWorkbook newWorkbook = new XSSFWorkbook(inputStream);
48 |
49 | XSSFSheet newSheet = newWorkbook.getSheet(sheetName);
50 |
51 | XSSFRow row = newSheet.getRow(rowNumber);
52 |
53 | XSSFCell cell = row.getCell(cellNumber);
54 |
55 | return cell.getStringCellValue();
56 |
57 |
58 |
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/test/java/com/qualitystream/tutorial/WriteExcelFile.java:
--------------------------------------------------------------------------------
1 | package com.qualitystream.tutorial;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileOutputStream;
6 | import java.io.IOException;
7 |
8 | import org.apache.poi.xssf.usermodel.XSSFCell;
9 | import org.apache.poi.xssf.usermodel.XSSFRow;
10 | import org.apache.poi.xssf.usermodel.XSSFSheet;
11 | import org.apache.poi.xssf.usermodel.XSSFWorkbook;
12 |
13 | public class WriteExcelFile {
14 |
15 | public WriteExcelFile() {
16 | // TODO Auto-generated constructor stub
17 | }
18 |
19 | public void writeExcel(String filepath, String sheetName, String[] dataToWrite) throws IOException {
20 |
21 | File file = new File(filepath);
22 |
23 | FileInputStream inputStream = new FileInputStream(file);
24 |
25 | XSSFWorkbook newWorkbook = new XSSFWorkbook(inputStream);
26 |
27 | XSSFSheet newSheet = newWorkbook.getSheet(sheetName);
28 |
29 | int rowCount = newSheet.getLastRowNum()-newSheet.getFirstRowNum();
30 |
31 | XSSFRow row = newSheet.getRow(0);
32 |
33 | XSSFRow newRow = newSheet.createRow(rowCount+1);
34 |
35 | for (int i = 0; i < row.getLastCellNum(); i++) {
36 | XSSFCell newCell = newRow.createCell(i);
37 | newCell.setCellValue(dataToWrite[i]);
38 | }
39 |
40 | inputStream.close();
41 |
42 | FileOutputStream outputStream = new FileOutputStream(file);
43 |
44 | newWorkbook.write(outputStream);
45 |
46 | outputStream.close();
47 | }
48 |
49 | public void writeCellValue(String filepath, String sheetName, int rowNumber, int cellNumber, String resultText) throws IOException {
50 |
51 | File file = new File(filepath);
52 |
53 | FileInputStream inputStream = new FileInputStream(file);
54 |
55 | XSSFWorkbook newWorkbook = new XSSFWorkbook(inputStream);
56 |
57 | XSSFSheet newSheet = newWorkbook.getSheet(sheetName);
58 |
59 | XSSFRow row = newSheet.getRow(rowNumber);
60 |
61 | XSSFCell firstCell = row.getCell(cellNumber-1);
62 |
63 | System.out.println("first cell value is:" + firstCell.getStringCellValue());
64 |
65 | XSSFCell nextCell = row.createCell(cellNumber);
66 | nextCell.setCellValue(resultText);
67 |
68 | System.out.println("nextcell value:" + nextCell.getStringCellValue());
69 |
70 | inputStream.close();
71 |
72 | FileOutputStream outputStream = new FileOutputStream(file);
73 |
74 | newWorkbook.write(outputStream);
75 |
76 | outputStream.close();
77 |
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/test/java/com/qualitystream/tutorial/MercuryTours_AutomatedTest.java:
--------------------------------------------------------------------------------
1 | package com.qualitystream.tutorial;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import java.util.List;
6 |
7 | import org.junit.After;
8 | import org.junit.Before;
9 | import org.junit.Test;
10 | import org.openqa.selenium.By;
11 | import org.openqa.selenium.WebDriver;
12 | import org.openqa.selenium.WebElement;
13 | import org.openqa.selenium.chrome.ChromeDriver;
14 |
15 | public class MercuryTours_AutomatedTest {
16 |
17 | private WebDriver driver;
18 | By registerLinkLocator = By.linkText("REGISTER");
19 | By registerPageLocator = By.xpath("//img[@src='/images/masts/mast_register.gif']");
20 |
21 | By usernameLocator = By.id("email");
22 | By passwordLocator = By.name("password");
23 | By confirmPassworLocator = By.cssSelector("input[name='confirmPassword']");
24 |
25 | By registerBtnLocator = By.name("register");
26 |
27 | By userLocator = By.name("userName");
28 | By passLocator = By.name("password");
29 | By signInBtnLocator = By.name("login");
30 |
31 | By homePageLocator = By.xpath("//img[@src='/images/masts/mast_flightfinder.gif']");
32 |
33 | @Before
34 | public void setUp() throws Exception {
35 | System.setProperty("webdriver.chrome.driver", "./src/test/resources/chromedriver/chromedriver.exe");
36 | driver = new ChromeDriver();
37 | driver.manage().window().maximize();
38 | driver.get("http://newtours.demoaut.com/mercurywelcome.php");
39 | }
40 |
41 | @After
42 | public void tearDown() throws Exception {
43 | //driver.quit();
44 | }
45 |
46 | @Test
47 | public void registerUser() throws InterruptedException {
48 | driver.findElement(registerLinkLocator).click();
49 | Thread.sleep(2000);
50 | if(driver.findElement(registerPageLocator).isDisplayed()) {
51 | driver.findElement(usernameLocator).sendKeys("qualityadmin");
52 | driver.findElement(passwordLocator).sendKeys("pass1");
53 | driver.findElement(confirmPassworLocator).sendKeys("pass1");
54 |
55 | driver.findElement(registerBtnLocator).click();
56 | }
57 | else {
58 | System.out.print("Register pages was not found");
59 | }
60 |
61 | List fonts = driver.findElements(By.tagName("font"));
62 |
63 | assertEquals("Note: Your user name is qualityadmin.",fonts.get(5).getText());
64 |
65 | }
66 |
67 | @Test
68 | public void signIn() throws InterruptedException {
69 | if(driver.findElement(userLocator).isDisplayed()){
70 | driver.findElement(userLocator).sendKeys("qualityadmin");
71 | driver.findElement(passLocator).sendKeys("pass1");
72 | driver.findElement(signInBtnLocator).click();
73 | Thread.sleep(2000);
74 | assertTrue(driver.findElement(homePageLocator).isDisplayed());
75 | }
76 | else
77 | System.out.println("username textbox was not present");
78 |
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------