I am looking for groovy script to add an wsdl to a project in SOAPUI dynamically at runtime using groovy scripts. i have tried the following code
import com.eviware.soapui.impl.wsdl.*
import com.eviware.soapui.impl.WsdlInterfaceFactory
project = new WsdlProject()
//wsdl = new WsdlInterfaceFactory()
project.setName("Project1");
WsdlInterface iface = WsdlInterfaceFactory.importWsdl(project, "C:\\Manoj\\BIAScalarReads\\IDSRequestLIB\\IDS_Request_MeterData.wsdl", true)[0];
No new project is getting loaded in the SOAPUI. Can anyone help on this?
You're creating a project, however then you don't add the project to the Workspace. To do so you must use the related method from Workspace class.
It possible to do so in a different ways. For example, create your project, save on disk and then load on the workspace in your groovy script testStep inside a testCase:
import com.eviware.soapui.impl.wsdl.*
import com.eviware.soapui.impl.WsdlInterfaceFactory
def project = new WsdlProject()
project.setName("Project1")
WsdlInterfaceFactory.importWsdl(project, 'path/to/yourWsdl', true)
// file to save the project
def projectFilePath = 'C:/temp/myProject.xml'
// save the project
project.saveAs(projectFilePath)
// load the project from disc to workspace
testRunner.testCase.testSuite.project.workspace.importProject(projectFilePath)
Another possible and more compact way to do the same is using workspace.createProject this way you avoid to save the disc and then import, to do it this way you can use the follow script:
import com.eviware.soapui.impl.wsdl.*
import com.eviware.soapui.impl.WsdlInterfaceFactory
def workspace = testRunner.testCase.testSuite.project.workspace
def project = workspace.createProject('Project2',new File('C:/temp/myProject.xml'))
WsdlInterfaceFactory.importWsdl(project, 'path/to/yourWsdl', true)
Hope this helps,
Related
I am doing PCA on CIFAR 10 image on IBM WATSON Studio Free version so I uploaded the python file for downloading the CIFAR10 on the studio
pic below.
But when I trying to import cache the following error is showing.
pic below-
After spending some time on google I find a solution but I can't understand it.
link
https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/add-script-to-notebook.html
the solution is as follows:-
Click the Add Data icon (Shows the Add Data icon), and then browse the script file or drag it into your notebook sidebar.
Click in an empty code cell in your notebook and then click the Insert to code link below the file. Take the returned string, and write to a file in the file system that comes with the runtime session.
To import the classes to access the methods in a script in your notebook, use the following command:
For Python:
from <python file name> import <class name>
I can't understand this line
` and write to a file in the file system that comes with the runtime session.``
Where can I find the file that comes with runtime session? Where is the file system located?
Can anyone plz help me in this with the details where to find that file
You have the import error because the script that you are trying to import is not available in your Python runtime's local filesystem. The files (cache.py, cifar10.py, etc.) that you uploaded are uploaded to the object storage bucket associated with the Watson Studio project. To use those files you need to make them available to the Python runtime for example by downloading the script to the runtimes local filesystem.
UPDATE: In the meanwhile there is an option to directly insert the StreamingBody objects. This will also have all the required credentials included. You can skip to writing it to a file in the local runtime filesystem section of this answer if you are using insert StreamingBody object option.
Or,
You can use the code snippet below to read the script in a StreamingBody object:
import types
import pandas as pd
from botocore.client import Config
import ibm_boto3
def __iter__(self): return 0
os_client= ibm_boto3.client(service_name='s3',
ibm_api_key_id='<IBM_API_KEY_ID>',
ibm_auth_endpoint="<IBM_AUTH_ENDPOINT>",
config=Config(signature_version='oauth'),
endpoint_url='<ENDPOINT>')
# Your data file was loaded into a botocore.response.StreamingBody object.
# Please read the documentation of ibm_boto3 and pandas to learn more about the possibilities to load the data.
# ibm_boto3 documentation: https://ibm.github.io/ibm-cos-sdk-python/
# pandas documentation: http://pandas.pydata.org/
streaming_body_1 = os_client.get_object(Bucket='<BUCKET>', Key='cifar.py')['Body']
# add missing __iter__ method, so pandas accepts body as file-like object
if not hasattr(streaming_body_1, "__iter__"): streaming_body_1.__iter__ = types.MethodType( __iter__, streaming_body_1 )
And then write it to a file in the local runtime filesystem.
f = open('cifar.py', 'wb')
f.write(streaming_body_1.read())
This opens a file with write access and calls the write method to write to the file. You should then be able to simply import the script.
import cifar
Note: You can get the credentials like IBM_API_KEY_ID for the file by clicking on the Insert credentials option on the drop-down menu for your file.
The instructions that op found miss one crucial line of code. I followed them and was able to import modules but wasn't able to use any functions or classes in those modules. This was fixed by closing the files after writing. This part in the instrucitons:
f = open('<myScript>.py', 'wb')
f.write(streaming_body_1.read())
should instead be (at least this works in my case):
f = open('<myScript>.py', 'wb')
f.write(streaming_body_1.read())
f.close()
Hopefully this helps someone.
I want to load a config value (something like json, yaml, xml or ini) from a jenkins pipeline script. When I try to use org.yaml.snakeyaml.Yaml I get
Scripts not permitted to use new org.yaml.snakeyaml.Yaml
I know I can unlock org.yaml.snakeyaml.Yam, but the message tells me that this does not seem to be the standard way of loading config files.
Is there a way of loading config files that is already unlocked?
If anyone looking for yaml parser in jenkinsfile, I recommend the following
def yamlData = readYaml file: 'cae.yaml'
Reference : https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#code-readyaml-code-read-yaml-from-files-in-the-workspace-or-text
Try using the JsonSlurper:
def config = new JsonSlurper().parse(new File("config.json"))
Based on this answer, I would like to iterate over all the properties in jenkins job and replace with their value in the job in build step.
e..g.
file = new File("folder/path/myfile.cs")
fileText = file.text;
fileText = fileText.replaceAll("parameter", "parametervalue");
file.write(fileText);
I saw an example to resolve one param like this:
build.buildVariableResolver.resolve("myparameter")
But I need
To iterate over all of them
To do it in Build step (after pulling from Source Code) so in the current build.
How can I do it?
The following is a sample groovy code that you can use with the scriptler plugin, that I suggest to use. This code can correctly read the Environment variables that are set in any Jenkins job:
import jenkins.model.Jenkins
def thr = Thread.currentThread()
def build = thr?.executable
def env = build.getEnvironment()
def buildNumber = env.get("BUILD_NUMBER")
In case you want to read the Build Parameters (you have a parameterized build and need access to those variables), you need to use the previous code and add the following:
def bparams = build.getBuildVariables()
def myBuildParam = bparams.get("MY_BUILD_PARAMETER")
after you read them, you can write them to your file, in a build step occurring after the git cloning.
I have a groovy script which reads the text from a file and returns it as a response
i have to read it as follows
text = new File("D:/text.xml")
now the problem is i'd like to use relative paths.. so i was wondering
If i just say
text = new File("text.xml")
Where does Soap UI / Groovy start searching for the file by default? This currently throws a "java.io.FileNotFoundException".
How do i change this so that it uses paths relative to the project.xml file?
This is how i finally solved my requirement
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def projectPath = groovyUtils.projectPath //gets the path of the project root
def response = new File(projectPath, "/test.xml").text;
Add
System.out.println(System.getProperty("user.dir"));
or
System.out.println(text.getAbsolutePath());
to your script to find out.
You can set the Resource Root Project Property in soapUI.
${projectDir} points to your project folder.
I'm having issues importing htmlunit (htmlunit.sf.net) into a groovy script.
I'm currently just using the example script that was on the web and it gives me unable to resolve class com.gargoylesoftware.htmlunit.WebClient
The script is:
import com.gargoylesoftware.htmlunit.WebClient
client = new WebClient()
html = client.getPage('http://www.msnbc.msn.com/')
println page.anchors.collect{ it.hrefAttribute }.sort().unique().join('\n')
I downloaded the source from the website and placed the com folder (and all its contents) where my script was located.
Does anyone know what issue I'm encountering? I'm not quite sure why it won't import it
You could use Grape to get the dependecy for you during script runtime. Easiest way to do it is to add a #Grab annotation to your import statement.
Like this:
#Grab('net.sourceforge.htmlunit:htmlunit:2.7')
import com.gargoylesoftware.htmlunit.WebClient
client = new WebClient()
// Added as HtmlUnit had problems with the JavaScript
client.javaScriptEnabled = false
html = client.getPage('http://www.msnbc.msn.com/')
println page.anchors.collect{ it.hrefAttribute }.sort().unique().join('\n')
There's only one problem. The page seems to be a little bit to much to chew off for HtmlUnit. When I ran the code I got OutOfMemoryException every time. I'd suggest downloading the html the normal way instead and then using something like NekoHtml or TagSoup to parse the html into XML and work with it that way.
This example uses TagSoup to work with html as xml in Groovy: http://blog.foosion.org/2008/06/09/parse-html-the-groovy-way/
you just need to download zip file, extract the jar file(s) and place them on the class path when compiling... You dont need the source
http://sourceforge.net/projects/htmlunit/files/htmlunit/2.8/htmlunit-2.8.zip/download