I tried to click on from-date textbox to select the From-Date but I am not able to do so for "opensource-demo.orangehrmlive.com". Dashboard > Apply leave
driver.findElement(By.id("applyleave_txtFromDate").click();
Select secMonth = new Select(driver.findElement(By.xpath("//div[#class='ui-datepicktitle']/select[1]")));
secMonth.selectByVisibleText("Jan"); Select secYear = new Select(driver.findElement(By.xpath("//div[#class='ui-datepicker-title']/select[2]")));
secYear.selectByVisibleText("2021");
java.util.List<WebElement> dates = driver.findElements(By.xpath("//td[#data-handler='selectDay']"));
int count = dates.size();
for(int i=0;i<count;i++)
{
String ReqD = dates.get(i).getText();
if(ReqD.equalsIgnoreCase("2"))
{
dates.get(i).click();
break;
}
it does not work?
String someDate = "2020-01-02";
WebElement fromDate = driver.findElement(By.id("applyleave_txtFromDate");
fromDate.click();
fromDate.sendKeys(someDate);
fromDate.sendKeys(Keys.TAB);
I would recommend for you to use AppConstants to add all final values to it. Then it will be easier to pass it using String
(example: public static final String DATE_VALUE = "12/22/2020";)
I use this approach for automation testing, because of you are going to use this script for long run as a regression testing for your framework, it will not pass when the calendar month will change. You will have to update your script. But if you will pass it within String value, your script will not need modifications.
Related
My project is using Oracle database, and everything works just fine. For the purpose of testing I set up an H2 db. The following query now throws an error:
"SELECT * FROM ERESIS.ECH_HISFAB f WHERE f.FG_ETAT = 'A' AND TO_DATE(DT_INS) > '30-AUG-18' ORDER BY f.CD_MAT"
error:
Cannot parse "TIMESTAMP" constant "30-AUG-18"; SQL statement:
I can fix the error by setting up the string like TO_DATE('30-AUG-2018'), but changing the query kind of defeats the purpose since I already am sure the query works (but I need it to test the service). Is there any way to bypass this error without changing the query?
parsedatetime() should be able to convert string to TIMESTAMP, please try using -
"SELECT * FROM ERESIS.ECH_HISFAB f WHERE f.FG_ETAT = 'A' AND TO_DATE(DT_INS) > parsedatetime('30-AUG-2018', 'dd-MMM-yyyy') ORDER BY f.CD_MAT"
I had a similar issue with H2 (1.4.200), it has just one format for TO_DATE(input) method "DD MON YYYY".
After a debug I found that H2 uses an enum for date format when it's not provided as second parameter: org.h2.expression.function.ToDateParser.ConfigParam
TO_DATE("DD MON YYYY")
I did a solution to override it using reflection so that the sql code does not change.
In my unit test I created a utility method used to instantiate the workaround on #BeforeClass
private static boolean h2WorkaroundApplied = false; //utility to apply workaround just one time
protected static synchronized void applyH2ToOracleCompatibilityWorkaround() {
if (!h2WorkaroundApplied) {
fixH2ToDateFormat(); //apply to_date workaround
h2WorkaroundApplied = true; //disable future changes of same workaround
}
}
private static void fixH2ToDateFormat() {
try {
Class<?> classConfigParam = Arrays.stream(ToDateParser.class.getDeclaredClasses())
.filter(c -> "ConfigParam".equals(c.getSimpleName()))
.findFirst()
.orElseThrow(); //get the enum inner class
Object toDateEnumConstant = Arrays.stream(classConfigParam.getEnumConstants())
.filter(e -> "TO_DATE".equals(((Enum) e).name()))
.findFirst()
.orElseThrow(); //get the enum constant TO_DATE
Field defaultFormatStr = classConfigParam.getDeclaredField("defaultFormatStr"); //get the enum private field defaultFormatStr
defaultFormatStr.setAccessible(true);
defaultFormatStr.set(toDateEnumConstant, "YYYY-MM-DD"); //change with my date format used by production oracle DB.
} catch (Exception e) {
throw new UnsupportedOperationException(
"The current H2 version doesn't support this workaround. Tested with version 1.4.200", e);
}
}
I'm trying to create an Extent Report with several categories, this in combination with testng. But everytime I run several classes it will overwrite the last category and in the end I will only have the last category. Is there any way I can prevent this?
followin method is run in the #BeforeMethod and here I will init my test
private void setupReportBeforeTest(Method method){
Test test = method.getAnnotation(Test.class);
String author = "ABC";
String description = "Test";
try{
description = test.description().split(",author:")[0];
if (test.description().contains(",bug:")){
author = test.description().split(",author:")[1].split(",bug:")[0];
this.setJiraBug(test.description().split(",author:")[1].split(",bug:")[1]);
}else {
author = test.description().split(",author:")[1];
this.setJiraBug(null);
}
}catch (Exception e){ }
logging = extentReports.createTest(this.getTestName() + "-" + method.getName(),description)
.assignCategory(test.groups())
.assignAuthor(author).pass("Test");
}
I'm getting the groups information from the following:
#Test(groups = "Testgroup1",description = "Test1,author:Steve")
you may assign these Categories not in this setupReportBeforeTest() but in another function when tests are finished and you will have collected every groups in a table.
public void assign ( String[] testCategory)
reportTest.assignCategory(testCategory);
To write the data into the Google spreadsheet I am using following code.
private static void writeValuesInSpreedSheet(Sheets service, String spreadsheetId, int sheetSize) throws IOException {
String range = "A"+(sheetSize+1)+":K"+(sheetSize+1);
List<List<Object>> newData = new ArrayList<>();
List<Object> rowValues = new ArrayList();
rowValues.add(getCurentDateInESTFormat());
rowValues.add("2");
rowValues.add("3");
rowValues.add("4");
rowValues.add("5");
rowValues.add("6");
rowValues.add("7");
rowValues.add("8");
rowValues.add("9");
rowValues.add("10");
rowValues.add("11");
/* List<Object> rowValues1 = new ArrayList();
rowValues1.add("1");
rowValues1.add("2");*/
newData.add(rowValues);
//newData.add(rowValues1);
// response.setValues(newData);
ValueRange oRange = new ValueRange();
oRange.setRange(range); // I NEED THE NUMBER OF THE LAST ROW
oRange.setValues(newData);
List<ValueRange> oList = new ArrayList<>();
oList.add(oRange);
BatchUpdateValuesRequest oRequest = new BatchUpdateValuesRequest();
oRequest.setValueInputOption("RAW");
oRequest.setData(oList);
BatchUpdateValuesResponse oResp1 = service.spreadsheets().values().batchUpdate(spreadsheetId, oRequest).execute();
System.out.println("Response Values " +oResp1.values());
}
private static Object getCurentDateInESTFormat() {
SimpleDateFormat sdfAmerica = new SimpleDateFormat("MM/dd/YYYY");
sdfAmerica.setTimeZone(TimeZone.getTimeZone("America/New_York"));
String sDateInAmerica = sdfAmerica.format(new Date());
return sDateInAmerica;
}
In sheet we have defined the date and currency type of respective column.
I am able to write the data but eventually its prepending ' in the data for example - '09/04/2016
Because of this we are not able to open it into date format. I have attached one screen shot as well.
We are using Google Sheets API V4.
I am asking this question because i did not find any link/solution related to it.
When using the ValueInputOption RAW you need to pass dates in the serial number format. The Apache POI library provides a getExcelDate method that will handle most of this for you, but you'll need to add a day to account for the difference in the epoch used.
I'm simply trying to update a customfield value in jira using java. I had created a method updateCustomField which accepts 3 parameters (customFieldCode, value, jiraId). Had tried using transition but all it did is change the jira status from "Open" to "Resolved 2". I googled everywhere but they suggest to use JSON which I have no idea how to apply.
here's my update method:
public void updateCustomField(String customFieldCode, String value, String jiraId) throws Exception {
final IssueRestClient issueRestClient = jiraClient.getIssueClient();
final Issue issue = issueRestClient.getIssue(jiraId).get();
FieldInput fieldInput = new FieldInput(customFieldCode, value);
List <FieldInput> fields = new ArrayList <FieldInput> ();
fields.add(fieldInput);
TransitionInput transision = new TransitionInput(1, fields);
issueRestClient.transition(issue, transision);
}
For those who want to simply update jira using java, you can try this jira-client library.
I'm new at Android dev, so I'm using ActiveAndroid to manage the DB and I'm having troubles using a query with a Date variable, I have this:
From fromQuery = new Select().from(Shift.class);
//It doesn't matter what currentShiftDates do.
CurrentShiftDates currentShiftDates = new CurrentShiftDates();
fromQuery = fromQuery.where("startDate > ? and startDate < ?",currentShiftDates.startDate,
currentShiftDates.endDate);
return fromQuery.execute();
I had read that the query needs to pass the parameter as a long value, so I've tried with .getTime():
fromQuery = fromQuery.where("startDate > ? and startDate < ?",currentShiftDates.startDate.getTime(), currentShiftDates.endDate.getTime());
But it still don't work.
What I'm doing wrong?
I' m very sorry, it wasn't working because i was writing "startDate" and the column name is "StartDate", so the correct query was:
fromQuery = fromQuery.where("StartDate > ? and StartDate < ?",currentShiftDates.startDate.getTime(), currentShiftDates.endDate.getTime());