58 lines
1.6 KiB
Java
58 lines
1.6 KiB
Java
package pages.webelements;
|
|
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
|
|
import org.openqa.selenium.JavascriptExecutor;
|
|
import org.openqa.selenium.WebDriver;
|
|
import org.openqa.selenium.WebElement;
|
|
import org.openqa.selenium.support.FindBy;
|
|
import org.openqa.selenium.support.PageFactory;
|
|
|
|
import pages.BasePage;
|
|
|
|
public class DatePickersPage extends BasePage
|
|
{
|
|
@FindBy(xpath = "//button[contains(text(),'Date Pickers')]")
|
|
private WebElement accordionItem;
|
|
|
|
@FindBy(id = "html-datepicker")
|
|
private WebElement htmlDatePicker;
|
|
|
|
public DatePickersPage(WebDriver driver)
|
|
{
|
|
super(driver);
|
|
PageFactory.initElements(this.driver, this);
|
|
}
|
|
|
|
public void clickOnAccordionItem()
|
|
{
|
|
accordionItem.click();
|
|
}
|
|
|
|
public void setDateOnHTMLDatePicker(String inputDateAsString)
|
|
{
|
|
// JavaScript uses dates in format "yyyy-MM-dd"
|
|
// We set the value of the HTML Date Picker input using JavascriptExecutor
|
|
// So we need to convert the input date from format "dd-MM-yyyy" into "yyyy-MM-dd"
|
|
String inputDateAsStringInJavaScriptFormat = "";
|
|
|
|
try
|
|
{
|
|
SimpleDateFormat inputDateFormat = new SimpleDateFormat("dd-MM-yyyy");
|
|
Date inputDate = inputDateFormat.parse(inputDateAsString);
|
|
|
|
SimpleDateFormat outputDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
inputDateAsStringInJavaScriptFormat = outputDateFormat.format(inputDate);
|
|
}
|
|
catch (ParseException e)
|
|
{
|
|
e.printStackTrace();
|
|
}
|
|
|
|
JavascriptExecutor js = (JavascriptExecutor) driver;
|
|
js.executeScript("arguments[0].value='" + inputDateAsStringInJavaScriptFormat + "';", htmlDatePicker);
|
|
}
|
|
}
|