Selenium Sandwich Part 2: Add some meat
Steven Lembark
Workhorse Computing
lembark@wrkhors.com
What is a Selenium Sandwich?
Tasty!!!
No really..
What is a Selenium Sandwich?
Last time we saw how to wrap an existing object.
Add some high-level functions to it.
Now we get to use them.
Chicken & Egg
How do you validate what's in the browser?
Without knowing the request and the reponse?
Chicken & Egg
How do you validate what's in the browser?
Without knowing the request and the reponse?
A: You can't.
That's why debugging front ends is so hard:
All you see is what's in the browser.
Fix: Feed the browser from a server you control.
Sounds easy enough:
Make a request you know.
To a server you control.
Get back a known response.
Validate what is in the browser.
Fix: Feed the browser from a server you control.
Sounds easy enough:
Make a request you know.
To a server you control.
Get back a known response.
Validate what is in the browser.
Q: How do you control the response?
The dynamic fly in our soup
You usually can't control the response.
Most browser-code testing uses an active server.
Bugs in the server show up in your browser.
Validating the browser requires a fixed response.
The dynamic fly in our soup
You usually can't control the response.
Most browser-code testing uses an active server.
Bugs in the server show up in your browser.
Validating the browser requires a fixed response.
That means you can't use the “real” server.
What's a fake server?
A: One that hands back a canned response.
Result:
Use the browser to request the pre-determined reply.
Validate the browser contents using selenium.
Defining content
PSGI makes defining the response easy.
PSGI reply format:
[
http code,
[ http headers ],
[ http returned content ]
]
[ 200, [], [ “Hello, world!<p>” ]
PSGI is easy in YAML
---
-
- 200
- []
- Hello, worldn
A complete setup & request
---
-
# high-level call to find and click “submit”
- find_click
- submit
-
# hardwired response
- 200
- []
- [ “hello, world!<p>”, “in flowed text<p>” ]
Plack is your friend.
Don't tell your dentist I said so...
POST some YAML to a server and it can do the deed.
<http://www.slideshare.net/lembark/get-your-teeth-into-
plack?qid=9164c31a-2e24-4ac3-ae97-
5fdfff95ec84&v=default&b=&from_search=1>
Er... how? You still need a browser...
Easy: Plack is Perl, remember?
PUT SELENIUM CODE
INTO THE BROWSER!!!
Server on one port gets a request
my $response = '';
my $validate = '';
sub setup_test # handler for port 5001
{
my $env = shift;
my $control = Load $env->{ POST_DATA };
( $response, $validate ) = @$contrl{qw( response validate )};
my $browser = Selenium::Handler->new;
run_browser_commands $control;
}
sub run_test # handler for port 80
{
my $env = shift; # from setup_test.
validate_request $env, $validate; # sanity checks.
$response # canned response.
}
What just happened?
HTTP server sent itself a request.
From a browser.
Using selenium.
What just happened?
HTTP server sent itself a request.
From a browser.
Using selenium.
It is a closed loop.
You can test it.
Next Month: Actually making it work.
Main issue is getting requests back to the server.
Which requires a proxy server.
And a bit of black magic under the hood.

Selenium sandwich-2

  • 1.
    Selenium Sandwich Part2: Add some meat Steven Lembark Workhorse Computing lembark@wrkhors.com
  • 2.
    What is aSelenium Sandwich? Tasty!!! No really..
  • 3.
    What is aSelenium Sandwich? Last time we saw how to wrap an existing object. Add some high-level functions to it. Now we get to use them.
  • 4.
    Chicken & Egg Howdo you validate what's in the browser? Without knowing the request and the reponse?
  • 5.
    Chicken & Egg Howdo you validate what's in the browser? Without knowing the request and the reponse? A: You can't. That's why debugging front ends is so hard: All you see is what's in the browser.
  • 6.
    Fix: Feed thebrowser from a server you control. Sounds easy enough: Make a request you know. To a server you control. Get back a known response. Validate what is in the browser.
  • 7.
    Fix: Feed thebrowser from a server you control. Sounds easy enough: Make a request you know. To a server you control. Get back a known response. Validate what is in the browser. Q: How do you control the response?
  • 8.
    The dynamic flyin our soup You usually can't control the response. Most browser-code testing uses an active server. Bugs in the server show up in your browser. Validating the browser requires a fixed response.
  • 9.
    The dynamic flyin our soup You usually can't control the response. Most browser-code testing uses an active server. Bugs in the server show up in your browser. Validating the browser requires a fixed response. That means you can't use the “real” server.
  • 10.
    What's a fakeserver? A: One that hands back a canned response. Result: Use the browser to request the pre-determined reply. Validate the browser contents using selenium.
  • 11.
    Defining content PSGI makesdefining the response easy. PSGI reply format: [ http code, [ http headers ], [ http returned content ] ] [ 200, [], [ “Hello, world!<p>” ]
  • 12.
    PSGI is easyin YAML --- - - 200 - [] - Hello, worldn
  • 13.
    A complete setup& request --- - # high-level call to find and click “submit” - find_click - submit - # hardwired response - 200 - [] - [ “hello, world!<p>”, “in flowed text<p>” ]
  • 14.
    Plack is yourfriend. Don't tell your dentist I said so... POST some YAML to a server and it can do the deed. <http://www.slideshare.net/lembark/get-your-teeth-into- plack?qid=9164c31a-2e24-4ac3-ae97- 5fdfff95ec84&v=default&b=&from_search=1>
  • 15.
    Er... how? Youstill need a browser... Easy: Plack is Perl, remember? PUT SELENIUM CODE INTO THE BROWSER!!!
  • 16.
    Server on oneport gets a request my $response = ''; my $validate = ''; sub setup_test # handler for port 5001 { my $env = shift; my $control = Load $env->{ POST_DATA }; ( $response, $validate ) = @$contrl{qw( response validate )}; my $browser = Selenium::Handler->new; run_browser_commands $control; } sub run_test # handler for port 80 { my $env = shift; # from setup_test. validate_request $env, $validate; # sanity checks. $response # canned response. }
  • 17.
    What just happened? HTTPserver sent itself a request. From a browser. Using selenium.
  • 18.
    What just happened? HTTPserver sent itself a request. From a browser. Using selenium. It is a closed loop. You can test it.
  • 19.
    Next Month: Actuallymaking it work. Main issue is getting requests back to the server. Which requires a proxy server. And a bit of black magic under the hood.