Your SlideShare is downloading. ×
0
High-level Web Testing
High-level Web Testing
High-level Web Testing
High-level Web Testing
High-level Web Testing
High-level Web Testing
High-level Web Testing
High-level Web Testing
High-level Web Testing
High-level Web Testing
High-level Web Testing
High-level Web Testing
High-level Web Testing
High-level Web Testing
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

High-level Web Testing

5,686

Published on

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,686
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. High-level web testing Peter Sergeant Contractor @ NET-A-PORTER
  • 2.  
  • 3.  
  • 4. <ul><li># $mech is a WWW::Mechanize subclass object </li></ul><ul><li>$mech ->get( '/Fulfilment/Putaway?process_group=844284' ); </li></ul><ul><li>print Dumper $mech ->as_data(); </li></ul><ul><li># Page contents as data </li></ul><ul><li>$VAR1 = { </li></ul><ul><li>'metadata' => { </li></ul><ul><li>'delivery_number' => '615019' , </li></ul><ul><li>'process_group_id' => '844284' , </li></ul><ul><li>'page_type' => 'Surplus' , </li></ul><ul><li>'Designer' => 'Rows' , </li></ul><ul><li>'Description' => 'New Description' , </li></ul><ul><li>'Colour' => 'Black' , </li></ul><ul><li>'Sales Channel' => 'MRPORTER.COM' </li></ul><ul><li>}, </li></ul><ul><li>'item_list' => [ </li></ul><ul><li>{ </li></ul><ul><li>'Size' => 'None/Unknown' , </li></ul><ul><li>'SKU' => '2106034-001' </li></ul><ul><li>}, </li></ul><ul><li>{ </li></ul><ul><li>'Size' => 'None/Unknown' , </li></ul><ul><li>'SKU' => '2106034-005' </li></ul><ul><li>} </li></ul><ul><li>] </li></ul><ul><li>}; </li></ul>
  • 5. <ul><li>'Fulfilment/PackingException/ViewContainer' => { </li></ul><ul><li>auto_match => qr!^/Fulfilment/PackingException/ViewContainer?container_id=Mw+ $! , </li></ul><ul><li>specification => { </li></ul><ul><li>orphaned_items => { </li></ul><ul><li>location => 'id(&quot;orphaned_items&quot;)' , </li></ul><ul><li>transform => 'parse_table' , </li></ul><ul><li>optional => 1 , </li></ul><ul><li>}, </li></ul><ul><li>shipment_items => { </li></ul><ul><li>location => 'id(&quot;shipment_items&quot;)' , </li></ul><ul><li>transform => 'parse_table' , </li></ul><ul><li>optional => 1 , </li></ul><ul><li>}, </li></ul><ul><li>cancelled_items => { </li></ul><ul><li>location => 'id(&quot;cancelled_items&quot;)' , </li></ul><ul><li>transform => 'parse_table' , </li></ul><ul><li>optional => 1 , </li></ul><ul><li>}, </li></ul><ul><li>} </li></ul><ul><li>}, </li></ul>
  • 6. <ul><li>'Fulfilment/Packing/EmptyTote' => { </li></ul><ul><li>auto_match => qr!^/Fulfilment/Packing/EmptyTote!, </li></ul><ul><li>specification => { </li></ul><ul><li>totes => { </li></ul><ul><li>location => 'id(&quot;totes&quot;)' , </li></ul><ul><li>transform => 'parse_simple_list' , </li></ul><ul><li>}, </li></ul><ul><li>}, </li></ul><ul><li>}, </li></ul>
  • 7. <ul><li>=head2 parse_simple_list </li></ul><ul><li>Return a simplified text representation of the li elements under a node. </li></ul><ul><li>=cut </li></ul><ul><li>sub _xclient_parse_simple_list { </li></ul><ul><li>my ( $self , $list_node ) = @_ ; </li></ul><ul><li># Find the child elements </li></ul><ul><li>my @li_elements = $list_node ->find_xpath( 'li' )->get_nodelist(); </li></ul><ul><li># Render them as text </li></ul><ul><li>my @simplified = map { </li></ul><ul><li>$self ->_xclient_trim_cell( $_ ->as_text) </li></ul><ul><li>} @li_elements ; </li></ul><ul><li># And give them back... </li></ul><ul><li>return @simplified ; </li></ul><ul><li>} </li></ul>
  • 8. <ul><li># Send the shipment ID </li></ul><ul><li>$mech ->submit_form_ok({ </li></ul><ul><li>with_fields => { shipment_nr = $shipment_id } </li></ul><ul><li>}, &quot;Shipment ID submitted&quot; ); </li></ul>
  • 9. <ul><li># Check we're in the right place, and then submit the form </li></ul><ul><li>unless ( $mech ->uri->path eq '/Fulfilment/Selection' ) { </li></ul><ul><li>die &quot;Expecting to be on /Fulfilment/Selection, actually: &quot; . </li></ul><ul><li>$mech ->uri->path </li></ul><ul><li>} </li></ul><ul><li># Send the shipment ID </li></ul><ul><li>$mech ->submit_form_ok({ </li></ul><ul><li>with_fields => { shipment_nr = $shipment_id } </li></ul><ul><li>}, &quot;Shipment ID submitted&quot; ); </li></ul>
  • 10. <ul><li># Check we're in the right place, and then submit the form </li></ul><ul><li>unless ( $mech ->uri->path eq '/Fulfilment/Selection' ) { </li></ul><ul><li>die &quot;Expecting to be on /Fulfilment/Selection, actually: &quot; . </li></ul><ul><li>$mech ->uri->path </li></ul><ul><li>} </li></ul><ul><li># Send the shipment ID </li></ul><ul><li>$mech ->submit_form_ok({ </li></ul><ul><li>with_fields => { shipment_nr = $shipment_id } </li></ul><ul><li>}, &quot;Shipment ID submitted&quot; ); </li></ul><ul><li># Check we didn't get any logical errors </li></ul><ul><li>if ( $mech ->as_data->error_message ) { </li></ul><ul><li>die &quot;HTTP request passed, but the application complained: &quot; . </li></ul><ul><li>$mech ->as_data->error_message; </li></ul><ul><li>} </li></ul>
  • 11. <ul><li>__PACKAGE__->create_fetch_method( </li></ul><ul><li>method_name => 'flow_mech__fulfilment__packingexception' , </li></ul><ul><li>page_description => 'packing Exception Page' , </li></ul><ul><li>page_url => '/Fulfilment/PackingException' </li></ul><ul><li>); </li></ul><ul><li>__PACKAGE__->create_form_method( </li></ul><ul><li>method_name => 'flow_mech__fulfilment__packingexception_comment' , </li></ul><ul><li>form_name => 'add_comments' , </li></ul><ul><li>form_description => 'add comment' , </li></ul><ul><li>assert_location => qr!^/Fulfilment/Packing/CheckShipmentException!, </li></ul><ul><li>transform_fields => sub { return { note_text => $_ [ 1 ] } }, </li></ul><ul><li>); </li></ul><ul><li>#------------------------------------------------------------------------------- </li></ul><ul><li>$framework </li></ul><ul><li>->flow_mech__fulfilment__packingexception </li></ul><ul><li>->flow_mech__fulfilment__packingexception_comment( </li></ul><ul><li>&quot;The quick brown fox ran over the lazy sheep dog&quot; </li></ul><ul><li>); </li></ul><ul><li>#------------------------------------------------------------------------------- </li></ul><ul><li># ->flow_mech__fulfilment__packingexception() </li></ul><ul><li># Retrieving the packing Exception Page </li></ul><ul><li># URL /Fulfilment/PackingException retrieved successfully via HTTP </li></ul><ul><li># No status message shown </li></ul><ul><li># Retrieved the packing Exception Page </li></ul><ul><li># ->flow_mech__fulfilment__packingexception_comment( &quot;Comment 1:70236&quot; ) </li></ul><ul><li># URL [/Fulfilment/Packing/CheckShipmentException] matched assertion </li></ul><ul><li># Searching for the add comment form </li></ul><ul><li># Submitting add comment form </li></ul><ul><li># URL /Fulfilment/Packing/CheckShipmentException?shipment_id=1630767 retrieved successfully via HTTP </li></ul><ul><li># No status message shown </li></ul>
  • 12. <ul><li># Look for our purchase order </li></ul><ul><li>$flow </li></ul><ul><li>->flow_mech__goodsin__stockin </li></ul><ul><li>->flow_mech__goodsin__stockin_search({ </li></ul><ul><li>purchase_order_number => $purchase_order_id </li></ul><ul><li>}); </li></ul><ul><li># Did we find it? </li></ul><ul><li>is( </li></ul><ul><li>$flow ->mech->as_data->{ 'products' }->[ 0 ]->{ 'PID' }, </li></ul><ul><li>$product_id , </li></ul><ul><li>&quot;Found our product from the purchase order search&quot; </li></ul><ul><li>); </li></ul><ul><li># Check the packing slip </li></ul><ul><li>$flow </li></ul><ul><li>->flow_mech__goodsin__stockin_packingslip( $flow ->stock_order->id ) </li></ul><ul><li># Is it sensible? </li></ul><ul><li>is( </li></ul><ul><li>$flow ->mech->as_data->{ 'product_data' }->{ 'Purchase Order' }->{ 'value' }, </li></ul><ul><li>$purchase_order ->purchase_order_number, </li></ul><ul><li>&quot;Purchase order matched from Stock Order page&quot; </li></ul><ul><li>); </li></ul>
  • 13. <ul><li>sub create_form_method { </li></ul><ul><li>my ( $class , %args ) = @_ ; </li></ul><ul><li># This is a good place to check a user is using it correctly... </li></ul><ul><li>$class ->_auto_methods_check_params( %args , </li></ul><ul><li>{ </li></ul><ul><li>required => [ qw/ </li></ul><ul><li>method_name form_name form_description assert_location </li></ul><ul><li>/ ], </li></ul><ul><li>optional => [ 'form_button' , 'transform_fields' ], </li></ul><ul><li>}); </li></ul><ul><li>$class ->meta->add_method( </li></ul><ul><li>$args { 'method_name' } => sub { </li></ul><ul><li>my ( $self , @user_options ) = @_ ; </li></ul><ul><li>$self ->show_method_name( $args { 'method_name' }, @user_options ); </li></ul><ul><li>$self ->assert_location( $args { 'assert_location' } ) </li></ul><ul><li>if defined $args { 'assert_location' }; </li></ul><ul><li>my $transformed_fields = $args { 'transform_fields' } ? </li></ul><ul><li>$args { 'transform_fields' }->( $self , @user_options ) : {}; </li></ul><ul><li>$self ->indent_note( &quot;Searching for the $args {'form_description'} form&quot; ); </li></ul><ul><li>my $name = ref ( $args { 'form_name' }) eq 'CODE' ? </li></ul><ul><li>$args { 'form_name' }->( $self , @user_options ) : </li></ul><ul><li>$args { 'form_name' }; </li></ul><ul><li>my $form = $self ->mech->form_name( $name ); </li></ul><ul><li>unless ( $form ) { </li></ul><ul><li>croak &quot;Couldn't find a form with name $args {'form_name'}&quot; ; </li></ul><ul><li>} </li></ul><ul><li>$self ->mech->set_fields( %$transformed_fields ); </li></ul><ul><li>my $button = ref ( $args { 'form_button' }) eq 'CODE' ? </li></ul><ul><li>$args { 'form_button' }->( $self , @user_options ) : </li></ul><ul><li>$args { 'form_button' }; </li></ul><ul><li>$self ->indent_note( &quot;Submitting $args {'form_description'} form&quot; ); </li></ul><ul><li>$self ->mech->submit_form( </li></ul><ul><li>fields => $transformed_fields , </li></ul><ul><li>$button ? ( button => $button ) : () </li></ul><ul><li>); </li></ul><ul><li>$self ->note_status; </li></ul><ul><li>return $self ; </li></ul><ul><li>} </li></ul><ul><li>); </li></ul><ul><li>} </li></ul>
  • 14. Come and work at Net-A-Porter <ul><li>We’re hiring </li></ul><ul><li>It’s a lot of fun </li></ul><ul><li>Nice offices </li></ul>

×