SoapUI print full URL path of rest request using groovy - rest

I'm using soapui with groovy script step
I want to print the full url of my REST request.
I tried using:
myFile.append( testRunner.testCase.testSteps["My Test Name"].getProperty( "requestUri" ));
and I got null.

You will not be able to see the request info from a test step groovy script. However, the groovy script assertion has access to that information.
You can use this to easily retrieve the full endpoint:
def endpoint = messageExchange.getEndpoint()

The below is working fine for me. you can use the same code just need to change your step name.
Note: Make sure your same Test step should have run prior to below code.else you will get the error
[Cannot invoke method getURL() on null object], see error log for details.
Working Code:
def tr=testRunner.testCase.getTestStepByName("TriggerRequestTransactionsReportsService_V)
def String endPointUrlSave= tr.getHttpRequest().getResponse().getURL();
log.info "Your EndpointUrl is : " + endPointUrlSave;

Related

Karate- Gatling: Not able to run scenarios based on tags

I am trying to run performance test on scenario tagged as perf from the below feature file-
#tag1 #tag2 #tag3
**background:**
user login
#tag4 #perf
**scenario1:**
#tag4
**scenario2:**
Below is my .scala file setup-
class PerfTest extends Simulation {
val protocol = karateProtocol()
val getTags = scenario("Name goes here").exec(karateFeature("classpath:filepath"))
setUp(
getTags.inject(
atOnceUsers(1)
).protocols(protocol)
)
I have tried passing the tags from command line and as well as passing the tag as argument in exec method in scala setup.
Terminal command-
mvn clean test-compile gatling:test "-Dkarate.env={env}" "-Dkarate.options= --tags #perf"
.scala update:- I have also tried passing the tag as an argument in the karate execute.
val getTags = scenario("Name goes here").exec(karateFeature("classpath:filepath", "#perf"))
Both scenarios are being executed with either approach. Any pointers how i can force only the test with tag perf to run?
I wanted to share the finding here. I realized it is working fine when i am passing the tag info in .scala file.
My scenario with perf tag was a combination of GET and POST call as i needed some data from GET call to pass in POST call. That's why i was seeing both calls when running performance test.
I did not find any reference in karate gatling documentation for passing tags in terminal execution command. So i am assuming that might not be a valid case.

Print console errors (with response code 4xx or 5xx) in logger file in protractor automation

I want to print console error with response code 4xx or 5xx in a logger file while executing automation script in protractor. Now I am using the following code in my afterEach. It prints everything from the console.
browser.manage().logs().get('browser').then(function(browserLog) {
console.log('log: ' + require('util').inspect(browserLog));
});
Thr protractor tests, are executed over node, so you can use node's file system ('fs' module) commands.
for example the appendFile methode
How to append to a file in Node?

Retrieve custom variable from a successful jenkins job run via REST api call

I would like to retrieve a custom variable from a successful last stable build jenkins job. I was able to retrieve the build number using curl on this link using Execute Shell. It's an internal server. https://jenkinsci.internalsvr/view/webapps/job/common-tools/lastStableBuild/buildNumber
Now, I'd like to do the same for a custom variable using curl. But I know that I may need to save the value of the custom variable but not sure how and to where.
So this is how I got it to work
I have this code in our dsl.groovy file
....
parameters {
stringParam('CUSTOM_VAR1', '', 'Custom Variable')
stringParam('CUSTOM_VAR2', '', 'Custom Variable')
}
shellCommands = sprintf('''#/bin/bash
echo "CUSTOM_VAR1=\${%s}" > env.properties
echo "CUSTOM_VAR2=\${%s}" >> env.properties
''', ['CUSTOM_VARIABLE1','CUSTOM_VARIABLE1'])
shell(shellCommands)
// This is extremely important
environmentVariables {
propertiesFile('env.properties')
}
// This allowed me to retrieve env.properties via http call from browser or curl.
publishers {
archiveArtifacts {
pattern('env.properties')
}
}
So if I need to access it, the http url should be formed like this
curl https://our-internal-server/job/theNameOfTheJob/lastStableBuild/artifact/env.properties
You can do it with the API of the EnvInject plugin, either with:
curl <jenkins-host>/job/<job_name>/<buildNumber>/injectedEnvVars/export
curl <jenkins-host>/job/<job_name>/<buildNumber>/injectedEnvVars/api/python
More info here.

Python Screen Scraper works within Eclipse, but not from command line

I'm writing a simple screen scraping script using python 2.7 with Eclipse PyDev. When running or debugging from within Eclipse everything works fine. However, when I run my program from the command line the server always returns a Response 500 error code. I've tried running the script and the compiled versions from the command line but get the same result -- Response 500. I've also tried some arbitrary things like adding a delay, repeated attempts, etc. but I do not know what Eclipse is doing that is different than python ran the command line.
First, where's a good place to start digging if I encounter something like this again?
Second, any ideas on how to get this working from the command line?
Code snippet below for reference
from requests import Request, Session
content_type = 'application/x-www-form-urlencoded'
headers2 = {"User-Agent" : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
"Content-Type" : content_type,
"Referer" : url
}
url = loginPage
payload = {"email" : username, "password" : password}
req = Request ('POST', url, data=payload, headers=headers2)
prepped = req.prepare()
s = Session()
resp = s.send(prepped)
print resp # Response 200 (good) from both within Eclipse and from cmd
resp = s.get(targetPage)
print resp # Response 200 (good) from Eclipse, Response 500 (generic web error) from cmd
s.get (logOutPage)
s.close()
Got an answer from somebody. Thanks go to user Justinsaccount from reddit.
First, I was using batch files to save typing and not directly using the command line.
Secondly, when printing out the parameters from inside the program and then comparing the eclipse version versus the .bat version, the .bat version was short a few characters which was the give away.
One of the parameters was a url that had a space character: http://somewhere.com/some page.
In strict URL, this turns into: http://somewhere.com/some%20page
When run from the command line http://somewhere.com/some%20page
works just fine. However, in a batch file the % needed to be escaped so what I got was: http://somewhere.com/some0page
which is why the server through an error -- that page didn't exist. What I needed to do was escape the % character: http://somewhere.com/some%%20page. After that change things worked just fine.

Calling Jmeter Functions from BeanShell Assertion Script

I am trying to run the jmeter test-suites in eclipse.
In my test-suite I am using a BeanShellAssertion to count the number of rows in a csv file.
I have a custom jmeter function to do so.
The script of the BeanShellAssertion is :
String str = "${__CustomFunction("Path to the CSV file")}";
int i = Integer.parseInt(str);
if(i ==0)
{
Failure = true;
FailureMessage = "Failed!";
}
return i;
This test-suite works fine when I run it using the jmeter on my local machine.
Only when I try to run it with eclipse, (using the jmeter maven plugin) I see the following error:
jmeter.util.BeanShellInterpreter: Error invoking bsh method:
eval Sourced file: inline evaluation of: `` String str =
"${__CustomFunction("FilePath")}"; int i = Integ . . . '' : Typed
variable declaration : Method Invocation Integer.parseInt
I am wondering if there's some other way to invoke the jmeter functions when executing it using eclipse cause I am sure that the function is correct as I mentioned before that it works fine when the test suite is run using the jmeter on my local machine.
Any help would be appreciated.
Thanks.
Are you sure your custom function jar is visible for the Maven Plugin ?
As when you run it from JMeter, it works , I suppose you have a jar in lib/ext.
So you need to make this jar available to the jmeter maven plugin.