DrupalCon Prague 2013

Introducción a Selenium

Earnest Berry  · 

Transcripción

Extracto de la transcripción automática del vídeo realizada por YouTube.

24 so everything gets kind of scrunched down so it'll be some kind of flickering back and forth so make sure we got everything set up over there dump them all right I know it's kind of small I hope everyone can see this so this is the basic test we're

going to go over I'm we're using PHP unit and PHP unit has a plugin for selenium and for those who aren't familiar with it I'm just going to quickly go go through this so I'm extending a webdriver test case which is just a general object

pattern of inheritance and this then obviously then extends a Drupal selenium test case which is just another general object kind of a helper object that I made and then this I can open that up this the next sentence phpunit extension selenium test case and

this is PHP PHP units plugin that does the selenium testing for you and like I said it's since it's open source we can go and just kind of give anyone who's not familiar with an idea so I'm just hoping it this way and inside of this PHP you

can see it's phpunit selenium and then inside of this class is this function to command and all i want to show you here is that it takes these commands that we're sending it for example open wait for element present takes command send it to the selenium

server that's waiting at that endpoint and just use this good old curl since dhcp command gets information back and that's the workflow that we're working with so i'm just going to run a simple workflow here or a simple test and the first thing

I'm going to do is I'm going to spin up the selenium server itself on my local machine so you can see I have this jar file here a selenium server which you just download from the selenium site going to run it standalone you just run it like a simple

jar file you'll see it's launched the selenium server and if I go to this port you'll see it started on port 44 for you can see that it's running and don't worry about the air is because we didn't send the right information and then

I'm just going to run this simple login test I put some sleep send because it goes really fast so I tried to slow it down a little bit and actually apologized for that so these two lines are a way I switch between webdriver and selenium so late in the

talk will go through that but what I want to want to run that test again to show one thing and this will help when we go to the difference between selenium and our selenium one and webdriver so you'll see we have this control window up here and in the

bottom we actually have the actual test run so plain and simple and I think we all understand that are there any questions so far we're all good okay alright so we did our simple tests so now we kind of want to talk about webdriver so webdriver is selenium

to I if you if you want we can go into the history but it was a separate project but webdriver selenium two and one of the main things that will that was that's kind of important about it is that it's kind of they want to drive it from the users point

of view they don't want to drive it as a browser so to speak and as I mentioned before they drive it by the by the browser's native API so for example Internet Explorer if you were going to write something for internet explorer in the most efficient

way you'd probably fire up visual studio and probably program in C++ because this automation bindings are in C++ and firefox has I think xpcom which is its kind of plug-in device that's native to it and that's what webdriver does its it drives

a browser by its native API so when you for example even though it's written in java java has something called J&I which is java native interface which allows you to run c++ almost as if you're you know natively working with it and so that's

that's the way they wrote what our web drivers architecture is set up it's also a actual standard you can go in google w3c web driver and they're trying to make it a standard so that other things can interface with it so I want to go back to I

don't wanna get too bogged down in the details of architecture that one statement of they're tryin a driver from the users point of view is kind of very important and it kind of also changes the way you write tests and it can also break your tests

so i have this simple example i call it the fortune teller and we're just going to show is how you know this concept in in place assouline one versus selenium too and also some of the side effects of writing in selenium one how you can actually you know

have tests that pass that shouldn't pass so let's go ahead and go through the fortune teller I'm going to go through it manually first just so we know how its set up okay so it's really simple it's not and I'm almost out of power I

apologize plugin so I put in any name favorite color let's go with red predict my future and it says Jim Brown you're okay it's very simple I wish fortune tellers were that nice so so our test if we go look at our test is pretty straightforward

we're going to open the webpage we're going to get a unique name just a random name we're going to put the name in we're going to click the next button like I did wait for the color text box to come up and we're going to put in a color

arbitrarily chose blue and then we're going to click Next and we're going to look for that link that says start over now just a little background about the fortune teller I use the basic Drupal AHA framework for Ajax forms so can anyone guess I guess

you can't what will happen when i run this at selenium one because we did the user login tests which means you put in to text you put in the information the two text fields and you told to click the button we're doing the same thing here which is what

i just did manually so let's go ahead and run it i really wish i had a not a 10 x 24 screen yep not small enough yet it's the yes so it did put in the name and actually to make this easier for you guys came I'm going to run this in single window

mode okay so one hint is that the end you can see it's now just waiting for that element to come up for the edit for the color question to come up one hint is that the AHA framework actually doesn't fire it attaches his button using a mouse down event

and as we mentioned before the selenium one drive through JavaScript so when you say click the button it uses JavaScript and actually clicks a button it fires the click event and the problem is it only fires a click event it doesn't actually do i click

on the button which would fire all the events that would happen in the button the mouse down mouse up and the click so the difference is when I run the same test switching to webdriver mode and all does is extend a different extends phpunit selenium to implementation

instead of the selenium one implementation let me see it works perfectly fine because it's driving it from the native from the native bindings and it actually just does like a mouse clicked here and then that I am that bubbles down and does all the events

that happen on that button so if you've ever done autocomplete fields for example the onblur event usually you have to do a fire event on blur because when you lose focus it actually doesn't fire the the blur event when you use webdriver it actually

fires when you lose focus and go someplace else it actually fires a blur event because it's actually driving it like a user instead of through JavaScript where you're kind of only doing one item and not the full stack and I have another example but

do you guys all I understand that okay and the other example real quick is that so what I did was I put in some JavaScript that just disables the name field and again if we go by charges are a simple basic login test and i just made a test called basic typing

is just going to type in those fields and do an absolute assertion which will always be true totality if you will and if i do this in selenium one ah yes we'll see that even though it's disabled it puts the username in there and if I if I switch that

or if I just switched a webdriver so it's not even gonna type it because to webdriver it says that fields not available for me to manipulate so again from the users point of view that one line just changes how you write your tests and how webdriver goes

about throwing errors and seeing what's available for it for it to do so you get like on a real feedback and these are very basic simple examples but it once you start getting kind of into more complicated items you'll get hit with things like if you

have a drop-down menu and you try and do a get text to see what's in there selenium one will give you the full UL the full ordered list oh yes that's okay it's it's up to the group we would need about 15 to 20 minutes to pull cables out with

the chairs and so if you want to do this we just need to know what time you'd like to go break okay I I'm almost to the next to the next section of organization so like five minutes yep five minutes and yeah I could really some coffee anyway so that's

good um where was I oh yes oh yes no and actually that's my next slide so so I'm glad yes um so you know that's that's kind of the difference of from a user's point point of view so and when you do get texts with with webdriver you'll

only see what the user can see you only see the my account you won't see their log out or the other or drop downs in there so it really is kind of saying and then you can do more complicated things something's overlaying that you know the user couldn't

[ ... ]

Nota: se han omitido las otras 4.918 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.