Remove <!--Zero or more repetitions:--> from soap request - web-services

I'm trying to remove a comment message from a soap request.
I'm using SoapUI to do it, and I would like to remove this message and have a request page "clear" without comments.
The comment is <!--Zero or more repetitions:-->
How can I do it? Someone can help me? :)
Thanks

A possible way to do so is using regex as #TimBiegeleisen note in his comment. You can do it for example using a groovy. To illustrate what I'm telling in you can do something like:
def xml = '''
<foo>
<!-- some comment -->
<bar>data</bar>
<!--
multiline comment
multiline comment
-->
</foo>'''
println xml.replaceAll( "(?s)<!--.*?-->", "" )
In the SOAPUI context, you've to add a Groovy Script testStep. There get the testStep by name, read the request, remove the comments, and finally set the result as a request of your testStep again. Something like may works:
// get the testStep in your TestCase by name
def testStep = testRunner.testCase.getTestStepByName('TestStepName')
// get the request content
def request = testStep.getPropertyValue('request')
// remove comments
request = request.replaceAll( "(?s)<!--.*?-->", "" )
// update the request
testStep.setPropertyValue('request',request)
Hope it helps,

Related

postman render html response and execute JavaScript

I have an http api that give me html response, and I want to "preview" it.
But there is some javascript code in it, and without execute them, it won't give me the right page.
I currently manually copy & paste them in some aaa.html file and use chrome to open it(file://aaa.html), but I want to simplified those steps.
Is there anyway to do that in postman? or is there any postman alternative can do that?
There is an alternative to do this in Postman itself. You will have to use pm.visualizer. Just open your API request which is giving you the HTML response. Then go to the Test tab, add the lines below, and then click on the Visualize tab:
// save your html response in the template and then
const template = pm.response.text();
// set that template to pm.visualizer
pm.visualizer.set(template);
From Postman official documentation
Postman provides a programmable way to visually represent your request responses. Visualization code added to the Tests for a request will render in the Visualize tab for the response body, alongside the Pretty, Raw, and Preview options.
You need add to the Tests for a request:
var template = pm.response.text();
pm.visualizer.set(template);
and see result on the Visualize tab (after Pretty, Raw, and Preview options).
Postman result HTML with JS and CSS
To fix the error:
Refused to load the image 'file:///C:/some.png' because it violates the following Content Security Policy directive: "img-src http: https: data:".
if the content simply does not find (404 Not Found) it along a similar path 'file:///C:/some.file'
need to add the HTML tag to the section of the response body:
var response = pm.response.text();
var base = '<base href="https://some.domain/">";
var template = response.replace('<head>', '<head>' + base);
pm.visualizer.set(template);
this answer also solves the question in this comment.
For more information:
Postman Visualizing responses
HTML <base> tag in MDN Web Docs

Why do browsers omit XML tags?

(Better title, anyone?) Rendering some XML made with lxml.builder using a small Flask app in Python 3.6. The function makeXML in module mkX builds and returns the XML like so:
from lxml import etree as ET
...
def makeXML():
...
# myxml is type <class 'lxml.etree._Element'>
f = ET.tostring(myxml, method='xml', xml_declaration=True, encoding='utf-8', pretty_print=True)
return f
Where method=xml could be omitted, as it's the default. The Flask app does:
#app.route('/getXML')
def getXML():
xml = mkX.makeXML()
print(type(xml)) # xml is type <class 'bytes'>
return xml
When I go to [myurl]/getXML in Chrome or Firefox, I see this:
eggs bacon sausage spam
It omits the XML tags. Why does that happen? Hitting view source, I see this:
<?xml version='1.0' encoding='utf-8'?>
<someXML>
<reclist>
<dat>eggs</dat>
<dat>bacon</dat>
<dat>sausage</dat>
<dat>spam</dat>
</reclist>
</someXML>
With pretty_print=True it's nicely formatted. Without it:
<?xml version='1.0' encoding='utf-8'?>
<someXML><reclist><dat>eggs</dat><dat>bacon</dat><dat>sausage</dat><dat>spam</dat></reclist></someXML>
Looking at other webservices that return XML, the browser does not omit the XML tags, for example this one.
Does this mean that myxml isn't valid XML? If so, what's the difference & how should I fix it?
A browser renders HTML, not XML. Most browser try to show what's possible from a document. In your case they show you all text nodes but not the XML elements that have no meaning in HTML.
Check if the HTTP response includes a line saying
Content-Type: application/xml
Only if this is set can the browser decide to display the XML document.
As you can see when you open the source view, the XML is complete. Everything works as it is supposed to do.
For completeness' sake, in addition to Lutz Horn's answer, this is how to set Flask to return a specific mimetype:
...
from flask import Response
...
def getXML():
xml = mkX.makeXML()
return Response(xml, mimetype='application/xml')
Since the xml is records rather than text, 'application/xml' is preferable over 'text/xml', more info here.

Post data to website using Python requests library

I'm trying to make a simple webscaper using Python and the requests library.
r=requests.get(https://nustar.newcastle.edu.au/psp/CS9PRD/EMPLOYEE/HRMS/c/MANAGE_ACADEMIC_RECORDS.STDNT_ACTIVATION.GBL?FolderPath=PORTAL_ROOT_OBJECT.HCSR_RECORDS_AND_REGISTRATION.HCSR_STUDENT_TERM_INFORMATION.HC_STDNT_ACTIVATION_GBL&IsFolder=false&IgnoreParamTempl=FolderPath%2cIsFolder
I would like to POST a search input into this URL, but I'm struggling to work out how.
This is the search box code from the website:
<input id="STDNT_SRCH_EMPLID" class="PSEDITBOX" type="text" maxlength="11" style="width:140px; " value="" tabindex="13" name="STDNT_SRCH_EMPLID"></input>
I assume I have to somehow change value = "" to value = "foo".
Any help will appreciated, thanks.
See request's quick start here.
import requests
value1='foo'
payload = {'STDNT_SRCH_EMPLID': value1} # 'key2': 'value2' and so on (comma delimited)
r = requests.post("http://yourUrl.org/", data=payload)
print(r.text)
Do a network analysis in the developer tool of your browser and copy the curl command of the POST package.
Then you surf to [curl.trillworks.com][1] and convert the curl command by pasting it into a Python POST request.
Inside of your python request you can modify the values.

Testing for links in a page content in Django

Good day!
So going to my question,
I have a template with some links and I want to assert that they are indeed there in my page.
My html section,
<section>
<p>Welcome to open radio. We help you get on air!</p>
<p>Login</p>
<p>View all our stations</p>
<p>SignUp!</p>
</section>
My test now,
response = self.client.get(reverse("home"))
assert reverse("userlogin") in response.content
assert reverse("liststations") in response.content
assert reverse("userregistration") in response.content
My test passes and I understand I am not really asserting for the links here but rather for the strings of URLs. How may I test for links specifically?
Django's own test suite uses this to assert a certain url is in the response:
response = self.client.get(reverse("home"))
self.assertContains(response, 'Login' % reverse("userlogin"), html=True)
...
self.assertContains handles both the fact that response is a response object, and that both sides are html and only have to be equivalent, not necessarily equal.
This is assuming you're using (a subclass of) django.test.SimpleTestCase.

How to properly use xpath & regexp extractor in jmeter?

I have the following text in the HTML response:
<input type="hidden" name="test" value="testValue">
I need to extract the value from the above input tag.
I've tried both regexp and xpath extractor, but neither is working for me:
regexp pattern
input\s*type="hidden"\s*name="test"\s*value="(.+)"\s*>
xpath query
//input[#name="test"]/#value
The above xpath gives an error at the Xpath Assertion Listener .. "No node matched".
I tried a lot and concluded that the xpath works only if I use it as //input[#name].
At the moment I'm trying to add an actual name it gives the error .. "No node matched".
Could anyone please suggest me how to resolve the above issue?
Please take a look at my previous answer :
https://stackoverflow.com/a/11452267/169277
The relevant part for you would be step 3:
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Element;
String html = prev.getResponseDataAsString(); // get response from your sampler
Document doc = Jsoup.parse(html);
Element inputElement = doc.select("input[name=test]").first();
String inputValue = inputElement.attr("value");
vars.put("inputTextValue", inputValue);
Update
So you don't get tangled with the code I've created jMeter post processor called Html Extractor here is the github url :
https://github.com/c0mrade/Html-Extractor
Since you are using XPath Extractor to parse HTML (not XML) response ensure that Use Tidy (tolerant parser) option is CHECKED (in XPath Extractor's control panel).
Your xpath query looks fine, check the option mentioned above and try again.