Selenium sandwich-2
-
Upload
workhorse-computing-llc -
Category
Technology
-
view
226 -
download
1
Transcript of Selenium sandwich-2
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>” ]
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 CODEINTO THE BROWSER!!!
Server on one port gets a requestmy $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.
It is a closed loop.
You can test it.