Tuesday, March 25, 2014

VBScript - Change Date Format

Use case:
For the following Calendar, set second date 2 days later that first date:
'parse initia date and change the format from 25.03.14 to 25/03/14
Dim fromDate, toDate, parsedDate, i, fromDay, fromMonth, fromYear
parsedDate = Split(Browser("Browser_Local").WebEdit("From").GetROProperty("value"),".")
fromDay = parsedDate(0)
fromMonth = parsedDate(1)
fromYear = parsedDate(2)
fromDate =    fromMonth & "/" & fromDay & "/" & fromYear
fromDate =    CDate(fromDate)
'set the second date 2 days after 03/25/14 => 03/27/14
toDate = DateAdd("d","2",fromDate)
'set the second date in the desired format => 27.03.14
Dim strDate
strDate = Right("0" & DatePart("d",toDate), 2) & "." & Right("0" & DatePart("m",toDate), 2) & "." & Right(DatePart("yyyy",toDate),2)
'enter the value for the second date Browser("Browser_Local").Page("Ihr Seminar, Kurs, Coaching").RunScript("$('#Hotel_overnight_to_1').val('"& strDate &"')") 
'following is optional. in my case these elements needed to have values also
Dim oPage
Set oPage=Browser("Browser_Local").Page("Ihr Seminar, Kurs, Coaching")
Dim bisDay, bisMonth, bisYear
Set bisDay=oPage.RunScript("document.getElementsByName('hotel[overnight_to][1][day]')(0);")
bisDay.Value=Right("0" & DatePart("d",toDate), 2)
Set bisMonth=oPage.RunScript("document.getElementsByName('hotel[overnight_to][1][month]')(0);")
bisMonth.Value=Right("0" & DatePart("m",toDate), 2)
Set bisYear=oPage.RunScript("document.getElementsByName('hotel[overnight_to][1][year]')(0);")
bisYear.Value=DatePart("yyyy",toDate)    

Run Javascript in UFT (QTP)

 Browser("Browser_Local").Page("MyPage").RunScript("$('#Hotel_overnight_to_1').val('25.03.14')") 
   
    Dim oPage
    Set oPage=Browser("Browser_Local").Page("MyPage") 
      Dim bisDay, bisMonth, bisYear
     
    Set bisDay=oPage.RunScript("document.getElementsByName('hotel[overnight_to][1][day]')(0);") 
    bisDay.Value="25"
   
    Set bisMonth=oPage.RunScript("document.getElementsByName('hotel[overnight_to][1][month]')(0);") 
    bisMonth.Value="03"
   
    Set bisYear=oPage.RunScript("document.getElementsByName('hotel[overnight_to][1][year]')(0);") 
    bisYear.Value="2014"

Source:
http://qtpcodes.blogspot.de/2011/10/running-javascript-in-qtp.html

Monday, March 24, 2014

Uninstall ALM-Client

1. Delete all files under following locations:
    %ALLUSERSPROFILE%\HP\ALM-Client
    %UserProfile%\AppData\Local\HP\ALM-Client
    %LocalAppData%\HP\ALM-Client
    %ALLUSERSPROFILE%\Application Data\HP\ALM-Client
    %UserProfile%\Local Settings\Application Data\HP\ALM-Client
    %temp%/td_80

2. Reopen ALM.

Source:
http://h30499.www3.hp.com/t5/Quality-Center-Support-and-News/How-do-I-uninstall-the-ALM-QC-v11-client/td-p/5616791#.UzAebvmSxlT 

Open ALM Client outside IE

If you need to open ALM-Client outside Internet Explorer you can open in IE following link:

http://ServerName/qcbin/start_a.jsp?embedclient=false

This will open ALM-Client.


Monday, March 17, 2014

UFT - Wait until Loading Icon is no longer displayed

I had something like this:

Search for something -> loading icon displayed until search is done -> results are displayed.
Here is the solution using XPath:

While Browser("Browser_Local").WebElement("xpath:=//div[contains(@class,'hitsArea')]/descendant::td[contains(@class,'cell-loadingIcon') and not(contains(@style,'display: none'))]").Exist = False
    wait 2
Wend

- It looks for the div, that contains a class named "hitsArea"
- finds between its descendants, one that contacins a class named "cell-loadingIcon"
- and it is not hidden: not(contains(@style,'display: none'))


Friday, February 14, 2014

Record what you do with Windows Problem Steps Recorder

Here is a simple way to record the steps to reproduce a problem:

1. Start -> Run -> psr.exe
    Following program opens:







2. Start record.
3. Perform your scenario.
4. Stop Record and save the file.

=> You will get a report with HD screenshots of everything you did. I was expecting a movie, but considering it's free and easy to use, I'm happy.

Source:
http://www.youtube.com/watch?v=70lmYJaUWJ8

Thursday, February 13, 2014

QTP / UFT - Object identification using XPath

Did you experience a situation where you had a WeElement that was visible only at mouse over, and UFT would not recognize it even if you pay for that?

Here is something to try:

1. Open site in Chrome browser.
2. Press F12 to see DevTools.
3. Go to the desired element, Right-click on it and select "Inspect Element".
4. The element will bie highlighted in the DevTools zone:
\
5. Copy XPath, and paste somewhere to use it, you should have something like this:

//*[@id="highcharts-0"]/svg

6. Enter the code in UFT. Should be something like:

 Browser("Browser_Local").Page("MyPage").WebElement("xpath:="//*[@id='highcharts-0']/svg"").Click

Hope this helps!

Note: Special thanks to my colleague Mihai, who pointed this out.