LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-12-2014, 04:32 AM   #1
jack.sully
Member
 
Registered: Jul 2012
Posts: 38

Rep: Reputation: Disabled
Web service test using Perl/Shell


I need to perform a web service test using Shell/Perl over a menu(some link is given https://.......)

Than I need to call a method (getů..) and enter some values for 3 fields:

1 xxxxxx for username
2 x for user role
3 xxxxx for dealerid

Then I need to verify authentication as true. And also verify that menu can pull up.

I am new to this, any suggestions.
 
Old 03-12-2014, 06:07 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,802

Rep: Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540
You could look at http://search.cpan.org/~ether/WWW-Me...W/Mechanize.pm and friends ...
 
Old 03-12-2014, 06:59 AM   #3
jack.sully
Member
 
Registered: Jul 2012
Posts: 38

Original Poster
Rep: Reputation: Disabled
#!/usr/bin/perl

use strict;

use WWW::Mechanize;
my $mech = WWW::Mechanize->new();

$mech->follow_link( url => 'https://**********?WSDL' );



$mech->submit_form(
form_name => '*****_UserMenu',
fields => {
$username => '*****',
$userRole => '*',
$dealerId => '****'
}
);

I have tried to implement the code. Is this the right way
 
Old 03-12-2014, 07:25 AM   #4
jack.sully
Member
 
Registered: Jul 2012
Posts: 38

Original Poster
Rep: Reputation: Disabled
I am getting errors in the code:

#!/usr/bin/perl

use strict;
use WWW::Mechanize;
use LWP::UserAgent;
use HTTP::Request;

my $mech = WWW::Mechanize->new();

$mech->follow_link( url => 'https://*************/soap/userMenu?WSDL' );

TestWS();

sub TestWS
{

my $message = "Your Request Message";

my $userAgent = LWP::UserAgent->new();
my $request = HTTP::Request->new(POST => "https://*************/soap/userMenu?WSDL");
$request->header(SOAPAction => '"https://*************/services/soap/userMenu"');
$request->content($message);
$request->content_type("text/xml; charset=utf-8");
my $response = $userAgent->request($request);

$mech->submit_form(
form_name => 'Services_UserMenu',
fields => {
$username => 'TESTHYU',
$userRole => 'J',
$dealerId => 'TESTU1A'
}
);

if($response->code == 200)
{
print "Web Service works fine";
}

else
{
print "Looks like there is a bug in the web service";
}
}


-bash-4.1# ./script_perl.pl
Global symbol "$username" requires explicit package name at ./script_perl.pl line 29.
Global symbol "$userRole" requires explicit package name at ./script_perl.pl line 30.
Global symbol "$dealerId" requires explicit package name at ./script_perl.pl line 31.
Execution of ./script_perl.pl aborted due to compilation errors.
 
Old 03-12-2014, 08:06 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182
This is probably better handled at http://www.perlmonks.org.

There are numerous web testing frameworks in Perl, including (as well as the ones mentioned) "LWP::UserAgent."

I happen to enjoy using Selenium a lot, because it runs tests "by gawd, in and with" your actual browser(s). This can be profoundly important. (It does not use Perl.)
 
Old 03-12-2014, 09:36 AM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 9,822

Rep: Reputation: 4420Reputation: 4420Reputation: 4420Reputation: 4420Reputation: 4420Reputation: 4420Reputation: 4420Reputation: 4420Reputation: 4420Reputation: 4420Reputation: 4420
Quote:
Originally Posted by sundialsvcs View Post
I happen to enjoy using Selenium a lot, because it runs tests "by gawd, in and with" your actual browser(s). This can be profoundly important. (It does not use Perl.)
Selenium is the correct way to do it, period. According to its manual, you can indeed script it with Perl.
 
Old 03-12-2014, 03:01 PM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by jack.sully View Post
I am getting errors in the code:

-bash-4.1# ./script_perl.pl
Global symbol "$username" requires explicit package name at ./script_perl.pl line 29.
Global symbol "$userRole" requires explicit package name at ./script_perl.pl line 30.
Global symbol "$dealerId" requires explicit package name at ./script_perl.pl line 31.
Execution of ./script_perl.pl aborted due to compilation errors.
Code:
sub TestWS
{

my $username;
my $userRole;
my $dealerId;

my $message = "Your Request Message";

my $userAgent = LWP::UserAgent->new();
Please use [CODE] [/CODE] tags.
See the underlined edits to fix the errors reported. These are basic Perl errors.
 
Old 03-12-2014, 06:49 PM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182
Quote:
Originally Posted by dugan View Post
Selenium is the correct way to do it, period. According to its manual, you can indeed script it with Perl.
This statement of course is true ... I've done it. What I really meant is that it is happening on the client side. Selenium is driving an actual instance of an actual browser on an actual client side to beat the out of your unsuspecting application.

----
Please let me repeat the suggestion that Perl-related questions are by far best handled over at PerlMonks. (No negativity at all with regard to LQ, but PM is a specialty, specialist site populated by some of the best heads in the Perl world. Present company not included.)

Last edited by sundialsvcs; 03-12-2014 at 06:51 PM.
 
Old 03-13-2014, 06:00 AM   #9
jack.sully
Member
 
Registered: Jul 2012
Posts: 38

Original Poster
Rep: Reputation: Disabled
Hi,I have edited the code. It was a basic error,I have just started working in perl.

I am getting new error.

-bash-4.1# cat perl_script.pl
#!/usr/bin/perl

use strict;
use WWW::Mechanize;
use LWP::UserAgent;
use HTTP::Request;

my $mech = WWW::Mechanize->new();

$mech->follow_link( url => 'https://xxxxxxxxx.com/services/soap/userMenu?WSDL' );

TestWS();

sub TestWS
{
my $username;
my $userRole;
my $dealerId;
my $message = "Your Request Message";

my $userAgent = LWP::UserAgent->new();
my $request = HTTP::Request->new(POST => "https://xxxxxx.com/services/soap/userMenu?WSDL");
$request->header(SOAPAction => '"https://xxxxxx.com/services/soap/userMenu"');
$request->content($message);
$request->content_type("text/xml; charset=utf-8");
my $response = $userAgent->request($request);

$mech->submit_form(
form_name => 'Services_Soap_UserMenu',
fields => {
$username => 'xxxxx',
$userRole => 'A',
$dealerId => 'xxx'
}
);

if($response->code == 200)
{
print "Web Service works fine";
}

else
{
print "Looks like there is a bug in the web service";
}
}

-bash-4.1# ./perl_script.pl
Link not found at ./perl_script.pl line 10.

i.e. $mech->follow_link( url => 'https://xxxxxxxxx.com/services/soap/userMenu?WSDL' );

I am not sure whether Mechanize can be used for making web service or dealing with web pages.
 
Old 03-13-2014, 07:59 AM   #10
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182
There's where you simply have to watch the exchange ... do it on your browser, print some logging information to STDERR to help you debug the logic in your program. You're well on your way, now.

A production-ready program is required to work ... no matter what. No matter what the host throws at it. If the statement that you cite is an error in your program, then, go fix it. (LQ is not a code-writing service.) However, if it is anything that the host might legitimately do, whether in response to an error in your program or otherwise, then your program must be prepared to handle the situation appropriately. (Whatever "appropriately" is.) If a module throws an exception (as this one apparently did), then maybe you need to catch it. (Again, "not a code-writing service," but I'm briefly telling you what this program will be expected to do.)

I presume that you have bookmarked http://search.cpan.org, and that you have diligently read every line of all the documentation on the modules that you are using. (And by the way, that is not an "RTFM!!" brush-off.)

Last edited by sundialsvcs; 03-13-2014 at 08:00 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] What topics do I need to study for *web* client server programming - Web service? TheIndependentAquarius Programming 9 03-15-2013 09:53 AM
Web service problem - perl vs. java nbcohen Linux - Software 2 06-10-2011 01:05 PM
[SOLVED] Silencing the line "echo test > test/test.txt" in a shell script Arenlor Linux - General 2 06-18-2010 01:37 PM
LXer: Create Web services with Ruby on Rails and Action Web Service LXer Syndicated Linux News 0 11-05-2008 06:00 PM
Tools for developing C# web service and web sites in Linux woodbase Linux - Software 3 08-10-2006 01:28 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration