Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
java-version: 1.8
- name: Run Selenium Test
run: mvn test -Dtestplan=todoTestPlan.xml
run: mvn test
- name: Publish Test Report
uses: scacap/action-surefire-report@v1
with:
Expand Down
50 changes: 39 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ Repo này chứa những bài tập và phần cấu hình sẵn cơ bản để
2. [Check to a box](https://cuhavp.github.io/checkboxes/)
* Open browser
* Navigate to https://the-internet.herokuapp.com/checkboxes
* Check on "checkbox1"
* Verify "checkbox1" is checked
* Check on "checkbox2"
* Verify "checkbox2" is checked
* Check on **checkbox1**
* Verify **checkbox1** is `checked`
* Check on **checkbox2**
* Verify **checkbox2** is `checked`
---
3. [Select option](https://cuhavp.github.io/drop-down/)
* Open browser
Expand Down Expand Up @@ -104,12 +104,16 @@ Repo này chứa những bài tập và phần cấu hình sẵn cơ bản để
* Open browser
* Navigate to https://the-internet.herokuapp.com/nested_frames
* Verify Text present:
```
LEFT
RIGHT
MIDDLE
BOTTOM
```

```
LEFT

RIGHT

MIDDLE

BOTTOM
```
---
7. JavaScript Alerts
* Open browser
Expand Down Expand Up @@ -141,4 +145,28 @@ Repo này chứa những bài tập và phần cấu hình sẵn cơ bản để
* Navigate to https://todomvc.com/examples/vanillajs/
* Enter a new todo name
* Verify a todo added
---
---
12. Ecommerce sample test
* Open Browser
* Navigator to [Ebay item's page](https://www.ebay.com/p/5034224981?iid=153638834105&var=453955077516)
* Validate the price
* Click **Buy It Now** button
* On the SigIn page, click **Continue as a guest**
* Fill Shipping info
* Validate **Subtotal** price
* Click **Continue** button
* Validate **Total** price
----
13. Basic authentication
----
14. Broken images
----
16. Drag & drop
----
18. Horizontal slider
----
19. Dynamic content
----
20. Dynamic loading
----
21. Input (from keyboard)
13 changes: 13 additions & 0 deletions form-authentication-testplan.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<suite name="Form Authentication">
<test name="credentials">
<parameter name="browser" value="chrome"/>
<groups>
<run>
<exclude name="smoke"/>
</run>
</groups>
<classes>
<class name="testcases.FormAuthenticationTest"/>
</classes>
</test>
</suite>
15 changes: 15 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand All @@ -37,6 +42,16 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>form-authentication-testplan.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
5 changes: 5 additions & 0 deletions src/test/java/bases/BasePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package bases;

public abstract class BasePage {
public abstract void open() ;
}
43 changes: 43 additions & 0 deletions src/test/java/bases/BaseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package bases;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;

import java.io.File;
import java.io.IOException;

public class BaseTest {

@Parameters({"browser"})
@BeforeClass(alwaysRun = true)
public void setUp(String name) {
Browser.launch(name);
}

@AfterMethod(alwaysRun = true)
public void captureScreen(ITestResult testResult) throws IOException {
if(!testResult.isSuccess()){
File file = ((TakesScreenshot) Browser.getDriver()).getScreenshotAs(OutputType.FILE);
File DestFile=new File("./target/screenshot/"
+testResult.getMethod().getMethodName()
+ "-"
+System.currentTimeMillis()+".png");

FileUtils.copyFile(file, DestFile);
}
}

@AfterClass(alwaysRun = true)
public void tearDown(){
Browser.getDriver().quit();
}
}
91 changes: 91 additions & 0 deletions src/test/java/bases/Browser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package bases;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.List;

public class Browser {
private static WebDriver driver;
public static Actions mouse;
public static WebDriverWait wait;

public static void launch(String name) {
if (name.equalsIgnoreCase("chrome")) {
WebDriverManager.chromedriver().setup();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setHeadless(true);
driver = new ChromeDriver(chromeOptions);
} else if (name.equalsIgnoreCase("firefox")) {
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
} else if (name.equalsIgnoreCase("ie")) {
WebDriverManager.iedriver().setup();
driver = new InternetExplorerDriver();
}
mouse = new Actions(getDriver());
wait = new WebDriverWait(getDriver(), 30);
}

public static WebDriver getDriver() {
return driver;
}

public static void visit(String url) {
driver.get(url);
}

public static void fill(By locator, String withText) {
driver.findElement(locator).clear();
driver.findElement(locator).sendKeys(withText);
}

public static WebElement find(By locator) {
return driver.findElement(locator);
}

public static void click(By locator) {
driver.findElement(locator).click();
}

public static String getText(By locator) {
return driver.findElement(locator).getText();
}

public static boolean isDisplayed(By locator) {
return driver.findElement(locator).isDisplayed();
}

public static void hover(By locator) {
mouse.moveToElement(find(locator)).perform();
}

public static List<WebElement> all(By locator) {
return driver.findElements(locator);
}

public static int count(By locator) {
return all(locator).size();
}

void check(By checkbox) {
if (!find(checkbox).isSelected()) {
click(checkbox);
}
}

void uncheck(By checkbox) {
if (find(checkbox).isSelected()) {
click(checkbox);
}
}

}
55 changes: 55 additions & 0 deletions src/test/java/helper/DateUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package helper;

import org.openqa.selenium.WebElement;

import java.time.LocalDate;
import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;

public class DateUtils {
//Get The Current Day
public static String getCurrentDay() {
//Create a Calendar Object
Calendar calendar = Calendar.getInstance(TimeZone.getDefault());

//Get Current Day as a number
int todayInt = calendar.get(Calendar.DAY_OF_MONTH);
System.out.println("Today Int: " + todayInt + "\n");

//Integer to String Conversion
String todayStr = Integer.toString(todayInt);
System.out.println("Today Str: " + todayStr + "\n");

return todayStr;
}

//Get The Current Day plus days. You can change this method based on your needs.
public static String getCurrentDayPlus(int days) {
LocalDate currentDate = LocalDate.now();

int dayOfWeekPlus = currentDate.getDayOfWeek().plus(days).getValue();
return Integer.toString(dayOfWeekPlus);
}

//Click to given day
public static void clickGivenDay(List<WebElement> elementList, String day) {
//DatePicker is a table. Thus we can navigate to each cell
//and if a cell matches with the current date then we will click it.
/**Functional JAVA version of this method.*/
elementList.stream()
.filter(element -> element.getText().contains(day))
.findFirst()
.ifPresent(WebElement::click);

/**Non-functional JAVA version of this method.*/
//for (
// WebElement cell : elementList) {
// String cellText = cell.getText();
// if (cellText.contains(day)) {
// cell.click();
// break;
// }
//}
}
}
16 changes: 16 additions & 0 deletions src/test/java/model/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package model;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

@Getter @AllArgsConstructor
@Data
public class Person {
private final String lastName;
private final String firstName;
private final String email;
private final String website;
private final float due;
}
17 changes: 17 additions & 0 deletions src/test/java/openBrowser/ChromeHeadlessTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package openBrowser;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class ChromeHeadlessTest {
public static void main(String[] args) {
WebDriverManager.chromedriver().setup();

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setHeadless(true);

WebDriver driver = new ChromeDriver(chromeOptions);
}
}
19 changes: 19 additions & 0 deletions src/test/java/openBrowser/ChromeMobileViewPortTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package openBrowser;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.util.HashMap;
import java.util.Map;

public class ChromeMobileViewPortTest {
public static void main(String[] args) {
WebDriverManager.chromedriver().setup();
Map<String, Object> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", "iPhone X");
ChromeOptions opts = new ChromeOptions();
opts.setExperimentalOption("mobileEmulation", mobileEmulation);
new ChromeDriver(opts);
}
}
Loading