| || |
Renaming/shortening browser name for use as a variable?
Thank you for reading, firstly. I love this place, it's helped me immensely in learning UFT. I have a question, the goal of which I'm not sure is even achievable, but I'm fairly new to UFT and programming in general so I'm overthinking it maybe. Here is the scenario:
I am attempting to automate a webpage report running script. This webpage has several links on it that open into separate PDF windows, and the script then saves the PDF to a specified directory on the local hard drive, closes the window and moves on to the next link. Through searching the forums here I figured out how to set variables so it would save in the preferred format of 'report name + current time', as shown in the line of code below:
Browser("Report Link 1").Dialog("Save As").WinEdit("File name:").Set "C:\Users\Users1\Desktop\T1\" + a + " " + rndm
where a is a variable that equals the browser name and rndm is a variable equaling current date and time.
My issue is that when it saves this way, the file name ends up being "Report Link 1 - Reports Viewer Page mm/dd/yy xx:xx:xx", because the full name of the browser is indeed "Report Link 1 - Reports Viewer Page" as in the OR properties. I've changed it there to shorten it to just Reports Link 1, but then it causes my text checkpoint to error out and it will no longer find the window to finish the rest of the script.
So, my actual question is how do I code it so that only the file name saves without adding the 'Reports Viewer Page' portion to the filename, if it's even possible? Maybe through regular expressions or something, but I'm not so knowledgeable about using them, though I figured it out enough for the checkpoints I needed to add.
Also, is there a different way to indicate to UFT to add the browser name as part of the saved filename other than declaring it as a variable? Right now, the line I use is as follows:
a=Browser("Report Link 1").GetROProperty("title")
Any and all help or other suggestions would be greatly appreciated!
tl;dr: Shortening browser name in OR properties causes script to stop working, through what method can I use only part of the browser name for purposes of file saving? Thank you!!
What the name is in the OR is irrelevant. When you use the GetROProperty command you are getting that from the browser itself. Is there always a hyphen between the part you want to keep and use for the file name and what you want to trim off? Could just do some string manipulation. Find position of "-", take the left portion of the string up to that point minus 2 for the space and the hyphen.
if a = "Report Link 1 - Reports Viewer Page"
then this would get you what you want.
a = left(a,instr(a,"-") - 2)
Last edited by NoUse4aName; 12-10-2015 at 03:24 PM.
My app displays PDFs (in another browser) what I do is pass the name of the file I want to save the PDF as to a function and let the function save it.
TEST_EVIDENCE_FOLDER & THIS_APP are global variables that hold the test evidence folder location and the sub folder of application area e.g.
TEST_EVIDENCE_FOLDER = "C:\Automation\TestEvidence"
THIS_APP = "AccountCreation"
the "regexpwndtitle:=rwservlet.pdf" is the name pre-populated in the "Save As" file name, you may have to amend this for your app.
Browser("CreationTime:=1").WinObject("object class:=AVL_AVView", "text:=AVPageView").Type micCtrlDwn + micShiftDwn + "s" + micCtrlUp + micShiftUp
fname = LCase(TEST_EVIDENCE_FOLDER & THIS_APP & Chr(92) & Environment("TestName") & Chr(92) & sFileName & MISC_DateTime(Now) & ".pdf")
YYYY = DatePart("yyyy",dateTime)
MM = DatePart("m",dateTime)
DD = DatePart("d",dateTime)
HH = DatePart("h",dateTime)
Mins = DatePart("n",dateTime)
SS = DatePart("s",dateTime)
MISC_DateTime = YYYY & MM & DD & HH & Mins & SS
I just tried this, and it worked perfectly! To answer the question, yes, that hyphen is a constant, and this now saves the file name the way I want. And I have a nice new programming command to work into my repertoire. Thanks for the assistance!
Hey Mark, interesting idea with the code, looks a bit advanced for me currently, but I'm already working out how to understand it. And one day, I may even incorporate it. I have a question on this though.
Is there a particular reason you went with the "micCtrlDwn + micShiftDwn + "s" + micCtrlUp + micShiftUp" command which I assume is for saving the file?
Right now I'm using a sendkeys command of ctrl+shift+s to open the save dialog, but as I mentioned I'm new to programming and was happy enough to stop looking for a better solution once I got it to work. I'm just wondering if your method is better for UFT or some other reason I'm unaware of, or if it was just preference?
Thanks again for the help, greatly appreciated
No advantage in either method, both will work fine.