Key sequence for DateTime format "YYYY-MM-DD HH-MM"

Best practices, code snippets for common functionality, examples, and guidelines.
gowthamp
Posts: 16
Joined: Fri Feb 05, 2016 7:19 pm

Key sequence for DateTime format "YYYY-MM-DD HH-MM"

Post by gowthamp » Fri Feb 05, 2016 7:29 pm

Hello,
I am new to Ranorex and C#, I want to enter Key sequence of Date and Time for a name which could be deleted at end of test run.[Application doesn't support repetition of Name :( ]

I want to enter Key sequence of format "YYYY-MM-DD HH-MM" ,so that every time I run the test case it will provide unique name.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Key sequence for DateTime format "YYYY-MM-DD HH-MM"

Post by odklizec » Mon Feb 08, 2016 2:07 pm

Hi,

You can try something like this...

Code: Select all

string curDate = DateTime.Now.ToString("yyyy-MM-dd HH-mm");
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

gowthamp
Posts: 16
Joined: Fri Feb 05, 2016 7:19 pm

Re: Key sequence for DateTime format "YYYY-MM-DD HH-MM"

Post by gowthamp » Mon Feb 08, 2016 4:41 pm

Defined variable with string type.
"repo.Testcase.Title.PressKeys(""+variable+"", 100);" working fine.
This creates variable with required format.

In this testcase I have like to click on this variable after creating it.
How can I click on this item?

Thanks odklizec for your help in creating variable with DateTime format.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Key sequence for DateTime format "YYYY-MM-DD HH-MM"

Post by odklizec » Mon Feb 08, 2016 7:13 pm

I'm afraid, I don't understand what exactly you want to achieve? If you just want to combine the code I posted with the keypress code, it should look like this...

Code: Select all

string curDate = DateTime.Now.ToString("yyyy-MM-dd HH-mm");
repo.Testcase.Title.PressKeys(curDate, 100);
You can then call this code from user code or code module.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

gowthamp
Posts: 16
Joined: Fri Feb 05, 2016 7:19 pm

Re: Key sequence for DateTime format "YYYY-MM-DD HH-MM"

Post by gowthamp » Mon Feb 08, 2016 7:21 pm

Part One Creation: I created variable with curDate.
After creating that I have save button which will save the variable with curDate value.

I will make few other clicks and will return back to this page.
Part Two : In that page I have to make a click on the variable curDate which was created earlier.

Example: I created variable with curDate value of "2016-02-08 14:10" and saved it.
After returning to this page, I have to click "2016-02-08 14:10" on this name.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Key sequence for DateTime format "YYYY-MM-DD HH-MM"

Post by odklizec » Mon Feb 08, 2016 9:38 pm

OK, but you know, you can't click the variable, right? It would be much easier if you could post a Ranorex snapshot of the second page, so we can see what kind of element you want to click and its xpath. It's hard to suggest something reliable without detailed info about your AUT, the technology it's built with, etc.

In general, if the actions you are supposed to perform on second page are in different recording/code module than the one in which you created the date variable, you will have to store the date variable in global parameter, so you can access it from anywhere in your test. There are also other ways, but using global parameters is probably the easiest solution?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

gowthamp
Posts: 16
Joined: Fri Feb 05, 2016 7:19 pm

Re: Key sequence for DateTime format "YYYY-MM-DD HH-MM"

Post by gowthamp » Mon Feb 08, 2016 10:04 pm

Attached screenshot of row, sorry for not attaching Snapshot[its revealing all GUI of application].
I have to create shiftname with testShift+"YYY-MM-DD HH-MM" format.
After that I have to make changes to StartTime and EndTime which are 2nd and 3rd columns .

Then I have to click on ShiftName[testShift+"YYY-MM-DD HH-MM"] to edit it.

All the time, I will make changes in current page. In this scenario Date Variable may not need to be Global parameter.
Attachments
ShiftName.png
ShiftName, StartTime, EndTime
ShiftName.png (7.4 KiB) Viewed 1429 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Key sequence for DateTime format "YYYY-MM-DD HH-MM"

Post by odklizec » Tue Feb 09, 2016 7:26 am

Well, without snapshot, there is not much I can do for you, except some general suggestions. What you need to do is to add a repository item with your created date time variable. How to create a repo item with variable you can learn here...
http://www.ranorex.com/support/user-gui ... html#c2970

In case the datetime string is located in the innertext attribute, the end of xpath should look like this...
//elementname[@innertext~$curDate]

Then you can simply drag&drop just created repo item to recording table and from the appeared context menu (after drop) select mouse click action.

That's all ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration