SyntaxError: cannot use absolute path on element? - xpath

I need identify a xpath in an xml file, but the robot show me this message
SyntaxError: cannot use absolute path on element
Code:
${RESULT}= Call Soap Method PersonalInformation ${list} #METODO DEL WEB SERVICE
#Set Global Variable ${RESULT}
${xml_result} = Get Last Received
${xml_unicode} = Decode Bytes To String ${xml_result} UTF-8
#${obj as str}= Convert To String ${xml_unicode}
#Log ${obj as str}
${root} = Parse XML ${xml_unicode}
${first} = Get Element ${root} //*[#id="collapsible2"]/div[1]/div[2]/div[1]/span[2]
Log ${first.text}
Im getting the xpath in google chrome, someone know the reason for this error?
greetings

Related

How to get the downloaded xlsx file from the api endpoint in karate?

I have an endpoint that downloads an xlsx file. In my test, I need to check the content of the file (not comparing the file with another file, but reading the content and checking). I am using karate framework for testing and I am trying to use apache POI for working with the excel sheet. However, the response I get from karate when calling the download endpoint is a String. For creating an excel file with POI I need an InputStream or the path to the actual file. I have tried the conversion, but it does not work.
I guess I am missing some connection here, or maybe the conversion is bad, I am new to karate and to the whole thing.
I appreciate any help, thanks!
Given url baseUrl
Given path downloadURI
When method GET
Then status 200
And match header Content-disposition contains 'attachment'
And match header Content-disposition contains 'example.xlsx'
And match header Content-Type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
* def value= FileChecker.createExcelFile(response)
* print value
And the Java code:
public static String createExcelFile(String excel) throws IOException, InvalidFormatException {
InputStream stream = IOUtils.toInputStream(excel, Charset.forName("UTF-8"));
Workbook workbook = WorkbookFactory.create(stream);
return ("Workbook has " + workbook.getNumberOfSheets() + " Sheets : ");
}
When running the scenario, I get the following error:
javascript evaluation failed: FileChecker.createExcelFile(response), java.io.IOException: Failed to read zip entry source
When testing the same endpoint in Postman, I am getting a valid excelsheet.
In Karate 0.9.X onwards you have a responseBytes variable which will be raw bytes, which may be what you need.
* def value = FileChecker.createExcelFile(responseBytes)
And you can change your method signature to be:
public static String createExcelFile(byte[] excel) {}
You should be easily able to convert a byte array to an InputStream and take it from there.
P.S. just saying that it "works in Postman" is not helpful :P
TO download zip file from Karate tests as binary bite array
Scenario: To verify and get the ADCI Uri from deployment
Given url basicURL + DeployUri +ArtifactUri
And headers {authorization:'#(authToken)',accept:'application/json',tenant:'#(tenantUUId)',Content-Type:'application/zip'}
When method get
Then status 200
And def responsebytes = responseBytes

Unexpected end of MIME multipart stream in reading the second time in Web API

at first step I tried to read the contents into MultipartMemoryStreamProvider with the following code
var multipartMemoryStreamProvider = await Request.Content.ReadAsMultipartAsync();
It solve my problem in getting the input File in memory.In this case I have access to other contents Key , but not value .
I tried to get them with reading again the Contents into MultipartFormDataStreamProvider variable
string root = HttpContext.Current.Server.MapPath("~/uploads");
var provider = new MultipartFormDataStreamProvider(root);
Seems because I try to read the stream twice , it has the following error:
Unexpected end of MIME multipart stream. MIME multipart message is not
complete
My first preference is to convert MultipartMemoryStreamProvider to MultipartFormDataStreamProvider
Is it possible to do that?

Accessing a 3rd party API JSON object in ruby

Been messing around with Kickbox's api for email verification. I'm trying to have the program only display the result object in the returned JSON.
Here's the code:
require "kickbox"
require 'httparty'
require 'json'
client = Kickbox::Client.new('ac748asdfwef2fbf0e8177786233a6906cd3dcaa')
kickbox = client.kickbox()
response = kickbox.verify("test#easdfwf.com")
file = File.read(response)
json = JSON.parse(file)
json['result']
I'm getting an error verify.rb:10:in read': no implicit conversion of Kickbox::HttpClient::Response into String (TypeError)
from verify.rb:10:in'
Here's a sample response:
{
"result":"undeliverable",
"reason":"rejected_email",
"role":false,
"free":false,
"disposable":false,
"accept_all":false,
"did_you_mean":"bill.lumbergh#gmail.com",
"sendex":0,
"email":"bill.lumbergh#gamil.com",
"user":"bill.lumbergh",
"domain":"gamil.com",
"success":true,
"message":null
}
You are getting this error:
read': no implicit conversion of Kickbox::HttpClient::Response into String (TypeError)
Because, in this line:
file = File.read(response)
Your response is a Kickbox::HttpClient::Response type object, but the File.read is expecting a String object instead (possibly a file name with path).
I'm not sure what you are trying to do, but this: file = File.read(response) is wrong. You can't do this and that's why you are getting the mentioned error.
If you really want to use file, then you can write the response to a file and then read the response back from the file and use that:
f = File.new('response.txt', 'w+') # creating a file in read/write mode
f.write(response) # writing the response into that file
file_content = File.read('response.txt') # reading the response back from the file
So, the issue is not about Accessing a 3rd party API JSON object in ruby, but you are trying to use File.read in a wrong way.
You can get the response from the API by doing this:
client = Kickbox::Client.new('YOUR_API_KEY')
kickbox = client.kickbox()
response = kickbox.verify("test#easdfwf.com")
Then, you can play with the response e.g. can do a puts response.inspect or puts response.body.inspect and see what's inside that object.
And, from there you can extract your required outputs only.

Error in URL.getFile()

I am trying to open a file from URL.
Object of URL is created with getResource() method of ClassLoader.
Output URL returned from getResource() method is =
file:/C:/users/
After using URL.getFile() method which returns String as " /C:/users/ " it removes "file:" only not the "/ "
This / gives me a error in opening a file using new FileInputStream.
Error : FileNotFoundException
" / " in the starting of the filename causes the same problem in getting the path object.
Here , value of directory is retrieved from the URL.getResource().getFile()
Path Dest = Paths.get(Directory);
Error received is :
java.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:/Users/
is anyone face such issue ?
Don't use URL.getFile(), it returns the "file" part of the URL, which is not the same as a file or path name of a file on disk. (It looks like it, but there are many ways in which there is a mismatch, as you have discovered.) Instead, call URL.toURI() and pass the resulting URI object to Paths.get()
That should work, as long as your URL points to a real file and not to a resource inside a jar file.
Example:
URL url = getClass().getResource("/some/resource/path");
Path dest = Paths.get(url.toURI());
The problem is that your result path contains leading /.
Try:
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Path path = Paths.get(loader.getResource(filename).toURI());

Ruby open-uri, returns error when opening a png URL

I am making a crawler parsing images on the Gantz manga at http://manga.bleachexile.com/gantz-chapter-1.html and on.
I had success until my crawler tried to open a image (on chapt 273):
bad URI(is not URI?): http://static.bleachexile.com/manga/gantz/273/Gantz[0273]_p001[Whatever-Illuminati].png
BUT this url is valid I guess, because I can open from Firefox.. Any thoughts?
Partial code:
img_link = nav.page.image_urls.find {|x| x.include?("manga/gantz")}
img_name = RAILS_ROOT+"/public/#{nome}/#{cap}/"+nome+((template).sub('::cap::', cap.to_s).sub('::pag::', i.to_s))
img = File.new( img_name, 'w' )
img.write( open(img_link) {|f| f.read} )
img.close
It is not a valid uri. Only certain characters are allowed for uri's. By the way firefox like all browsers try to do as much as possible for the user instead of complaining when it does not look standard compliant.
It is valid in the following form:
open("http://static.bleachexile.com/manga/gantz/273/Gantz%5B0273%5D_p001%5BWhatever-Illuminati%5D.png") # => #<File:/tmp/open-uri20100226-3342-clj08a-0>
You could try to escape it like this:
uri.gsub(/\/.*/) do |t|
t.gsub(/[^.\/a-zA-Z0-9\-_ ]/) do |c|
"%#{ c[0]<16 ? "0" : "" }#{ c[0].to_s(16).upcase }"
end.gsub(" ", "+")
end
But be carefull, if the website uses correct escaped uri's and you escape them a second time. The uri's wont point to the same location anymore.

Resources