-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
174 additions
and
159 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package anhtester.com.helpers; | ||
|
||
import java.io.File; | ||
|
||
public class Helpers { | ||
|
||
public static String getCurrentDir() { | ||
String current = System.getProperty("user.dir") + "/"; | ||
//File.separator = ký tự phân cách thư mục máy tính | ||
String current = System.getProperty("user.dir") + File.separator; | ||
return current; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package anhtester.com.pages; | ||
|
||
import anhtester.com.helpers.Helpers; | ||
import anhtester.com.utils.WebUI; | ||
import org.openqa.selenium.By; | ||
|
||
import java.awt.*; | ||
import java.awt.datatransfer.StringSelection; | ||
import java.awt.event.KeyEvent; | ||
|
||
public class UploadFileCMSPage { | ||
|
||
//Login | ||
private By buttonCopy = By.xpath("//button[normalize-space()='Copy']"); | ||
private By buttonLogin = By.xpath("//button[normalize-space()='Login']"); | ||
|
||
//Category | ||
private By menuProducts = By.xpath("//span[normalize-space()='Products']"); | ||
private By menuCategory = By.xpath("//span[normalize-space()='Category']"); | ||
private By butttonAddNewCategory = By.xpath("//span[normalize-space()='Add New category']"); | ||
private By chooseFile = By.xpath("//label[normalize-space()='Banner (200x200)']/following-sibling::div//div[normalize-space()='Choose file']"); | ||
private By buttonUploadNew = By.xpath("//a[normalize-space()='Upload New']"); | ||
private By buttonBrowse = By.xpath("//button[normalize-space()='Browse']"); | ||
private By buttonAddFiles = By.xpath("//button[normalize-space()='Add Files']"); | ||
private By messageComplete = By.xpath("//div[@class='uppy-StatusBar-statusPrimary']"); | ||
|
||
private By buttonSelectFile = By.xpath("//a[normalize-space()='Select File']"); | ||
private By inputSearchFile = By.xpath("//input[@placeholder='Search your files']"); | ||
private By itemFile = By.xpath("(//div[@class='card-body']//h6)[1]"); | ||
|
||
public void loginCMS() { | ||
WebUI.openURL("https://demo.activeitzone.com/ecommerce/login"); | ||
WebUI.clickElement(buttonCopy); | ||
WebUI.clickElement(buttonLogin); | ||
} | ||
|
||
public void uploadFileInCategory() { | ||
WebUI.waitForPageLoaded(); | ||
WebUI.clickElement(menuProducts); | ||
WebUI.clickElement(menuCategory); | ||
WebUI.clickElement(butttonAddNewCategory); | ||
WebUI.clickElement(chooseFile); | ||
WebUI.clickElement(buttonUploadNew); | ||
WebUI.clickElement(buttonBrowse); //Mở form select file từ local PC | ||
|
||
//Dán đoạn code dùng Robot class để hành động với bàn phím | ||
// Khởi tạo Robot class | ||
Robot rb = null; | ||
try { | ||
rb = new Robot(); | ||
} catch (AWTException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
String filePath = Helpers.getCurrentDir() + "datatest\\Selenium4_Upload.png"; | ||
|
||
// Copy File path vào Clipboard | ||
StringSelection str = new StringSelection(filePath); | ||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(str, null); | ||
|
||
WebUI.sleep(1); | ||
|
||
// Nhấn Control+V để dán | ||
rb.keyPress(KeyEvent.VK_CONTROL); | ||
rb.keyPress(KeyEvent.VK_V); | ||
|
||
// Xác nhận Control V trên | ||
rb.keyRelease(KeyEvent.VK_CONTROL); | ||
rb.keyRelease(KeyEvent.VK_V); | ||
|
||
WebUI.sleep(2); | ||
|
||
// Nhấn Enter | ||
rb.keyPress(KeyEvent.VK_ENTER); | ||
rb.keyRelease(KeyEvent.VK_ENTER); | ||
|
||
WebUI.sleep(3); | ||
WebUI.clickElement(buttonSelectFile); | ||
WebUI.setText(inputSearchFile, "Selenium4_Upload"); | ||
WebUI.sleep(1); | ||
WebUI.clickElement(itemFile); | ||
WebUI.sleep(1); | ||
WebUI.clickElement(buttonAddFiles); | ||
WebUI.sleep(2); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package anhtester.com.testcases; | ||
|
||
import anhtester.com.common.BaseTest; | ||
import anhtester.com.helpers.Helpers; | ||
import anhtester.com.pages.UploadFileCMSPage; | ||
import anhtester.com.utils.WebUI; | ||
import org.openqa.selenium.By; | ||
import org.testng.annotations.Test; | ||
|
||
public class UploadFileCMS extends BaseTest { | ||
|
||
@Test | ||
public void testUploadFileWithSendKeys() throws InterruptedException { | ||
WebUI.openURL("https://cgi-lib.berkeley.edu/ex/fup.html"); | ||
WebUI.waitForPageLoaded(); | ||
By inputFileUpload = By.xpath("//input[@name='upfile']"); | ||
|
||
//DriverManager.getDriver().findElement(inputFileUpload).sendKeys(Helpers.getCurrentDir() + "datatest/Selenium4_Upload.png"); | ||
WebUI.setText(inputFileUpload, Helpers.getCurrentDir() + "datatest/Selenium4_Upload.png"); | ||
Thread.sleep(3000); | ||
} | ||
|
||
@Test | ||
public void testUploadFileInCategoryCMS() { | ||
UploadFileCMSPage uploadFileCMSPage = new UploadFileCMSPage(); | ||
uploadFileCMSPage.loginCMS(); | ||
uploadFileCMSPage.uploadFileInCategory(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters