How to add system date on ui pop up instead of key sequence

Ask general questions here.
gsb
Posts: 17
Joined: Wed Mar 17, 2021 3:49 pm

How to add system date on ui pop up instead of key sequence

Post by gsb » Wed Apr 07, 2021 10:38 pm

Instead of key sequence how to use system date in DD/MM/YYYY format to pass for every scenario.
repo path for element

Testcase code when converted key sequence into code
public void Key_sequence_ApplicationDate(RepoItemInfo inputtagInfo)
{
Report.Log(ReportLevel.Info, "Keyboard", "Key sequence '04/07/2021' with focus on 'inputtagInfo'.", inputtagInfo);
inputtagInfo.FindAdapter<InputTag>().PressKeys("04/07/2021");
}

repo path of element

?/?/form[@id='undefined']/tag[2]/tag[@tagname='row']/div/tag[@tagname='dynamic-control']/tag[@tagname='ng-component']/div/div/div/input[@id='applicationDate']

locked code
Report.Log(ReportLevel.Info, "Keyboard", "Key sequence '04/07/2021' with focus on 'FairwayBrokerPortal.ModalBodyTextCenter1.ApplicationDate'.", repo.testurlPortal.ModalBodyTextCenter1.ApplicationDateInfo, new RecordItemIndex(49));
repo.userportalPortal.ModalBodyTextCenter1.ApplicationDate.PressKeys("04/07/2021");
Delay.Milliseconds(0);

And how to get immediate response or online support for licensed users ? We have two currently Floating

User avatar
Mike K
Certified Professional
Certified Professional
Posts: 28
Joined: Wed Jun 28, 2017 5:58 pm

Re: How to add system date on ui pop up instead of key sequence

Post by Mike K » Wed Apr 07, 2021 11:24 pm

Hi,

If I understand correctly you are looking to auto fill you date selection use system time. To do this we will write a simple coded action to place today's date in the correct format using the code below.


public void GetTime()
{
System.DateTime dt = System.DateTime.Today;
string date = String.Format("{0:MM/dd/yyyy}", dt);

repo.TestWebApplicatio.datefield.PressKeys(date);

}

Hope this helps!

Cheers,
Mike

gsb
Posts: 17
Joined: Wed Mar 17, 2021 3:49 pm

Re: How to add system date on ui pop up instead of key sequence

Post by gsb » Thu Apr 08, 2021 12:11 am

yes Mike you understand it correctly

Since my test only works on today date

If you please also tell me where to write this code have shared everything here..

oh got it !! need to Map the user code with newly created GetTime() function ?

seems it works (added.jpg file)

Thanks

BTW what does this code do ?
string date = String.Format("{0:MM/dd/yyyy}", dt)
Attachments
added.JPG
added.JPG (10.01 KiB) Viewed 142 times
Capturedate.JPG
Capturedate.JPG (24.27 KiB) Viewed 142 times

User avatar
Mike K
Certified Professional
Certified Professional
Posts: 28
Joined: Wed Jun 28, 2017 5:58 pm

Re: How to add system date on ui pop up instead of key sequence

Post by Mike K » Thu Apr 08, 2021 12:36 am

Hi there,

My apologizes for not explaining this very well but I am glad to hear you were able to easily decipher what I was trying to say :)

This code is taking the System.Date value and converting to the format we need and then saves it to a String data type which is what Ranorex needs.

//Create a variable to hold today's date
System.DateTime dt = System.DateTime.Today;

//Format the date variable in MM/dd/yyyy format and save it to a String variable.
string date = String.Format("{0:MM/dd/yyyy}", dt);

Hope this helps!

Cheers,
Mike

gsb
Posts: 17
Joined: Wed Mar 17, 2021 3:49 pm

Re: How to add system date on ui pop up instead of key sequence

Post by gsb » Thu Apr 08, 2021 9:37 pm

Np Prob Bro, Many Thanks for explaining . Thank you

Just another query how add particular date in same code Like previous and current employment Start and End date

public void Empdate()
{
System.DateTime dt = System.DateTime.Today;
string date = String.Format("{0:MM/dd/yyyy}", dt);

repo.TestWebApplicatio.datefield.PressKeys(date);

}

Thanks Mike :)

User avatar
Mike K
Certified Professional
Certified Professional
Posts: 28
Joined: Wed Jun 28, 2017 5:58 pm

Re: How to add system date on ui pop up instead of key sequence

Post by Mike K » Fri Apr 09, 2021 1:14 am

Something like this will give you previous date or future date

System.DateTime dt = System.DateTime.Today-7; //This would give you last week

System.DateTime dt = System.DateTime.Today+7; //Will give you next week

It is really up to you to determine how you want to calculate past and future dates.

Cheers,
Mike

gsb
Posts: 17
Joined: Wed Mar 17, 2021 3:49 pm

Re: How to add system date on ui pop up instead of key sequence

Post by gsb » Mon Apr 12, 2021 4:19 pm

Thanks. Mike :)