In the BuiltIn library, there are a ton of "Run keyword If.." commands, but I don't want to test a condition and then run a keyword. Is it possible to use the conditional "if" or "else" without involving keywords?
It appears you misunderstand how robot works. Everything you do in robot is with keywords. Robot framework isn't a programming language, it's a keyword driven framework. Its only purpose is to run keywords.
If you want to run click element based on a condition, you do it with run keyword if since click element is itself a keyword.
For example:
*** Test Cases ***
Examples
Run keyword if '${PO_Dictionary.ExistingMember}' == 'Yes'
... Click Element ${EXISTING_MEMBER_YES_RADIO}
... ELSE
... Click Element ${EXISTING_MEMBER_NO_RADIO}
Unfortunately, running multiple commands in an if statement is difficult. If you only want to run Input Text ${ZIP_TEXT} ${PO_Dictionary.ZipCode} in the else clause, you have to either call run keywords or create a small keyword.
For example:
*** Test Cases ***
Examples
run keyword if '${PO_Dictionary.ExistingMember}' == 'Yes'
... Click Element ${EXISTING_MEMBER_YES_RADIO}
... ELSE Run keywords
... Click Element ${EXISTING_MEMBER_NO_RADIO}
... AND Input Text ${ZIP_TEXT} ${PO_Dictionary.ZipCode}
Related
I am using RSpec.shared_context to set variables that all the describe blocks will use.
Something like this
RSpec.shared_context "common" do
let(:name) { #creates a database object }
#more let statements
end
Now I invoke it from describe block like so
describe "common test" do
include_context "common"
#run few tests
end
Now after running the describe block I want to clean it up. How do I rollback all the objects created in the shared context?
I tried cleaning it in the after(:context) hook but since it is a let statement the variable name is only allowed inside examples.
Is there someway I can use use_transactional_fixtures to clean this up after running the tests in the describe block.
You don't need to worry about cleaning up your "lets" if you just setup your test suite properly to wipe the database.
Use let to define a memoized helper method. The value will be cached
across multiple calls in the same example but not across examples.
Note that let is lazy-evaluated: it is not evaluated until the first
time the method it defines is invoked.
In almost every case you want teardown to happen automatically and per example. Thats what config.transactional_fixtures does - it rolls back the database after every example so that you have a fresh slate and don't get test ordering issues. Relying on each example / context whatever to explicitly clean up after itself is just a recipe for failure.
ANSWER TO THE QUESTION
Please, dear reader, if you wish, you can proceed further and read through the question. But at the most top I'm willing to provide Dmitri's answer, so that others won't waste time playing around with Jmeter If Controller.
If you wish to use multiple condition statement in If Controller,
specifically if you want to check that variables equal some strings,
DON'T USE ${__javaScript()} FUNTION!!! Dmitri suggested to use instead
${__groovy()} function, which worked in my situation. Correct syntax
below. Pay attention to opening parenthesis, comma location and closing curly brackets:
${__groovy((vars.get('yourVariable').equals('someString') &&
vars.get('yourAnotherVariable').equals('someOtherString')),)}
Addition
If you want to save your time while trying to make If Controller working with multiple conditions, always uncheck Interpret Condition as Variable Expression checkbox. Otherwise you will have to stuck with those __javaScript, __groovy or other functions, as there is no way to understand how the hell they suppose to work and why they don't resolve to true or false (log file is always clean at this situation). This is how you do without help of those "functions". Please see my example below
${yourVariable} != 'not_found' && ${youAnotherVariable_matchNr} == 1
That's it, no need to use any functions.
INITIAL QUESTION
In Jmeter v4.0 r 1823414 I can use If Controller only with single statement, but not with multiple. Example of using multiple statements I have taken from here and it was suggested to use
${__javaScript("${responsecode}"=="404")} &&
${__javaScript("${responseMessage}" == "Not Found")}
I have also checked blazemeter tutorial page, but it says nothing about multiple conditional statements inside If Controller.
Example of my Test Plan is below
In my Debug Sampler I can see following
At some place in the Test Plan I put IF Controller to check that both variables are equal to not_found...
${__javaScript(vars.get('manual_bug')=='not_found')} && ${__javaScript(vars.get('integration_bug')=='not_found')}
...so all the subsequent actions are executed. However, this IF Controller either never gets executed or always return FALSE. Not sure what's happening with it.
Before blaming me :-) that I didn't do enough research and rushed to ask a question on SO, I will provide below samples of what I've already tried and that didn't help:
With double quotes around variables
${__javaScript(vars.get("manual_bug")=="not_found")} && ${__javaScript(vars.get("integration_bug")=="not_found")}
With additional space between equal sign
${__javaScript(vars.get('manual_bug') == 'not_found')} &&
${__javaScript(vars.get('integration_bug') == 'not_found')}
Avoid using vars.get
${__javaScript(${manual_bug} == 'not_found')} && ${__javaScript(${integration_bug} == 'not_found')}
Using double quotes without vars.get
${__javaScript(${manual_bug} == "not_found")} && ${__javaScript(${integration_bug} == "not_found")}
My log file looks completely fine, no errors
Please advise if someone was able to execute multiple conditional statements in the Jmeter tool? Thanks!
In the link you're referencing the 2 clauses are in a single __javaScript() function and you have 2 different functions so JMeter doesn't know what does your && means especially given Interpret Condition as Variable Expression? default mode of the If Controller.
Also if you open If Controller GUI you will see the following warning:
For performance it is advised to check "Interpret Condition as Variable Expression"
and use __jexl3 or __groovy evaluating to true or false or a variable that contains true or false.
${JMeterThread.last_sample_ok} can be used to test if last sampler was successful
Therefore I would recommend reconsidering your approach and use __groovy() function, the relevant syntax would be:
${__groovy((vars.get('responseCode').equals('404') && vars.get('responseMessage').equals('Not Found')),)}
Demo:
The following syntax (with double quotes) works too, however it also requires that you uncheck the 'Interpret Condition as Variable Expression' setting.
"${yourVariable}" != "not_found" && "${youAnotherVariable_matchNr}" == "1"
In SSDT project (using VS2017/VS2015, SSDT version 15.1.61702.140), I cannot get my project to build. The compiler keeps complaining about the sql statement in my PostDeploymentScript (yes, I have set the BuildAction property to PostDeploy). The sql statement is:
if ('$(env)' = 'dvp')
BEGIN
PRINT 'creating users for dvp'
:r .\SecurityAdditions\usersdvp.sql
END
ELSE IF ('$(env)' = 'qat')
BEGIN
PRINT 'creating users for qat'
:r .\SecurityAdditions\usersqat.sql
END
The actual error message is:
D:\My\File\Path\PostDeploymentScript.sql (lineNum, col): Error: SQL72007:
The syntax check failed 'Unexpected end of file occurred.' in the batch near:
The line num referred in the error message in the last line (end). Any idea what's causing this?
Apparently the problem was due to the GO statements I had in the files I was referencing. Having GO statements inside if else block is invalid. Here is an article explaining that. I was able to get it work by removing all GO statements from the referenced files and by splitting if else to two if.
IF ('$(env)' = 'dvp')
BEGIN
:R .\SecurityAdditions\UsersDVP.sql
END
IF ('$(env)' = 'qat')
BEGIN
:R .\SecurityAdditions\UsersQAT.sql
END
GO
I had this same error because I forgot to end one of the scripts being included in the post deployment script with a GO statement. What makes it hard fix is that the error will point to the first line in the next script instead of the script where the GO statement is missing.
I ran into this issue while I was trying to create database users in a SQL Database project. Setting the build action to None is no use because then your script doesn't run during the deployment.
I was using a script like this to create the users:
IF NOT EXISTS (SELECT * FROM sys.sysusers WHERE name='$(DbUserName)')
BEGIN
CREATE USER [$(DbUserName)] WITH PASSWORD = '$(DbPassword)';
ALTER ROLE [db_owner] ADD MEMBER [$(DbUserName)];
END
I had two SQLCMD variables in the project file and setting a default value for one of them actually resolved the issue. It's really weird but I hope this helps some poor soul one day :)
I would like to share my experience here.
I got same error building my sql project but scenario was different and tricky.
I introduced new column in one of my database table and I needed to populate that column for already existing rows in that table. So basically it should be one time process and hence I decided to create post deployment script to do that. This post deployment script
began with IF condition to make sure it run only once for a given database. Please note this does not allow GO statement.
then Create Function to create temporary function. This needs GO statement before Create Function mainly because it makes changes in database schema. This was tricky because IF does not allow GO statement.
then Update query using temp function to achieve my requirement. This is fine without GO statement
then DROP FUNCTION to remove temporary function. This is also database schema change and ideally needs GO statement.
To handle this situation without any GO statement
I created a variable let's say '#CreateFuntion NAVARCHAR(MAX)' and set it with whole Create Function statement.
Executed Create Function using "EXEC sp_executesql #CreateFunction". This runs Create Function in separate batch. I was expecting Drop Function will need same treatment but in my case it worked without GO and "EXEC sp_executesql" may be because it was last statement in the script and would anyway run in next batch.
Everything else as it is
Another reason this could happen is if a post deployment script has a BEGIN statement without a corresponding END line. In such a case, any subsequent GO in anther future script will cause this error. I stumbled across this due to my own absent-mindedness when editing one of the post-deployment scripts.
Would anyone know of a way to dynamically increment an integer for item titles? This is mainly to avoid having to change every step number in the event that a new step would need to be added/removed somewhere in the middle of a ton of steps. Below is a small three-step procedure to give you a rough idea of the template structure:
=step_wash 1. Wash
<p>Add washing steps here</p>
=cut
# Throw some perl code here to wash stuff
=step_dry 2. Dry
<p>Add drying steps here</p>
=cut
# Throw some perl code here to dry things
=step_fold 3. Fold
<p>Add folding steps here</p>
=cut
# Fold all of the things Perl!
Disregarding the item names and structure of this, the goal is to try and eliminate the use of statically numbering the title of each item. I am wondering if there is a possible way to generate an integer that increments; pretty much like replacing 1, 2, 3, etc with something like { print $i++ } instead.. but in POD.
POD is pretty Plain and doesn't do that sort of thing.
An extension of POD called PseudoPod in theory does (see https://metacpan.org/pod/distribution/Pod-PseudoPod/lib/Pod/PseudoPod/Tutorial.pod#Lists) but when I tried it it gave an error.
There is nothing built into POD that allows doing automatic numbering.
I see that you are using custom POD regions which encompass HTML markup, your POD also doesn't look like normal documentation. If you are trying to do Literate Programming, there should exist systems that don't require you to write POD. If this is just normal documentation, you should probably remove the HTML, as docs are often viewed via perldoc – on the command line.
Sometimes it isn't neccessary to use numbering at all. Bullet points • are pretty as well.
I am using JRules to author business rules. I want to add comments to the rules as shown in the very simple example below. I realise there is a documentation section for the rule but that is not what I require
// comments needed here
definitions
set 'an existing customer' to a customer
where the category of 'an existing customer' is "gold"
if
the city of 'an existing customer' is "London"
then
give a 5% discount to 'an existing customer'
else
// and more comments needed here
give a 10% discount to 'an existing customer'
Clearly, using the usual c++ and c# double forwardslash // will not work in the example above, so my question is how are comments added to rules in BAL.
Unfortunately you cannot add comments in rules. The rules are supposed to be self explanatory if the verbalization is good.
But you can use the documentation feature,if you want to document the business justification for each of the rules.
There is a simple workaround:
You can create 2 static virtual methods in your BOM: one commenting the conditions and one for the actions.
In the case of conditions:
Create a static method that takes a parameter String and return a boolean
Verbalize it like this "// {0}" (without quotes)
In the B2X, make it return true
Then, you can comment a condition with //"your_condition" and ...
In the previous example:
if
the city of 'an existing customer' is "London" and
// "blablabla" and
the age of 'an existing customer' is greater than 18
then ...
Since the method returns true, it won't affect the test. It has to be surrounded by "and", not "or".
In the case of actions:
Create a static method that takes a parameter String and return void
Verbalize it like this "// {0}" (without quotes)
In the B2X, add "return;"
Then, you can comment an action with //"your_action" ;
In the previous example:
else
// "and more comments needed here" ;
give a 10% discount to 'an existing customer' ;
You can do it but it means a hell lot of customization. So forget it
And it would be feasible only via browser interface, not Eclipse.
Just because you will be cheating.
How to do it:
Ready?... Steady?...
You need to recreate your own RTS (teamserver) web interface! if it sounds like too much effort then stop reading :)
Using the API, you can retrieve the rules from RTS (database) the there is (as mention in Tito's answer) a documentation attached to any rule.
So you can handle the display of your rule and add the comment accordingly.
Of course you need to find a way to position the comment correctly in the rule Line number could do the trick.
This is for the display...
Ten when you save the rule (by clicking a lovely button that you will have coded to do the actual saving) you need to remove the comments (and know where they are for the next time you want to display the rule) and save both the rule body and the documentation attached.
Sounds crazy? One client done it and I was working on this :) but we didn't modify the rule body. Almost everything but the rule body.
This will take you months, inpependently to the number of people working on it, I'm afraid.
To sum up: Can you do it, yes!
Does the implementation worth the effort? NO WAY!!!
Will this feature be available in the next version? NO! As Tito mentioned a rule should be self-explainatory.
Sorry :(