Skip to content

Commit

Permalink
#1022 - Apply Automation test for Yas project
Browse files Browse the repository at this point in the history
- add automation-ui/backoffice
  • Loading branch information
Duy Le Van committed Sep 17, 2024
1 parent 2a0e5f2 commit 444822c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ public enum InputType {
this.serviceName = serviceName;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.yas.automation.ui.pages;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class BasePage {

private final WebDriver webDriver;

public BasePage(WebDriver webDriver) {
this.webDriver = webDriver;
}

public void scrollDown() {
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) webDriver;
javascriptExecutor.executeScript("window.scrollBy(0,document.body.scrollHeight)");
}

public void scrollTo(WebElement webElement) {
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) webDriver;
javascriptExecutor.executeScript("arguments[0].scrollIntoView(true);", webElement);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
import com.yas.automation.ui.hook.WebDriverFactory;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.How;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.yas.automation.ui.util.WebElementUtil.getWebElementBy;

@Component
public class HomePage {

@Autowired
private final WebDriverFactory webDriverFactory;

@Autowired
public HomePage(WebDriverFactory webDriverFactory) {
this.webDriverFactory = webDriverFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,15 @@
import com.yas.automation.ui.hook.WebDriverFactory;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.How;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.yas.automation.ui.util.WebElementUtil.getWebElementBy;

@Component
public class LoginPage {

@Autowired
private final WebDriverFactory webDriverFactory;

public void login(String username, String password) {
WebElement usernameEle = getWebElementBy(webDriverFactory.getChromeDriver(), How.ID, "username");
usernameEle.sendKeys(username);

WebElement passwordEle = getWebElementBy(webDriverFactory.getChromeDriver(), How.ID, "password");
passwordEle.sendKeys(password);
}

@Autowired
public LoginPage(WebDriverFactory webDriverFactory) {
this.webDriverFactory = webDriverFactory;
}
Expand All @@ -31,4 +20,12 @@ public void clickLogin() {
WebElement loginBtn = getWebElementBy(webDriverFactory.getChromeDriver(), How.CLASS_NAME, "submit");
loginBtn.click();
}

public void login(String username, String password) {
WebElement usernameEle = getWebElementBy(webDriverFactory.getChromeDriver(), How.ID, "username");
usernameEle.sendKeys(username);

WebElement passwordEle = getWebElementBy(webDriverFactory.getChromeDriver(), How.ID, "password");
passwordEle.sendKeys(password);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.yas.automation.ui.form.ProductForm;
import com.yas.automation.ui.hook.WebDriverFactory;
import com.yas.automation.ui.service.InputDelegateService;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.How;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -15,13 +16,13 @@
import static com.yas.automation.ui.util.WebElementUtil.getWebElementBy;

@Component
public class ProductPage {
public class ProductPage extends BasePage {

private final WebDriverFactory webDriverFactory;
private final InputDelegateService inputDelegateService;

@Autowired
public ProductPage(WebDriverFactory webDriverFactory, InputDelegateService inputDelegateService) {
super(webDriverFactory.getChromeDriver());
this.webDriverFactory = webDriverFactory;
this.inputDelegateService = inputDelegateService;
}
Expand All @@ -42,11 +43,7 @@ public void fillProductData() {
inputDelegateService.setInputValue(InputType.TEXT, productForm.getSku(), UUID.randomUUID().toString());
inputDelegateService.setInputValue(InputType.DROPDOWN, productForm.getBrand(), "Apple");
inputDelegateService.setInputValue(InputType.DROPDOWN, productForm.getTax(), "Value Added Tax (VAT)");
try {
Thread.sleep(3000L);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
this.scrollTo(productForm.getCreateBtn());
productForm.submitForm();
}

Expand Down

0 comments on commit 444822c

Please sign in to comment.