QTP Using if statement for Run Time Object - if-statement

How can I set up the if statement so that QTP will display Passed or Failed if conditions met. Currently I have the properties of a valid coupon and invalid coupon. Each will display a different message on the website. Please see the code below:
Set objBrowser = Browser("name:=.*Chico's")
Set objPage = objBrowser.Page("title:=.*Chico's")
Dim x
x=datatable.GetSheet("Global").GetRowCount
'-----for loop---------
For i = 1 To x Step 1
Datatable.SetCurrentRow(i)
objPage.WebEdit("html tag:=INPUT","html id:=claimCodeField","name:=claimCodeField").Set datatable ("Coupon_code", GlobalSheet)
wait 2
objPage.Image("name:=CouponFormHandler","html tag:=INPUT","image type:=Image Button","file name:=btn_apply\.gif").Click
wait 2
objBrowser.Sync
Dim Coupon, Couponerror
xlCoupondescription=dataTable ("Coupon_description", GlobalSheet)
xlInvalid=dataTable("Invalid_coupon", GlobalSheet)
'----Coupon----
Coupon=objPage.WebElement("class:=sb-promo-msg","html tag:=SPAN","html id:=","Index:=1").GetROProperty("outertext")
'----Coupon Error msg-----
Couponerror=objPage.WebElement("class:=sb-error-message","html tag:=DIV","html id:=").GetROProperty("outertext")
'----if statement---------
If (Trim(Coupon) = Trim(xlCoupondescription)) Then
datatable.value("Actual_results", GlobalSheet)="Passed"
If (Trim(Coupon) = Trim(Couponerror)) Then
datatable.value("Actual_results", GlobalSheet)="Failed"
End If
End If

Use the Reporter.ReportEvent method when you want to report custom pass/fail conditions.

Related

Report during local report processing which have not specified, Path format not support

I Have install all package which need for reports viewer but still show have error apply all format path but still face problem.
this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + #"C: \Users\nazir\OneDrive\Documents\Nazam pos\Reportproduct.rdlc";
this.reportViewer1.LocalReport.DataSources.Clear();
DataSet1 ds = new DataSet1();
SqlDataAdapter da = new SqlDataAdapter();
cn.Open();
da.SelectCommand = new SqlCommand("select p.pcode ,p.barcode,p.pdesc,b.brand,c.category,p.purchase,p.price, p.qty, p.reorder from tblProducts as p inner join tblBrand as b on p.bid=b.id inner join tblCategory as c on p.cid=c.id ", cn);
da.Fill(ds.Tables["dtproduct"]);
cn.Close();
enter image description here
Image show error
As #Paulo Santos mentioned, you should check if ReportPath's value is correct, set a breakpoint on the row of the following code and check the value of ReportPath
this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + #"C: \Users\nazir\OneDrive\Documents\Nazam pos\Reportproduct.rdlc";
In addition, please modify the code as below and check if it works. mark sure the rdlc file is exist on the fold.
this.reportViewer1.LocalReport.ReportPath = #"C: \Users\nazir\OneDrive\Documents\Nazam pos\Reportproduct.rdlc";

Can any of the SAS METADATA_GET* functions give information on authorizations

We use SAS in a client server setup with a metadata server.
I use SAS Functions for Reading Metadata
to read attributes and relations of SAS libraries, tables, folders etc from the metadata.
To verify our setup, we would like to list who can access what, i.e. to programmatically retrieve what you can find in SAS Management Console on the Authorization tab of an object's properties:
Does anyone know where to find that information?
For your inspiration: I usually use the functions to read metadata in a datastep, but this time, I used Lua
proc Lua restart;
submit;
debug = true
maxDo = 9
function getObjAttr(uri, attrList, old_obj)
new_obj = old_obj or {}
if debug then new_obj.uri = uri:gsub("%s+$", "") end
-- list only the requested attributes
local val_256 = string.rep("v",256)
for _, attrName in ipairs(attrList) do
if sas.METADATA_GETATTR(uri, attrName, val_256) >= 0 then
new_obj[attrName] =
( attrName:sub(1, 2) == 'Is'
or attrName == 'NumRows'
or attrName == 'UsageVersion' ) and tonumber(val_256)
or val_256:gsub("%s+$", ""):gsub("^%s+", "")
end
end
-- list all properties
local prop_256 = string.rep("p",256)
for prop_nr = 1, maxDo do
if sas.METADATA_GETNPRP(uri, prop_nr, prop_256, val_256) < 0 then break end
new_obj["_".. prop_256:gsub("%s+$", "")] = val_256:gsub("%s+$", "")
end
return new_obj
end
-- find the path to an object
function getLocation(uri)
local folder_256 = string.rep("f",256)
if sas.METADATA_GETNASN(uri,
string.find(uri, ":Tree") and 'ParentTree' or 'Trees',
1, folder_256) >= 0
then
return getObjAttr(folder_256, {'name'}, {location = getLocation(folder_256)})
end
end
-- collect all libraries
lib_set = {}
for obj_nr = 1, maxDo do
local uri_256 = string.rep("u",256)
-- test with a limited set
if sas.METADATA_GETNOBJ("SASLibrary?#name contains '_CBC'", obj_nr, uri_256) < 0 then break end
-- to get all, change to SASLibrary?#id contains '.'
lib_set[uri_256:gsub("%s+$", ""):gsub(".+%.", "")] =
getObjAttr(uri_256, {'name', 'libref', 'engine'}, {location = getLocation(uri_256)})
end
if debug then print("Lua: ".. table.tostring(lib_set)) end
-- to be completed with code to export the relevant info to sas datasets
endsubmit;
run;
I don't think this is possible in pure macro. However - it can be done with batch tools.
I started a PR to the core library that would make use of these - if you feel like finishing it off, be my guest! Our current SAS 9 environment does not have X Command so I can't test it.
https://github.com/sasjs/core/pull/45/files

Excel data import in specific cell

I would like to list up devices and put their prices next to them.
My goal is to check different sites every week and notice trends.
This is a hobby project, I know there are sites that already do this.
For instance:
Device | URL Site 1 | Site 1 | URL Site 2 | Site 2
Device a | http://... | €40,00 | http://... | €45,00
Device b | http://... | €28,00 | http://... | €30,50
Manually, this is a lot of work (checking every week), so I thought a Macro in Excel would help. The thing is, I would like to put the data in a single cell and excel only recognises tables. Solution: view source code, read price, export price to specific cell.
I think this is all possible within Excel, but I can't quiet figure out how to read the price or other given data and how to put it in one specific cell. Can I specify coordinates in the source code, or is there a more effective way of thinking?
First of all you have to find out how does the website works. For the page you asked I have done the following:
Opened http://www.mediamarkt.de page in Chrome.
Typed BOSCH WTW 85230 in the search box, suggestion list appeared.
Pressed F12 to open developer tools and clicked Network tab.
Each time I was typing, the new request appeared (see yellow areas):
Clicked the request to examine general info:
You can see that it uses GET method and some parameters including url-encoded product name.
Clicked the Response tab to examine the data returning from the server:
You can see it is a regular JSON, full content is as follows:
{"suggestions":[{"attributes":{"energyefficiencyclass":"A++","modelnumber":"2004975","availabilityindicator":"10","customerrating":"0.00000","ImageUrl":"http://pics.redblue.de/artikelid/DE/2004975/CHECK","collection":"shop","id":"MediaDEdece2358813","currentprice":"444.00","availabilitytext":"Lieferung in 11-12 Werktagen"},"hitCount":0,"image":"http://pics.redblue.de/artikelid/DE/2004975/CHECK","name":"BOSCH WTW 85230 Kondensationstrockner mit Warmepumpentechnologie (8 kg, A++)","priority":9775,"searchParams":"/Search.ff?query=BOSCH+WTW+85230+Kondensationstrockner+mit+W%C3%A4rmepumpentechnologie+%288+kg%2C+A+%2B+%2B+%29\u0026channel=mmdede","type":"productName"}]}
Here you can find "currentprice":"444.00" property with the price.
Simplified the request by throwing out some optional parameters, it turned out that the same JSON response can be received by the URL http://www.mediamarkt.de/FACT-Finder/Suggest.ff?channel=mmdede&query=BOSCH+WTW+85230
That data was enough to built some code, assuming that first column intended for products:
Option Explicit
Sub TestMediaMarkt()
Dim oRange As Range
Dim aResult() As String
Dim i As Long
Dim sURL As String
Dim sRespText As String
' set source range with product names from column A
Set oRange = ThisWorkbook.Worksheets(1).Range("A1:A3")
' create one column array the same size
ReDim aResult(1 To oRange.Rows.Count, 1 To 1)
' loop rows one by one, make XHR for each product
For i = 1 To oRange.Rows.Count
' build up URL
sURL = "http://www.mediamarkt.de/FACT-Finder/Suggest.ff?channel=mmdede&query=" & EncodeUriComponent(oRange.Cells(i, 1).Value)
' retrieve HTML content
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", sURL, False
.Send
sRespText = .responseText
End With
' regular expression for price property
With CreateObject("VBScript.RegExp")
.Global = True
.MultiLine = True
.IgnoreCase = True
.Pattern = """currentprice""\:""([\d.]+)""" ' capture digits after 'currentprice' in submatch
With .Execute(sRespText)
If .Count = 0 Then ' no matches, something going wrong
aResult(i, 1) = "N/A"
Else ' store the price to the array from the submatch
aResult(i, 1) = .Item(0).Submatches(0)
End If
End With
End With
Next
' output resultion array to column B
Output Sheets(1).Range("B1"), aResult
End Sub
Function EncodeUriComponent(strText)
Static objHtmlfile As Object
If objHtmlfile Is Nothing Then
Set objHtmlfile = CreateObject("htmlfile")
objHtmlfile.parentWindow.execScript "function encode(s) {return encodeURIComponent(s)}", "jscript"
End If
EncodeUriComponent = objHtmlfile.parentWindow.encode(strText)
End Function
Sub Output(oDstRng As Range, aCells As Variant)
With oDstRng
.Parent.Select
With .Resize( _
UBound(aCells, 1) - LBound(aCells, 1) + 1, _
UBound(aCells, 2) - LBound(aCells, 2) + 1 _
)
.NumberFormat = "#"
.Value = aCells
.Columns.AutoFit
End With
End With
End Sub
Filled worksheet with some product names:
Launched the sub and got the result:
It is just the example how to retrieve a data from the website via XHR and parse a response with RegExp, I hope it helps.

Omnet Tkenv run config for multiple parameters: executing only the first value of parameter

My ini code for the config is as:
[Config BR54MBPS1MS]
description = "at 54MBPS with SI 1ms for 1250 Bytes with all time interval"
repeat = 2
sim-time-limit = 1 min
**.scalar-recording = true
**.vector-recording = false
**.host1.udpApp[0].messageLength = 1250B
**.wlan*.bitrate = 54Mbps
**.host1.udpApp[*].sendInterval = ${interval = 100..1200 step 100} us
**.vector-recording = false
output-scalar-file = 54Mbps/${configname}54Mbps${interval}us.sca
and I want to run it for all given intervals from 100 us to 1200 us with a gap of 100 us (at 100, 200, 300 ... us) in omnet tkenv or gui. The only option I read for it is by run it through run configuration as:
The problem is that, it runs only for 100us successfully, generates the output sca file and terminates the process. I am not able to figure out the reason for not running the for the next send interval.
In order to run all combinations of sendInterval values you should write * (asterisk) in Run number field and select Command line interface. Multiple runs are not possible when Tcl/Tk user interface is selected.

Two checkbuttons to toggle sound not working right

self.mb = Menubutton ( self.window2, text="Sound Toggler", relief=RAISED )
self.mb.grid(row=4, column = 0)
self.mb.menu = Menu ( self.mb, tearoff = 0 )
self.mb["menu"] = self.mb.menu
self.ONSound = IntVar()
self.ONSound.set(1)
self.OFFSound = IntVar()
self.OFFSound.set(0)
self.mb.menu.add_checkbutton ( label="ONSound", variable=self.ONSound, command = self.turnON(), onvalue=1,offvalue=0)
self.mb.menu.add_checkbutton ( label="OFFSound", variable=self.OFFSound, command = self.turnOFF(), onvalue=1,offvalue=0)
def turnON(self):
self.ONSound.set(1)
self.OFFSound.set(0)
def turnOFF(self):
self.ONSound.set(0)
self.OFFSound.set(1)
My goal is to turn these two check buttons to toggle sound On and OFF and in doing so only one of these check buttons can be on/off at a single time. Currently this effect is not working and I've been looking at my code for an hour and can't find the problem. Everything shows up when my full program is run but this ON/OFF toggle doesn't work how I want it to.
All help is appreciated,
Thanks
The problem is that you set the command to a function call instead of a funciton reference. This makes the functions run once and assign the return value (None) to command. You should remove the parentheses after the function names.
To make two options of which only one can be selected however, why don't you make them radiobuttons? Then it's as simple as
self.Sound = IntVar()
self.mb.menu.add_radiobutton(label= "ONSound", variable=self.Sound, value=1)
self.mb.menu.add_radiobutton(label="OFFSound", variable=self.Sound, value=0)