Is it possible to disable one of the valueSource in a parameterizedTest? - junit5

I am using JUnit 5 and I have a test case like this:
#ParameterizedTest
#ValueSource(Strings = {a , b , c})
void example(String letter){
// do something
}
the c case is unhandled for now, so is it possible to use #Disabled to ignore only the c case not the whole test suite?
Or maybe suggest another way to take c case out of my smoke tests.

I think we can't disable a particular value in ParameterizedTest simply remove the value and run

Related

WaitFor 2 different results in Karate tests

We have a component which takes more time to build and we want to test it with Karate:
retry(120, 1000).waitForText('h1', 'Successful')
There can be more states in the h1 element (Waiting, Building), but error is usually shown almost immediately. How can we put waitForText to the condition and diferenciace between these 2 final states? Something like this
retry(120, 1000).if (waitForText('h1', 'Successful')) { ...continue with tests } elseif(waitForText('h1', 'Error')) { karate.fail('Error occured') }
Please read the docs for optional() and exists(): https://github.com/intuit/karate/tree/master/karate-core#optional
Also it is quite likely waitForAny() will solve this: https://github.com/intuit/karate/tree/master/karate-core#waitforany
* retry(120, 1000).waitForAny('{h1}Successful', '{h1}Error')
* if exists('{h1}Error') karate.fail('error occurred')
The first line above will actually return the Element so you can be smarter on the second line. There are many options, find the way that suits you best.

How to make a # test annotation out of data provider loop?

I have a data provider with name "name" and to the #Test I am passing this.
#DataProvider(name = "TC_001")
#Test(dataProvider = "TC_001")
before this #Test I want to run another #Test which need to run only once .
I have given the priority like
#Test(priority=0)
#DataProvider(name = "TC_001")
#Test(dataProvider = "TC_001",priority=1)
But Still the control goes to the second priority instead of first one
Is there any solution for this ?
I set the priority 1 and 2. #Test(priority=1) #DataProvider(name = "TC_001") #Test(dataProvider = "TC_001",priority=2) But Still the control goes to the second priority instead of first one.
Setting a value of priority=0 is as good as you not setting any priority at all.
TestNG honors priorities only when they are non negative positive numbers.
To fix your problem you have two options.
Start with a priority of 1 and have your data driven test method use a priority of 2 (or)
Have your data driven test method depend on the other test method using dependsOnMethod attributes.

Cucumber Ordered Tagged Hooks

I am trying to use an ordered, tagged hook using Java cucumber. For example:
#Before("#quicklink", order = 20)
The compiler doesn't seem to like it. Is it not possible to have an ordered, tagged hook ? Seems like a reasonable combination of functionality. If so, what is the syntax ?
thnx
I have tried the same but in a different way
#Before(value = "#quicklink", order = 20)
But, this may create odd issues if you have another hook method with the same order number for other tests. Like both the methods will run for this scenario.
So I suggest using the tagged expressions if you are using same order like as follows:
For other methods use
#Before(value = "~#quicklink", order = 20)
this will make sure this scenario will never run on other methods
and for this scenario alone,
#Before(value = "#quicklink", order = 20)
this will make sure the above method will never run for those.
If you are using 2x version of tagged expressions in your project, you can replace the '~' with a 'not'
This might come handy if you want to replace a method in hooks class in just a specific scenario.
#Before(value = "#quicklink", order = 20)
You should be able to specify the order for hooks like this:
Annotated method style (if you are using cucumber-java):
#Before(order = 10)
public void doSomething(){
// Do something before each scenario
}
Lambda style (if you are using cucumber-java8):
Before(10, () -> {
// Do something before each scenario
});

Same `where` clause for multiple tests

I know about data driven testing with the where clause in Spock.
But how can I expand this to use one where for multiple tests?
For example, I have I set of tests I want to run against different versions of a library:
#Unroll
def "test1 #firstlibVersion, #secondLibVersion"() {...}
#Unroll
def "test2 #firstlibVersion, #secondLibVersion"() {...}
...
The where clause might look like this:
where:
[firstlibVersion, secondLibVersion] <<
[['0.1', '0.2'], ['0.2', '0.4']].combinations()
I don't want to repeat this same where clause in every test. I could achieve that by reading environment variables in the tests and running the test suite multiple times with different env vars (test matrix style as CI services like travis support it).
But I would prefer to do that directly in the tests so I don't have to run the test suite multiple times. Does Spock support this somehow?
Might not be 100% possible, but you can put the right hand side in a method and annotate with #Shared. This would allow you to extract that piece of logic from each test.
For example:
myTest () {
#Shared combinations = getCombinations()
someTest() {
...
where:
[firstlibVersion, secondLibVersion] << combinations
}
def getCombinations() {
[['0.1', '0.2'], ['0.2', '0.4']].combinations()
}

How to access a stored value in PHPUnit_Extensions_SeleniumTestCase

How can I store a value within Selenium-RC (through PHPUnit) and then retrieve/access it later using PHPUnit?
Suppose I run a command like the following in a test:
$this->storeExpression( "foo", "bar" );
If I understand the Selenium API documentation correctly, I could access this data using javascript{storedVars['foo']} using good 'ol fashioned Selenese. It should contain the value "bar".
My question is this: how can I access this javascript{storedVars['test']} expression (or, more generally, javascript{storedVars} in PHPUnit?
For example, here's a simple test I've run:
public function testStorage()
{
$this->open('http://www.google.com/'); // for example
$this->storeExpression( 'foo', 'bar' );
$foo = $this->getExpression('foo');
echo $foo;
}
The output of which is "foo" (among the other standard PHPUnit output), while I expect it should be "bar". It's just giving me back the name of the expression, not its value.
Can anyone with experience in this give me some guidance?
Good posts in this thread, but looks like no 100% working answer so far.
Based on the Selenium reference here
http://release.seleniumhq.org/selenium-core/1.0/reference.html#storedVars
It would seem the correct code syntax would be:
$this->storeExpression( 'bar', 'foo' );
$foo = $this->getExpression("\${foo}");
I haven't tested that exactly, but doing something similar with
$this->storeHtmlSource('srcTxt');
$val = $this->getExpression('\${srcTxt}');
print $val;
did the trick for me.
The PHPUnit Selenium Testcase driver actually understands storeExpression and getExpression; have a look at its source code. You can do
$this->storeExpression('foo', 'bar');
and
$this->getExpression('foo');
As Selenium Stores the expression result in second argument it stores value in "bar" and when u need to call it you should call the stored name to get the expression.
$this->storeExpression( 'foo', 'bar' );
$foo = $this->getExpression("bar");
May this helps you it worked for me.
EDIT :
$evaluated = $this->getEval("regex:3+3");
$expressed = $this->getExpression("regex:3+3");
The First Evaluated will give the evaluated output for expression
and the second will show the expressed output.
The secound is used to verify that the specified expression is genrated or not by the alert.