Python execution via the Polyglot API always needs full System IO access - graalvm

I am trying to execute some very straightforward piece of python code via the polyglot API. When trying to run even simple tests such as the following:
#Test
public void printSomTextPythonTest() throws ScriptExecutionException, IOException {
String code = "print('Python will print this to the console!')";
String[] supportedLangs = { "js", "python", "R" };
Context testContext = Context.newBuilder(supportedLangs)
.allowAllAccess(false)
.allowHostAccess(false)
.allowHostClassLoading(false)
.allowIO(false)
.allowNativeAccess(false)
.allowCreateThread(false)
.build();
Source source = Source.newBuilder("python", code, "pyScript").build();
Value result = testContext.eval(source);
testContext.close();
}
Or:
#Test
public void setAVariablePythonTest() throws ScriptExecutionException, IOException {
String code = "someNumber = 11";
String[] supportedLangs = { "js", "python", "R" };
Context testContext = Context.newBuilder(supportedLangs)
.allowAllAccess(false)
.allowHostAccess(false)
.allowHostClassLoading(false)
.allowIO(false)
.allowNativeAccess(false)
.allowCreateThread(false)
.build();
Source source = Source.newBuilder("python", code, "pyScript").build();
Value result = testContext.eval(source);
testContext.close();
}
I get this error (stack trace below):
org.graalvm.polyglot.PolyglotException: java.lang.SecurityException: Operation is not allowed for: /code/polyglot-test
If I change allowIO to true when building the Context, the code runs fine and gives the expected result. I have also tried it with more complex code with the same results.
Why is IO access necessary for Python code to be executed?
Equivalent code written and executed in JS does not need the allowIO to be set to true, so it seems to me to be a Python specific thing.
Thanks for your help.
UPDATE
I have been testing with R as a guest language too. Running the following test:
#Test
public void helloWorldRTest() throws ScriptExecutionException, IOException {
String code = "print(\"R will print this to the console!\")";
String[] supportedLangs = { "js", "python", "R" };
Context testContext = Context.newBuilder(supportedLangs)
.allowAllAccess(false)
.allowHostAccess(false)
.allowHostClassLoading(false)
.allowIO(false)
.allowNativeAccess(false)
.allowCreateThread(false)
.build();
Source source = Source.newBuilder("R", code, "rScript").build();
Value result = testContext.eval(source);
testContext.close();
}
I get the following error:
FastR unexpected failure: error loading libR from: /Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/R/lib/libR.dylib.
If running on the NFI backend, did you provide the location of libtrufflenfi.so as the value of the system property 'truffle.nfi.library'?
The current value is 'null'.
Is the OpenMP runtime library (libgomp.so) present on your system? This library is, e.g., typically part of the GCC package.
Details: Access to native code is not allowed by the host environment.
However, by setting "allowNativeAccess" to true, the code runs fine without errors.
Do different languages need different types of access priviliges to run?
In my use case I am trying to sandbox the execution as much as possible. I want the scripts, regardless of the language they are written in to only have access to the data that is given to them.
Scripts running in the guest languages should not have any access to the host system. Is this achievable?
Partial stack trace (if needed for debugging I can supply the full stack trace):
org.graalvm.polyglot.PolyglotException: java.lang.SecurityException: Operation is not allowed for: /code/polyglot-test
at com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.forbidden(FileSystems.java:489)
at com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.checkAccess(FileSystems.java:367)
at com.oracle.truffle.api.TruffleFile.checkAccess(TruffleFile.java:983)
at com.oracle.truffle.api.TruffleFile.exists(TruffleFile.java:102)
at com.oracle.graal.python.builtins.modules.PosixModuleBuiltins$StatNode.stat(PosixModuleBuiltins.java:404)
at com.oracle.graal.python.builtins.modules.PosixModuleBuiltins$StatNode.doStat(PosixModuleBuiltins.java:397)
at com.oracle.graal.python.builtins.modules.PosixModuleBuiltinsFactory$StatNodeFactory$StatNodeGen.executeAndSpecialize(PosixModuleBuiltinsFactory.java:855)
at com.oracle.graal.python.builtins.modules.PosixModuleBuiltinsFactory$StatNodeFactory$StatNodeGen.execute(PosixModuleBuiltinsFactory.java:807)
at com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode$BuiltinBinaryCallNode.execute(BuiltinFunctionRootNode.java:103)
at com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode.execute(BuiltinFunctionRootNode.java:229)
at stat(Unknown)
at stat(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-graalpython/posix.py:51:2230-2247)
at _path_stat(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap_external.py:82:2759-2772)
at _path_is_mode_type(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap_external.py:88:2901-2916)
at _path_isdir(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap_external.py:103:3245-3278)
at path_hook_for_FileFinder(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap_external.py:1333:50397-50413)
at PathFinder._path_hooks(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap_external.py:1083:40517-40526)
at PathFinder._path_importer_cache(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap_external.py:1107:41279-41299)
at PathFinder._get_spec(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap_external.py:1135:42391-42421)
at PathFinder.find_spec(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap_external.py:1166:43686-43722)
at _find_spec(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap.py:892:28932-28960)
at _find_and_load_unlocked(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap.py:953:31192-31213)
at _find_and_load(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap.py:968:31701-31738)
at _gcd_import(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap.py:985:32285-32317)
at import(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap.py:1066:35366-35382)
at (../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-graalpython/builtins_patches.py:48:2220-2224)
at org.graalvm.polyglot.Context.eval(Context.java:313)
at bolt.tests.BoltEngineGraalTest.helloWorldPythonTest(BoltEngineGraalTest.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Original Internal Error:
java.lang.SecurityException: Operation is not allowed for: /code/polyglot-test
at com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.forbidden(FileSystems.java:489)
at com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.checkAccess(FileSystems.java:367)
...

Related

QAF | Scenario needs to skip if dependent scenario gets fail

Team,
Problem statement: Scenario2 should skip if dependent scenario1 gets fail. Need some support to fix this issue.
Reference: I took reference from below link Skip Dependent scenario issue
Issue: End up with error after added #dependsOnMethods:['scenario1']
**Caused by: org.testng.TestNGException:
Method "scenarios.suite1.feature.scenario2()[pri:2, instance:com.qmetry.qaf.automation.step.client.Scenario#2]" depends on nonexistent method "scenario1"**
Example Feature file:
```Feature: Google Search
#priority:1`enter code here`
Scenario: Scenario1
Given COMMENT: "SC1"
And Call negative step
#priority:2 #dependsOnMethods:['scenario1']
Scenario: Scenario2
Given COMMENT: "SC2" ```
**I used same listener from the above link**
public class DependecyListener implements ITestListener {
#Override
public void onTestStart(ITestResult result) {
ITestNGMethod method = result.getMethod();
String[] methodsDependedUpon = method.getMethodsDependedUpon();
if (method.isTest() && null != methodsDependedUpon && methodsDependedUpon.length > 0) {
List<String> methodsDependedUponLst = Arrays.asList(methodsDependedUpon);
IResultMap failedTests = result.getTestContext().getFailedTests();
List<ITestResult> falildMethodsDependedUpon = failedTests.getAllResults().stream()
.filter(t -> methodsDependedUponLst.contains(t.getName())).collect(Collectors.toList());
if(!falildMethodsDependedUpon.isEmpty()) {
throw new SkipException("Skipped because of dependency failure!");
}
}
}
StepLibrary.Java
```#QAFTestStep(description = "Call negative step")
public static void iCallNegativeStep() {
System.out.println("Enter into Neg");
Assert.assertEquals(true, false,"Called Negative step" );
}```
Console Log:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
log4j:WARN No such property [follow] in org.apache.log4j.FileAppender.
Added "QAFMethodSelector"
[ConfigurationManager] - ISFW build info: {qaf-Type=core, qaf-Revision=0b, qaf-Build-Time=24-Oct-2021 19:53:30, qaf-Version=3.1}
[ConfigurationManager] - Resource dir: D:\Temp\DelDepIssue\qaf-blank-project-maven-master\resources. Found property files to load: 6
[ConfigurationManager] - Resource dir: D:\Temp\DelDepIssue\qaf-blank-project-maven-master\resources. Found property files to load: 0
include groups []
exclude groups: [] Scanarios location:
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104)
**at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70)
Caused by: org.testng.TestNGException:
Method "scenarios.suite1.feature.Scenario2()[pri:2, instance:com.qmetry.qaf.automation.step.client.Scenario#2]" depends on nonexistent method "scenario1"**
at org.testng.DependencyMap.getMethodDependingOn(DependencyMap.java:65)
at org.testng.TestRunner.createDynamicGraph(TestRunner.java:1041)
at org.testng.TestRunner.privateRun(TestRunner.java:723)
at org.testng.TestRunner.run(TestRunner.java:610)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:122)
at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:101)
9 more
Preparing For Shut Down...
[ResultUpdator] - Using QAF Json Reporter
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.142 s
[INFO] Finished at: 2022-03-08T00:09:40+05:30
[INFO] ------------------------------------------------------------------------
While specifying dependency, method name value need to be exact same including upper/lower case, it is case sensitive. In your case when providing method name in dependsOnMethods you didn't provided name in the same case. For instance, method name is Scenario1 and in dependsOnMethods it is provided scenario1, if you observer it is not equal considering case sensitivity. That's why it complains that depends on nonexistent method scenario1. You can correct as sample below:
Scenario: Scenario1
Given COMMENT: "SC1"
And Call negative step
#priority:2 #dependsOnMethods:['Scenario1']
Scenario: Scenario2

Jenkins Groovy error groovy.lang.MissingMethodException when trying to use readFile()

I've been getting an odd error in Jenkins when trying to run readFile() within a shared library, so that I can determine if a Dockerfile is pulling from ECR or docker hub. The error is :-
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.myorg.DockerManager.readFile() is applicable for argument types: (java.lang.String) values: [DockerServiceDescription/Dockerfile]
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
at org.proj.DockerManager.login(/tmp/persistence/jobs/PROJ/jobs/builds/jobs/proj-subproj/branches/PROJ-4190/builds/47/libs/Global/src/org/me/DockerManager.groovy:26)
The method that's triggering the error is :-
/**
Login to docker
*/
void login() {
dockerfileHandle = readFile(dockerfile)
dockerfileLines = dockerfileHandle.readLines()
def dockerfileFROM = dockerfileLines.find{ dockerfileLine-> dockerfileLine =~ /^FROM / }
println("FROM: " + dockerfileFROM)
if (dockerfileFROM =~ /\.ecr\./ ) {
println("Using ECR")
ecrlogin()
} else {
println("Using DOCKER HUB")
dockerhublogin()
}
}
however that same code worked perfectly well within the pipeline code, it just breaks when moved into a shared library.
Any ideas?
Access to pipeline steps is done via an instance of CPSScript that represents the running pipeline. To use it in a class of shared library, you have to pass this into your library, either as constructor or method argument:
/**
Login to docker
*/
void login(def script) { // actually CPSScript, but that way, no import is needed
dockerfileHandle = script.readFile(dockerfile)
//...
}
This from your actual Jenkins file, you then call it like:
myInstance.login(this)
Also note that you println calls would result in output in the Jenkins logs, not the build logs, what you are aiming for is script.echo()

Can not use Groovy collections with closures in Jenkinsfile script

I want to use groovy closures with collections in Jenkinsfile:
// other parts removed for brevity
steps {
script {
def testList = ["item1", "item2", "item3"]
testList.stream().map{it+".jpeg"}.each{println it}
}
}
// other parts removed for brevity
However, it gives error:
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.util.stream.ReferencePipeline$Head.map() is applicable for argument types: (org.jenkinsci.plugins.workflow.cps.CpsClosure2) values: [org.jenkinsci.plugins.workflow.cps.CpsClosure2#248ba046]
Possible solutions: map(java.util.function.Function), max(java.util.Comparator), min(java.util.Comparator), wait(), dump(), grep()
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:153)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
at WorkflowScript.run(WorkflowScript:49)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
...
I am fighting the same problem--constructs in Groovy which I use all the time, like all the handy collection methods, are breaking.
It turns out that in a Jenkinsfile, the code is passed through a transformer called Groovy CPS which enables Jenkins to stop and restart execution of a stage. In the process, stuff gets changed from its original class, and this causes the kind of error you're seeing here, because you're mixing non-CPS code (the Java lib methods) with CPS code (anything inside the Jenkinsfile).
Here's the link to the documentation of this behavior...but I didn't find it very helpful, so I am reverting to doing stuff like I would in Java (pre-lambda) with lots of for loops :(
While it’s not as handy as locally defined closures, you can, in some cases, define methods in the global scope and then rely on them via the Groovy method pointer operator.
void doSomething(final String key, final String value) {
println "${key} → ${value}"
}
pipeline {
stages {
stage('Process data') {
steps {
script {
final Map myData = [
"foo": "bar",
"plop": "yo",
]
myData.each(this.&doSomething)
}
}
}
}
}

com.qmetry.qaf.automation.step.client.ScenarioFactory.getTestsFromFile() threw an exception

Followed steps outlined here: https://qmetry.github.io/qaf/qaf-2.1.14/gherkin_client.html
<test name="Gherkin-QAF-Test">
<parameter name="step.provider.pkg" value="com.cucumber.steps" />
<parameter name="scenario.file.loc" value="resources/features/component/test/smoke.feature" />
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
Added feature file:
#Web
Feature: Google Search
#Smoke
Scenario: Search InfoStrech
Given I am on Google Search Page
When I search for "git qmetry"
Then I get at least 5 results
And it should have "QMetry Automation Framework" in search results
Added steps in java
#QAFTestStep(description = "I am on Google Search Page")
public void step1() {
System.out.println("I am on Google Search Page");
}
#QAFTestStep(description = "I search for {0}")
public void iSearchFor(String s) {
System.out.println("I search for " + s);
}
#QAFTestStep(description="I get at least {num} results")
public void iGet_inSearchResults(Integer n) {
System.out.printf("I get at least %d results\n", n);
}
#QAFTestStep(description="it should have {0} in search results")
public void itShouldHave_inSearchResults(String s) {
System.out.printf("it should have %s in search results\n", s);
}
Ran xml file as TestNG, getting error below:
The factory method class com.qmetry.qaf.automation.step.client.ScenarioFactory.getTestsFromFile() threw an exception
org.testng.TestNGException:
The factory method class com.qmetry.qaf.automation.step.client.ScenarioFactory.getTestsFromFile() threw an exception
at org.testng.internal.FactoryMethod.invoke(FactoryMethod.java:197)
at org.testng.internal.TestNGClassFinder.processFactory(TestNGClassFinder.java:223)
at org.testng.internal.TestNGClassFinder.processMethod(TestNGClassFinder.java:179)
at org.testng.internal.TestNGClassFinder.processClass(TestNGClassFinder.java:171)
at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:121)
at org.testng.TestRunner.initMethods(TestRunner.java:370)
at org.testng.TestRunner.init(TestRunner.java:271)
at org.testng.TestRunner.init(TestRunner.java:241)
at org.testng.TestRunner.<init>(TestRunner.java:192)
at org.testng.remote.support.RemoteTestNG6_12$1.newTestRunner(RemoteTestNG6_12.java:33)
at org.testng.remote.support.RemoteTestNG6_12$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_12.java:66)
at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:713)
at org.testng.SuiteRunner.init(SuiteRunner.java:260)
at org.testng.SuiteRunner.<init>(SuiteRunner.java:198)
at org.testng.TestNG.createSuiteRunner(TestNG.java:1295)
at org.testng.TestNG.createSuiteRunners(TestNG.java:1273)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.IllegalArgumentException: wrong number of arguments
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.FactoryMethod.invoke(FactoryMethod.java:167)
... 21 more
something else I've noticed. After an update to "Scenario" in feature file next to each line of conditions I see warning with text:
Step '********' does not have a matching glue code
To answer original question, easiest way is to start using maven template or ANT template.
Regarding your question in comment, of using testng annotations, when using BDD you can move that code into respective testng listener. For example, method with Before/AfterSuite annotation can be moved to Suite listener and Before/AfterMethod can be moved to Method Invocation listener.
When you are using QAF you may not required much of the code for driver management because qaf provides inbuilt feature of thread safe driver and resource management. You can take benefit of that with driver and element listeners and locator repository features. It is highly configurable, for example you can set property selenium.singletone to specify driver instance scope. Possible value can be Tests (testng xml test) or Methods (test mtehod) or Groups.

what is the jenkins job-dsl snippet for generating allure report in freestylejob

I am trying to generate job using jenkins JOB-DSL and i am unable to find a way to trigger allure report as publisher in freestylejob
job('ci') {
publishers {
allure([includeProperties: false, jdk: '', results: [[path: 'Result']]])
}
}
I even tried to search on https://jenkinsci.github.io/job-dsl-plugin also tried on https://job-dsl.herokuapp.com/ for getting this work. but no luck.
But getting the following error:
javaposse.jobdsl.dsl.DslScriptException: (script, line 5) No signature of
method: javaposse.jobdsl.dsl.helpers.publisher.PublisherContext.allure()
is applicable for argument types: (java.util.LinkedHashMap) values:
[[includeProperties:false, jdk:, results:[[path:Result]]]]
Possible solutions: mailer(java.lang.String), use([Ljava.lang.Object;),
asType(java.lang.Class)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScriptEngine(AbstractDslScriptLoader.groovy:112)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader$_runScripts_closure1.doCall(AbstractDslScriptLoader.groovy:59)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScripts(AbstractDslScriptLoader.groovy:46)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader$runScripts$0.callCurrent(Unknown Source)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScript(AbstractDslScriptLoader.groovy:85)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader$runScript.call(Unknown Source)
at com.sheehan.jobdsl.DslScriptExecutor.execute(DslScriptExecutor.groovy:27)
at com.sheehan.jobdsl.ScriptExecutor$execute.call(Unknown Source)
at Ratpack$_run_closure1$_closure3$_closure7$_closure8.doCall(Ratpack.groovy:32)
at com.sun.proxy.$Proxy10.execute(Unknown Source)
at ratpack.exec.internal.DefaultPromise$1.success(DefaultPromise.java:42)
at ratpack.exec.Promise.lambda$null$9(Promise.java:304)
at ratpack.exec.Downstream$1.success(Downstream.java:73)
at ratpack.exec.Promise.lambda$null$9(Promise.java:304)
at ratpack.exec.Downstream$1.success(Downstream.java:73)
at ratpack.exec.internal.DefaultExecution$2.lambda$success$1(DefaultExecution.java:161)
at ratpack.exec.internal.DefaultExecution$SingleEventExecStream.exec(DefaultExecution.java:419)
at ratpack.exec.internal.DefaultExecution.exec(DefaultExecution.java:246)
at ratpack.exec.internal.DefaultExecution.intercept(DefaultExecution.java:240)
at ratpack.exec.internal.DefaultExecution.drain(DefaultExecution.java:220)
at ratpack.exec.internal.DefaultExecution.access$100(DefaultExecution.java:45)
at ratpack.exec.internal.DefaultExecution$SingleEventExecStream.resume(DefaultExecution.java:452)
at ratpack.exec.internal.DefaultExecution$2.success(DefaultExecution.java:161)
at ratpack.server.internal.RequestBody.complete(RequestBody.java:125)
at ratpack.server.internal.RequestBody.add(RequestBody.java:76)
at ratpack.server.internal.NettyHandlerAdapter.channelRead(NettyHandlerAdapter.java:84)
at io.netty.channel.ChannelHandlerInvokerUtil.invokeChannelReadNow(ChannelHandlerInvokerUtil.java:83)
at io.netty.channel.DefaultChannelHandlerInvoker.invokeChannelRead(DefaultChannelHandlerInvoker.java:163)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:155)
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
at io.netty.channel.ChannelHandlerInvokerUtil.invokeChannelReadNow(ChannelHandlerInvokerUtil.java:83)
at io.netty.channel.DefaultChannelHandlerInvoker.invokeChannelRead(DefaultChannelHandlerInvoker.java:163)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:155)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
at io.netty.channel.ChannelHandlerInvokerUtil.invokeChannelReadNow(ChannelHandlerInvokerUtil.java:83)
at io.netty.channel.DefaultChannelHandlerInvoker.invokeChannelRead(DefaultChannelHandlerInvoker.java:163)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:155)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:276)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:263)
at io.netty.channel.ChannelHandlerInvokerUtil.invokeChannelReadNow(ChannelHandlerInvokerUtil.java:83)
at io.netty.channel.DefaultChannelHandlerInvoker.invokeChannelRead(DefaultChannelHandlerInvoker.java:163)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:155)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:950)
at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:818)
at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:338)
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:254)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742)
at ratpack.exec.internal.DefaultExecController$ExecControllerBindingThreadFactory.lambda$newThread$0(DefaultExecController.java:113)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
Caused by: groovy.lang.MissingMethodException: No signature of method: javaposse.jobdsl.dsl.helpers.publisher.PublisherContext.allure() is applicable for argument types: (java.util.LinkedHashMap) values: [[includeProperties:false, jdk:, results:[[path:Result]]]]
Possible solutions: mailer(java.lang.String), use([Ljava.lang.Object;), asType(java.lang.Class)
at javaposse.jobdsl.dsl.AbstractExtensibleContext.methodMissing(AbstractExtensibleContext.groovy:19)
at javaposse.jobdsl.dsl.AbstractContext.invokeMethod(AbstractContext.groovy)
at script$_run_closure1$_closure2.doCall(script:5)
at script$_run_closure1$_closure2.doCall(script)
at javaposse.jobdsl.dsl.ContextHelper.executeInContext(ContextHelper.groovy:16)
at javaposse.jobdsl.dsl.ContextHelper$executeInContext.call(Unknown Source)
at javaposse.jobdsl.dsl.ContextHelper$executeInContext.call(Unknown Source)
at javaposse.jobdsl.dsl.Job.publishers(Job.groovy:628)
at script$_run_closure1.doCall(script:3)
at javaposse.jobdsl.dsl.JobParent.processItem(JobParent.groovy:104)
at javaposse.jobdsl.dsl.JobParent.freeStyleJob(JobParent.groovy:46)
at javaposse.jobdsl.dsl.JobParent$freeStyleJob$0.callCurrent(Unknown Source)
at javaposse.jobdsl.dsl.JobParent$freeStyleJob$0.callCurrent(Unknown Source)
at javaposse.jobdsl.dsl.JobParent.job(JobParent.groovy:38)
at javaposse.jobdsl.dsl.DslFactory$job.callCurrent(Unknown Source)
at script.run(script:1)
at script$run.call(Unknown Source)
at script$run.call(Unknown Source)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScript(AbstractDslScriptLoader.groovy:132)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScriptEngine(AbstractDslScriptLoader.groovy:106)
... 49 more
Can some one give me any snippet for allure?
https://docs.qameta.io/allure/#_job_dsl_plugin
// default
publishers {
allure(['allure-results'])
}
// advanced
publishers {
allure(['first-results', 'second-results']) {
jdk('java7')
commandline('1.4.18')
buildFor('UNSTABLE')
includeProperties(true)
property('allure.issues.tracker.pattern', 'http://tracker.company.com/%s')
property('allure.tests.management.pattern', 'http://tms.company.com/%s')
}
}
I found it. i need to use the Dynamic DSL for this.
Note: this can not be tested in command line or playground. but it works on jenkins only.
here is the dynamic dsl for freestyle job with allure report configuration.
publisher {
allure {
results {
resultsConfig {
path('Result')
}
}
}
}
To be able to use Allure with the Job DSL I had to add the allure-jenkins-plugin to my build.gradle as follows:
dependencies {
testPlugins 'ru.yandex.qatools.allure:allure-jenkins-plugin:2.30.2'
}
Note: what can help is making sure Allure is available on your Jenkins, which you can check by going to https://url-of-your-jenkins.org/plugin/job-dsl/api-viewer/index.html and looking for "allure".
Hope this helps anyone who struggled with the error!

Resources