I am using Spock in combination with Geb for web browser testing.
I have created the "stepThrough" extension by following the instructions found here:
Spock Stepwise - Keep running testsuite after single failure
That works all fine and well, but I would like to make a new annotation. That sets a a geb feature method to "Mandatory" meaning that if this feature method fails I would like to stop execution of the rest of the test.
I like the stepThrough annotation because if one test case fails I can continue with the rest of my testing, but if something like login fails, then I would want to stop the testing because obviously nothing else would work if Login fails.
This is what I have so Far but it does not seem to be working. Where have I gone wrong?
Here is the Annotation class import org.spockframework.runtime.extension.ExtensionAnnotation
import java.lang.annotation.ElementType
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
import java.lang.annotation.Target
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@ExtensionAnnotation(ManditoryExtension.class)
@interface Manditory {}
Here is the extension:
class ManditoryExtension extends AbstractAnnotationDrivenExtension<Manditory>{
void visitFeatureAnnotation(Manditory annotation, FeatureInfo feature) {
skipFeaturesAfterFirstFailingFeature(feature)
}
private void skipFeaturesAfterFirstFailingFeature(final FeatureInfo feature){
feature.getParent().getBottomSpec().addListener(new AbstractRunListener() {
void error(ErrorInfo error) {
if (!error.getMethod().equals(feature)) return
for (FeatureInfo feat : feature.getSpec().getFeatures())
feat.setSkipped(true)
}
})
}
}