bug4210 Added and integrated new page object for DateAndTimeInputs

This commit is contained in:
Benjamin Barth
2017-11-21 17:56:26 +01:00
parent e82fe2aa7a
commit f7c8069534
5 changed files with 64 additions and 82 deletions
@@ -9,8 +9,8 @@ import org.openqa.selenium.support.ui.Select;
import com.sap.sailing.selenium.core.BySeleniumId;
import com.sap.sailing.selenium.core.FindBy;
import com.sap.sailing.selenium.pages.common.DataEntryDialogPO;
import com.sap.sailing.selenium.pages.gwt.BetterDateTimeBoxPO;
import com.sap.sailing.selenium.pages.gwt.CheckBoxPO;
import com.sap.sailing.selenium.pages.gwt.DateAndTimeInputPO;
import com.sap.sailing.selenium.pages.gwt.TextAreaPO;
import com.sap.sailing.selenium.pages.gwt.TextBoxPO;
@@ -50,8 +50,8 @@ public class EventCreateDialogPO extends DataEntryDialogPO {
TextBoxPO.create(driver, nameTextBox).appendText(name);
TextAreaPO.create(driver, descriptionTextArea).appendText(description);
TextBoxPO.create(driver, venueTextBox).appendText(venue);
BetterDateTimeBoxPO.create(driver, startDateTimeBox).setDate(start, false);
BetterDateTimeBoxPO.create(driver, endDateTimeBox).setDate(end, false);
DateAndTimeInputPO.create(driver, startDateTimeBox).setValue(start, false);
DateAndTimeInputPO.create(driver, endDateTimeBox).setValue(end, false);
CheckBoxPO.create(driver, isPublicCheckBox).setSelected(isPublic);
}
@@ -8,7 +8,7 @@ import org.openqa.selenium.WebElement;
import com.sap.sailing.selenium.core.BySeleniumId;
import com.sap.sailing.selenium.core.FindBy;
import com.sap.sailing.selenium.pages.common.DataEntryDialogPO;
import com.sap.sailing.selenium.pages.gwt.BetterDateTimeBoxPO;
import com.sap.sailing.selenium.pages.gwt.DateAndTimeInputPO;
public class SetStartTimeDialogPO extends DataEntryDialogPO {
@@ -28,7 +28,7 @@ public class SetStartTimeDialogPO extends DataEntryDialogPO {
}
public void setStartTimeValue(Date startTime) {
BetterDateTimeBoxPO.create(driver, startTimeTimeBox, true).setDate(startTime,true);
DateAndTimeInputPO.create(driver, startTimeTimeBox).setValue(startTime, true);
}
public void pressSetStartTime() {
@@ -8,7 +8,7 @@ import org.openqa.selenium.WebElement;
import com.sap.sailing.selenium.core.BySeleniumId;
import com.sap.sailing.selenium.core.FindBy;
import com.sap.sailing.selenium.pages.common.DataEntryDialogPO;
import com.sap.sailing.selenium.pages.gwt.BetterDateTimeBoxPO;
import com.sap.sailing.selenium.pages.gwt.DateAndTimeInputPO;
import com.sap.sailing.selenium.pages.gwt.ListBoxPO;
import com.sap.sailing.selenium.pages.gwt.TextBoxPO;
@@ -56,8 +56,8 @@ public class RegattaCreateDialogPO extends DataEntryDialogPO {
public void setValues(String name, String boatClass, Date startDate, Date endDate) {
this.setRegattaName(name);
this.setBoatClass(boatClass);
BetterDateTimeBoxPO.create(driver, startDateTimeBox).setDate(startDate, false);
BetterDateTimeBoxPO.create(driver, endDateTimeBox).setDate(endDate, false);
DateAndTimeInputPO.create(driver, startDateTimeBox).setValue(startDate, false);
DateAndTimeInputPO.create(driver, endDateTimeBox).setValue(endDate, false);
}
// TODO: Scoring System, Event and Course Area
@@ -1,74 +0,0 @@
package com.sap.sailing.selenium.pages.gwt;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import com.sap.sailing.selenium.core.BySeleniumId;
import com.sap.sailing.selenium.core.FindBy;
import com.sap.sailing.selenium.pages.PageArea;
import com.sap.sailing.selenium.pages.PageObject;
/**
* {@link PageObject} implementation for better date time boxes.
*/
public class BetterDateTimeBoxPO extends PageArea {
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
private static final DateFormat timeFormat = new SimpleDateFormat("hh:mm");
private static final DateFormat timeFormatSeconds = new SimpleDateFormat("hh:mm:ss");
@FindBy(how = BySeleniumId.class, using = "datebox")
private WebElement datebox;
@FindBy(how = BySeleniumId.class, using = "timebox")
private WebElement timebox;
/**
* @see TextBoxPO#TextBoxPO(WebDriver, WebElement)
*/
protected BetterDateTimeBoxPO(WebDriver driver, WebElement element, DateFormat timeFormat) {
super(driver, element);
}
/**
* Sets the underlying {@link WebElement}s text by formatting the given {@link Date} using the internal date format
* (<code>dd/MM/yyyy hh:mm</code> or <code>dd/MM/yyyy hh:mm:ss</code>).
*
* @param date
* the {@link Date} object to set
* @param withSeconds true, if the used TimeBox requires also seconds and not only hours and minutes
*
* @see DateFormat#format(Date)
* @see #setText(String)
*/
public void setDate(Date date, boolean withSeconds) {
String datein = dateFormat.format(date);
datebox.clear();
datebox.sendKeys(datein);
// ensure popups are closed!
datebox.sendKeys("\t");
final String timein;
if(withSeconds){
timein = timeFormatSeconds.format(date);
}else{
timein = timeFormat.format(date);
}
timebox.clear();
timebox.sendKeys(timein);
// ensure popups are closed!
timebox.sendKeys("\t");
}
public static BetterDateTimeBoxPO create(WebDriver driver, WebElement startTimeTimeBox, boolean b) {
return new BetterDateTimeBoxPO(driver, startTimeTimeBox, null);
}
public static BetterDateTimeBoxPO create(WebDriver driver, WebElement startDateTimeBox) {
return create(driver, startDateTimeBox, true);
}
}
@@ -0,0 +1,56 @@
package com.sap.sailing.selenium.pages.gwt;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import com.sap.sailing.selenium.core.BySeleniumId;
import com.sap.sailing.selenium.core.FindBy;
import com.sap.sailing.selenium.pages.PageArea;
public class DateAndTimeInputPO extends PageArea {
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("MMM d, y");
private static final DateFormat TIME_FORMAT_MINUTES = new SimpleDateFormat("h:mm a");
private static final DateFormat TIME_FORMAT_SECONDS = new SimpleDateFormat("h:mm:ss a");
@FindBy(how = BySeleniumId.class, using = "dateInput")
private WebElement dateInput;
@FindBy(how = BySeleniumId.class, using = "timeInput")
private WebElement timeInput;
private DateAndTimeInputPO(WebDriver driver, WebElement element) {
super(driver, element);
}
/**
* Sets the provided {@link Date date value} to the underlying {@link WebElement}.
*
* @param date
* the {@link Date date value} to set to the input field
* @param enterSeconds
* <code>true</code> to enter seconds fragment as well, <code>false</code> otherwise
*
* @see DateFormat#format(Date)
* @see WebElement#sendKeys(CharSequence...)
*/
public void setValue(Date date, boolean enterSeconds) {
this.setValue(dateInput, date, DATE_FORMAT);
this.setValue(timeInput, date, enterSeconds ? TIME_FORMAT_SECONDS : TIME_FORMAT_MINUTES);
}
private void setValue(WebElement input, Date date, DateFormat format) {
final String value = format.format(date);
input.clear();
input.sendKeys(value);
input.sendKeys("\t"); // ensure popup closing!
}
public static DateAndTimeInputPO create(WebDriver driver, WebElement element) {
return new DateAndTimeInputPO(driver, element);
}
}