Chuan Chuan Law

DevOps | Software Automation | Continuous Integration

Tag: Ruby

Code For Web Services Regression Tests

This is to replace my July post with the link to the source code in GitHub which I have remove for security reasons.

However, below is how the code looks like:

#!/usr/bin/ruby

class WebServices
def main_method
f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @adauthenticate.xml -s -v -D – http://webservices.pageup.com.au/nas/ADAuthenticate/ADAuthenticate.asmx 2>/dev/null>result.xml”).readlines
evalresult(“authenticate”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @bulkData.xml -s -v -D – http://webservices.pageup.com.au/nas/BulkData/BulkData.asmx?op=GetAvailableImportItemTypes 2>/dev/null>result.xml”).readlines
evalresult(“bulkData”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @htmlToPdf.xml -s -v -D – http://webservices.pageup.com.au/nas/HTMLToPDF/HTMLToPDF.asmx?op=GetToken 2>/dev/null>result.xml”).readlines
evalresult(“HTMLToPDF”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @htmlToRtf.xml -s -v -D – http://webservices.pageup.com.au/nas/HTMLToRTF/HTMLToRTF.ASMX?op=URLToRTF 2>/dev/null>result.xml”).readlines
evalresult(“HTMLToRTF”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @jobSource.xml -s -v -D – http://webservices.pageup.com.au/nas/JobSourceWS/JobSourceWS.asmx?op=GetToken 2>/dev/null>result.xml”).readlines
evalresult(“jobSource”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @jobSource2.xml -s -v -D – http://webservices.pageup.com.au/nas/JobSourceWS/JobSourceWS.asmx?op=UpdateJobSource  2>/dev/null>result.xml”).readlines
evalresult(“updateJobSource”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @mediaOrder.xml -s -v -D – http://webservices.pageup.com.au/nas/MEDIAORDERWS/MediaOrderWS.asmx?op=GetToken 2>/dev/null>result.xml”).readlines
evalresult(“MediaOrder”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @pageUpPeople.xml -s -v -D – http://webservices.pageup.com.au/nas/PageUpPeopleWS//PageUpPeople.asmx?op=GetApplicant 2>/dev/null>result.xml”).readlines
evalresult(“PageUpPeople”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @pdfReportGenerator.xml -s -v -D – http://webservices.pageup.com.au/nas/PDFReportGenerator/PDFReportGenerator.asmx?op=Generate360ReportWS 2>/dev/null>result.xml”).readlines
evalresult(“PDFReportGenerator”)

f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @pdfToHtml.xml -s -v -D – http://webservices.pageup.com.au/nas/PDFtoHTML/PDFtoHTML.asmx?op=PDFToHTML 2>/dev/null>result.xml”).readlines
evalresult(“PDFToHTML”)

f=IO.popen(“curl http://webservices.pageuppeople.com/nas/JobsRest/JobListing.svc/218/caw/en  2>/dev/null>result.xml”).readlines
evalresult(“JobRest”)

end

def evalresult(webserviceType)
f=File.new(“/Users/chuan/webservicesTest/result.xml”)
text = f.read

if (webserviceType==”authenticate”) then
print “Authenticate: ”
if (text =~/HTTP/1.1 200 OK/ && text =~/Success/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”bulkData”) then
print “Bulk Data: ”
if (text =~/HTTP/1.1 200 OK/ && text =~/OrgUnit/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”HTMLToPDF”) then
print “HTML To PDF: ”
if (text =~/HTTP/1.1 200 OK/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”jobSource”) then
print “Job Source: ”
if (text =~/HTTP/1.1 200 OK/) then
print  “Successn”
token=text.scan(/(.*)</GetTokenResult>/)
token_string=token.to_s
token_string.gsub!(/[^a-zA-Z0-9-]/,””)
File.open(‘jobSource2.xml’, ‘w’) do |f1|
f1.puts ”
f1.puts ‘  ‘
f1.puts ‘    ‘
f1.puts ”      #{token_string}”
f1.puts ‘     test’
f1.puts ‘
‘                    f1.puts   ‘
‘                    f1.puts ‘
‘                     end
else
print  “Failn”
end
end

if (webserviceType==”updateJobSource”) then
print “Job Source – Update Job Source: ”
if (text =~/HTTP/1.1 200 OK/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”MediaOrder”) then
print “Media Order: ”
if (text =~/HTTP/1.1 200 OK/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”PageUpPeople”) then
print “PageUpPeople: ”
if (text =~/HTTP/1.1 200 OK/ && text =~/tester145127@pup.com/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”PDFReportGenerator”) then
print “PDFReportGenerator: ”
if (text =~/HTTP/1.1 200 OK/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”PDFToHTML”) then
print “PDFToHTML: ”
if (text =~/HTTP/1.1 200 OK/) then
print  “Successn”
else
print  “Failn”
end
end

if (webserviceType==”JobRest”) then
print “JobRest: ”
if (text =~/Account management/) then
print  “Successn”
else
print  “Failn”
end
end

end

end

WebServices.new.main_method

Regression Testing Web Services

The mechanism I use to regression test web services is the same as the mechanism I test API, which is by using:

  • Curl
  • Ruby
Curl is main tool to call the web services and it sits inside the Ruby script which is used to do other functions such as checking the output, etc.
For example, the Curl command below will pass the XML file to the JobSource web service and pipe the output to another XML file:

 f=IO.popen(“curl –request POST –header ‘Content-type: text/xml’ –data @jobSource2.xml -s -v -D – http://webservices.pageup.com.au/JobSourceWS/JobSourceWS.asmx?op=UpdateJobSource  2>/dev/null>result.xml”).readlines

Selenium-Ruby: How To Attach Document On Computer

I encounter a scenario where the browser opens up a window on the computer to attach a file.  I am delighted to find the “attach_file” function.

Below is the code:

Then /^I attach file “([^”]*)” into “([^”]*)”$/ do |filename, id|
filepath=File.expand_path(Dir.pwd)+”/features/support/”+filename
attach_file(id,filepath)
find(:xpath,”//button[@id=’file-submit-button’]”).click
sleep 5
end

© 2019 Chuan Chuan Law

Theme by Anders NorenUp ↑