syntax error, expected end statement on QTP - hp-uft

Set obju=description.Create()
obju("name").value="user"
obju("html tag").value="input"
Arow=Browser("creationtime:=0").page("title:=.*").webedit(obju).set DataTable.Value("user",Global)
Arow=datatable.GetRowCount
For i = 1 To Arow Step 1
datatable.SetCurrentRow (i)
Next
its giving me error "The test run cannot continue due to a syntax error.
Expected end of statement"
anyone know whats going on?

In the line
Arow=Browser("creationtime:=0").page("title:=.*").webedit(obju).set DataTable.Value("user",Global)
you're assigning the return value from the webedit(obju).set procedure to the variable Arow. If you're doing this in VBScript then the arguments for the procedure need to be put in parentheses.
Following the logic of your code I'm not sure if you're intending to save a return value from the set procedure, in which case just take out assigning to the variable:
Browser("creationtime:=0").page("title:=.*").webedit(obju).set DataTable.Value("user",Global)
Similarly, in the for loop, the datatable.SetCurrentRow (i) procedure should be called as
datatable.SetCurrentRow i

Related

Assign a value to a variable on RETURN PL/SQPL

Is there a way to achieve this in PL/SQL oracle ?
RETURN (return_status:=1);
It gives a compilation error when I try to do this. If this is not possible please suggest a better alternative instead of doing
return_status := 1;
RETURN (return_status);
When we execute a RETURN the procedure terminates at that point and control flow passes to the calling program. So there would be no value in this construct …
RETURN (return_status:=1);
… because nothing in the program unit could act on return_status after the RETURN.
this is a function and return_status is an OUT param
That's the root of your problem: poor design. Either return a value or have it as an OUT parameter but not both. The accepted practice in PL/SQL is that a function returns a value and has no OUT parameters. Only procedures (which don't have RETURN) have OUT parameters.
So you choices are:
return 1 and don't have an OUT parameter
set OUT parameter = 1 and return something else
make it a procedure instead
I dont understand what the problem is?
If you want to return the value return_status then the second option is just fine(if you are really doing a hardcoded assignment you could just return 1.
And I thought maybe you actually have an external variable return_status you are trying to change the value of by calling this function. In which case, use a procedure and have return_status be an IN OUT variable(maybe even just OUT).
AFAIK, you cannot assign value in the Oracle FUNCTIONS RETURN Statement.
From Oracle Docs, the syntax should be
RETURN [[(] expression [)]];
For expression refer Expressions
Only solution i can think of based on your requirement(1 condition instead of 2) is using case expression. Something like below (if you have any condition)
RETURN
CASE when return_status is not null
THEN 1
Functions with OUT parameters are permitted but smell wrong.

Error handling in UFT

Please suggest me how to handle the scenario. Problem is supposed I got an error
at statement 2 during execution of the first iteration for Row 1 from excel then how to skip remaining statement and start the execution of statement 1 with excel row 2.
Browser("ABC").Page("ABC").WebEdit("ABC").Set "123"
Dim i
Dim iRow
iRow = datatable.GetRowCount
For i = 1 to iRow
Statement 1- Browser("ABC").Page("").WebEdit("ABC").Set DataTable("DT", dtGlobalSheet)
Statement 2- Browser("ABC").Page("").WebEdit("ABC").Set DataTable("DT", dtGlobalSheet)
Statement 3- Browser("ABC").Page("").WebEdit("ABC").Set DataTable("DT", dtGlobalSheet)
Statement 4- Browser("ABC").Page("").WebEdit("ABC").Set DataTable("DT", dtGlobalSheet)
Statement 5- Browser("ABC").Page("").WebEdit("ABC").Set DataTable("DT", dtGlobalSheet)
datatable.SetNextRow
Next
Excel sheet
Row 1 Row 2 Row 3
step1) create a new Action with Name "Action2" and put the code from inside for loop
step2) import data to Action2 local data table
step3) create a recovery scenario enable check on every line with recovery function as
function RecoveryFunction()
ExitActionIteration
End function
step4) from Action1 call Action2 with allIterations
Firstly, if your test is set to Run on all rows in File->Settings->Run then you do not require the loop you have in the code - UFT knows it needs to iterate for each row in your data table.
Secondly, all you need is the statement followed by a check on its success and any error handling. IN the event of the error, just exit the test iteration, and UFT will move onto the next one.
My reworked version of your code:
Browser("ABC").Page("ABC").WebEdit("ABC").Set "123" ' sets an initial value
Browser("ABC").Page("").WebEdit("ABC").Set DataTable("DT1", dtGlobalSheet)
If Browser("ABC").Page("").WebEdit("ABC").GetROProperty("value") <> DataTable("DT1", dtGlobalSheet) Then
' Handle error popup if it exists
Browser("ABCError").Page("").WebButton("OK").Click
ExitTestIteration
End If
Browser("ABC").Page("").WebEdit("CDE").Set DataTable("DT2", dtGlobalSheet)
If Browser("ABC").Page("").WebEdit("CDE").GetROProperty("value") <> DataTable("DT2", dtGlobalSheet) Then
' Handle error popup if it exists
Browser("ABCError").Page("").WebButton("OK").Click
ExitTestIteration
End If
Browser("ABC").Page("").WebEdit("FGH").Set DataTable("DT3", dtGlobalSheet)
If Browser("ABC").Page("").WebEdit("FGH").GetROProperty("value") <> DataTable("DT3", dtGlobalSheet) Then
' Handle error popup if it exists
Browser("ABCError").Page("").WebButton("OK").Click
ExitTestIteration
End If
Browser("ABC").Page("").WebEdit("JKL").Set DataTable("DT4", dtGlobalSheet)
If Browser("ABC").Page("").WebEdit("JKL").GetROProperty("value") <> DataTable("DT4", dtGlobalSheet) Then
' Handle error popup if it exists
Browser("ABCError").Page("").WebButton("OK").Click
ExitTestIteration
End If
Browser("ABC").Page("").WebEdit("MNO").Set DataTable("DT5", dtGlobalSheet)
If Browser("ABC").Page("").WebEdit("MNO").GetROProperty("value") <> DataTable("DT5", dtGlobalSheet) Then
' Handle error popup if it exists
Browser("ABCError").Page("").WebButton("OK").Click
ExitTestIteration
End If
I have assumed that your repeated setting of Statement 1 etc in the question is supposed to emulate setting a number of different WebEdit text boxes and coded 5 sets as an example. If, as the iteration progresses, any of the text boxes is not set to the specified data table column value (DT1 to DT5 in my example) then the If condition will be satisfied, causing the attempt to handle an error popup (you'd need to amend my guessed code to suit your requirements) followed by the exiting of the test iteration. Exiting the iteration will trigger a new one to be started, so just be sure you handle any error popup before you exit.
If all WebEdits are completed successfully, then UFT will just repeat for all iterations defined in your data table.
You need to decide one thing: are you going to use the UFT way of Data-Driven testing or you would do the whole controlling yourself
Option 1 - Do the UFT Way
Tell Uft to interpret the DataTable properly - meaning execute the Test Case as many times as many rows there are in the Global Sheet: File->Settings->Run-> Run on all rows should be checked
Tell UFT that we are in a Datat-Driven mode. At the same page set the Setting; When error occurs during run session to proceed to Next Action Iteration - uft will start the whole thing with the beginning but next line
Add the five statements in Action 1 (That's all, UFT Takes care of the rest)
Option 2 - Do it in your way
Seems like you are already doing. You implement the Loop and iterate over all the lines of the Table
Extract the 5 Statements into a function (and Function Library)
Create a function that calls the previous one in a supervised manner (and Function Library)
PSEUDO-CODE
ACTION1
ForEach row In DataTable.GlobalSheet
ExecuteStatementsSupervised row
Next
FUNCTION LIBRARY
Function ExecuteStatementsSupervised(row)
On Error Resume Next
ExecuteStatements row
If Err.Number <> 0 Then
Reporter.ReportEvent micFail, "OOPS Failed"
End If
On Error GoTo 0
End Function
SubExecuteStatements(row)
Statement1
Statement2
....
Statement5
End Sub
So in Action1 we iterate over the DataTable, in the Supervisor function we catch the error if anything happens and make sure that the iterations can go on. The real function per se, just executes the steps

What is the return type of my VBScript function?

This question is mostly out of interest to understand the functionality of VBScript better. I recognize that I can simply do some casting to know what to expect from my code, but in my situation I want to understand why casting, or any "workaround", is needed. For simplicity, here's the basic idea of my code:
variable1 = 1
Public Function findSomethingInATextString(par1, par2)
[...searching with a Do Until loop code here...]
Result = 1
If([par2 is found in par1]) Then
Result = 0
End If
Return Result
End Function
variable1 = findSomethingInATextString("Hello World", "Hello")
When I run this I get a Type Mismatch error. I don't understand why that's the case. variable1 is an integer and findSomethingInAString() returns an integer. They appear to be the same data type.
I'm working in a restricted environment where I can't do much debugging (it's painfully slow to code in this program...). So at the moment I'm unable to say what data type this is coming out as - I just know that it's apparently not integer.
After all that, and to make sure my question is clear, I'm intrigued to know what the return type of my function is (if someone happens to know), but my real question is: Why isn't the return type matching with variable1?
Use the minimal script
Return
Output
cscript 36633603.vbs
...36633603.vbs(1, 1) Microsoft VBScript runtime error: Type mismatch: 'return'
to prove to yourself, that just mentioning return in a VBScript will throw a type mismatch error.
Believe JosefZ's comment that VBScript returns function values by assigning to the function's name. Better: Read the docs (before you try to write code).
Evidence:
Function f1()
f1 = 1
End Function
WScript.Echo f1(), TypeName(f1())
Output:
cscript 36633603.vbs
1 Integer

VBScript runtime error '800a0005'

Not sure why I am getting this error for invalid procedure call for my right call.
Here is my line of code:
lcase(right(trim(RS2.Fields("First_Name")),len(RS2.Fields("Last_Name"))-1))
I can trim everything off and leave just the right function and it will not run as long as I have the length calculation in there. If I make it a simple integer it runs fine.
Make sure that len(RS2.Fields("Last_Name")) won't be 0, so the second parameter can't become -1. Either prepend an If clause or use a Max()-function that clips values < 0.
Evidence:
>> sLN = ""
>> s = Right("pipapo", Len(sLN) - 1)
>>
Error Number: 5
Error Description: Invalid procedure call or argument

PLW-06002 unreachable code when using NULL;

I occasionally do something like....
IF very-likely-condition THEN
NULL;
ELSE
<<code to deal with the unlikely condition>>
END IF;
Which gives a PLW-06002 unreachable code warning from the PL/SQL compiler on the NULL line atfer the IF.
Now whilst I can clearly ignore the warning and/or refactor the IF statement to be a NOT, I think it reads better this way.
So does anybody know is there is another way of inserting an empty statement so that I don't get the compiler warning?
EDIT:
I'm not saying I do this often... in fact I'd do it very rarely. But occasionally I do think it reads better this way.
EDIT 2:
Plus there are other scenarios where it might be valid to do this (such as ignoring a specific error in an EXCEPTION block). I only used the IF as a simple example to illustrate the point.
To Recursive And Weblog :
the following statements are NOT equivalent:
IF :x = 0 THEN
NULL;
ELSE
do_something;
END IF;
and
IF NOT :x = 0 THEN
do_something;
END IF;
If :x IS NULL the do_something procedure will be called in the first case only. This is because the expression NULL = 0 is neither TRUE nor FALSE in Oracle, it is "unknown".
The correct way to re-write the first statement would be:
IF :x != 0 OR :x IS NULL THEN
do_something;
END IF;
I can see why in some cases we could write things as the OP.
Looks like this is by design. See http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/controlstructures.htm#i5421
Example 4-23 Using NULL as a Placeholder When Creating a Subprogram
CREATE PROCEDURE ... AS
BEGIN
NULL; -- use NULL as placeholder, raises "unreachable code" if warnings enabled
END;
/
Why do you have an empty statement? That's a code smell. It's generally accepted that is it not easier to read with an empty if block.
Change your if condition to the opposite of what it currently is:
IF NOT very-likely-condition THEN
<<code to deal with the unlikely condition>>
END IF;
If you need to do something when the condition is true, you can always add that block back in. Empty blocks separate the condition from the block that's executed when the condition is true. It also looks like you used to have code in the if section, then removed it but were too lazy to rewrite the if condition to remove the empty statement.
Subjectively, if I were reading your code and saw the empty if block, I'd think you didn't know what you were doing.

Resources