Automating Different Layers with Eggplant (with Full Stack e2e Example)

Hi, and welcome to this talk on full-stack end-to-end testing using Eggplant Fusion Engine or Eggplant Functional that you may be familiar with. My name is Kieran Leicester. I am a technical consultant for Keysight and I work under the Eggplant umbrella working with various software. I have previous experience as a Senior Test and Automation engineer for Liberty Global. And before that, I was a system engineer for Hawk-Eye Innovations. And I come from a mechanical engineering background, but I've moved into the current world of testing. But enough about me, we'll move on to the matter at hand. Eggplant only does image recognition. It's something we had quite a lot here at Eggplant, and it's quite frankly not true. Don't get me wrong, we're really good at it. Actually, we can interact with various other layers of the testing. I want to sort of show you some of those layers that we can incorporate into your test environment, and how that can help improve your testing environment from there.

As you can see here, obviously we do have the OCR and the image recognition. This is something I'm sure we're all familiar with Eggplant doing, very good at that. But it's not all we can do. It does help us interact with your system under test as a human, we can look at various other layers to not just have the front end, but actually everywhere else that you sort of want to look at. Going down to that, we can actually work with the WebDriver so that your Selenium and your Appium to look at the object layer and help incorporate that into your testing. And then going down further we can work with APIs. So your standards of HTTP commands where you're getting posting, you can send your query out, you will get the response body and you can interact with that, put it into JSON form, whatever you want to do. Going down another layer, we can interact with databases and tables to do whatever you would sort of with an SQL command. So you can select them, you can create them, you can delete them, you can adjust them whatever as you would do to SQL capable of doing that with an Eggplant. And actually, we can also interact on the show level.

Say you had an Android device as your system under test. You can have the show command to turn the screen on. So yeah, you can see how we have those various layers. And I sort of spend a bit of time looking at how we introduce a few of those layers into a simple example. This simple example is going to be not too much testing-related, but I will still show you exactly what it is we're capable of doing. We've got a sort of upper management is going to query a SQL database to find out the postcode of an employee, that then going to take that postcode out and stick it into Google Maps to find a local cafe over four stars, find the name of that cafe, and latitude and longitude. We then pass that latitude and longitude into the weather API to find the local weather forecast. And then lastly, we're going to connect to a phone to send an email inviting said employee out for lunch at that cafe and just pre-warning them off the weather.
Kieran Leicester: We're going to start with the ODBC side of things.

So setting up our SQL connection into a database however you want to call it. First things first, we want to set the connection to our database. And that's done quite simply. If we do set my DB that's the variable for my database to. And then I simply want to put the connection sort of settings in here. So the type is going to be ODBC. And then we just need to give it a DSN, which in my case sqllite3. So that sets the connection to our database. And then we actually want to open up, that's simple open database my DB. And whilst we're there I'm just going to have the closed database commands just done. And then it's literally as simple as using that SQL command. And that is what we used to SQL commands.

So if I just put SQL. This takes in two variables. So I've got my DB so it knows exactly what database we're connecting to. And then the command SQL, the command we want to use. So I'm just gonna do something as simple as select * from EMPLOYEES. And you should see that if I run that I've now got all the information from that table where my database and this command can be anything that sort of works with the generic SQL command.

So hopefully, we can quickly parameterize this, and make it into a function within our script test. I'm just going to put to SQL query put command as an input into this. I'm just going to copy this whole thing in there. I'm just going to get rid of the commands that are actually inputting into SQL thing, that variable there. And then we can now just input any SQL command we want into this simple function and return all the end for the information we need. I'm going to go again, I'll go for the same on select * from EMPLOYEES. This is where we grab the employee info. And then if I just run that, again, we get the same information and now we can just replace this with any extra command you want it can be. Selecting it can be creating, it can be deleting, it can be anything with that. So that's nice and simpler. That might be what you need to complete your requirements. Or we can actually go a step further and make it a bit more sense talking.

Again, I'm going to set my database connection. I can then call on the next table I want. I do that by putting table and then have to name the table. In this case, I'll go for employees again. Tell it where this table is, so of my database. And that's going to put it into a local table called employee table. And then I can work with that and I can grab, for this case, I'll grab the postcode of the record of employee table, where and then what column I want to match up. I'm just going to use that employee surname. So surname here is I'll just go for Johnson because I know there's a Johnson in there and I'll put that into. In fact, I can just run that. As is. So you see now that's just returned the postcode of Johnson within our own validity space. So nice and easy. And again, now I can look to parameterize this and make it a bit more customizable going forward. I'm gonna make a function code to get the postcode, and I'll set the surname as an input into that. Now I can just grab all that, stick it in there. This is going to be parameterized. This will be Sname. I'm going to put this into a variable. Call it postcode nice and easy. And then we can return the postcode out of this. And then we've got that variable coming up that we can pay with later in our script. I was just run and put that postcode again which our good old friend Johnson. I think we're getting that information out.

Now, for this situation, we can just change whichever employee's surname is that we want to take out of coffee. We can just put it in that nice and easy. And this can be expanded out. For example, in this situation, we're going to want to get the email address. So using this similar format, here's one I did earlier. We can now get the email address out. And again, I'll just show you that working. But it's just a case of putting in the surname again that we want. It could be anything. It could be any sort of column within your table on that. And we can help get it out. And we can call on these functions later in our script.

Now, we're ready to move on to the API side of things, which can be getting the weather forecast based off an input, which in this case is going to be a latitude and longitude. And we'll put that into our email to warn our employees of the forecast. If you look here at the top left, we've got these icons up here in the API test one is a little globe. And if I create a new API test, I'm just going to call it weather API as I'm very imaginative and you can see we are greeted with this screen up here. In this case, I'm going to be using a get command but it can be any of your classic ones there. And you'll see we've got a few different parameters and stuff we can change in our request. And also we can look at the response and we'll be able to look a different part of that. So for this case, I'm just going to copy over a URL that is going to query the weather stack. I'll copy that into there. And I'm going to add a couple of parameters.

So you could just add as many parameters as you need for your test in there. For this case, I need an access key. So access_key. And I'll just copy that over. And then we'll also need to pass in the query, which in this case is going to be the location that we're looking to get the forecast of. So query here. And for their sake, I'll just do London and nice and easy that we'll run and we'll get our response body by looking here in JSON format. And you see there's plenty for us to play around here. We can look at the headers that are associated with this API. If you want to turn in the request we can add some authentication. We can add our own headers. There's all that to do which can be quite useful. But I actually like to use a different format.

 I'm going to create a new API test. And I'm just going to call it get. I'm going to leave it as this. And I'm doing this so that we can use this bit more interactively in our script. And then go into my scripts actually what's in here. I'm just going to copy this URL. I should be needing that shortly. I'm going to go into this script and this is over run it from. I'm just going to first, I'll set a parameter called URL to. And this can be that part that we copied over there. I'm then going to call this API down here. I'm going to put get. And this takes an input of URL which in this case would be our URL. And that will give us the same response that we got before. Again, it's in JSON format. It doesn't look that great as it's formatted here.

But you can see that information is there. We can expand out there. We can expand out this, there's some inbuilt functionality to sort of support JSON, and we can assert, and check we've got that correct result. Let's go ahead and do that. I'm just going to stick that into a little variable there called APIResults. And I'm going to firstly, I'm going to want to assert the API results. And I just want to look at the status code is equal to 200. So if it's anything other than 200 we'll get a warning log and the test will start running there. I'm then going to put this into a much easier format for sense talk to you.

So it's got that inbuilt functionality to work with JSON. I'm just going to get the results out. I'm just going to look more about the response body because that's going to have the information that I'm worried about for this situation. And I'll stick that into. I'll just imaginatively again call that response body so that we've got that there. And maybe now I'll just log response body to show you exactly what we've got. So I can run that. And you see, it's been formatted slightly nicer and we've just got the response body. But for this situation, I'm just worried about a sort of quick overview of the weather. So you'll see there's this under the current section.

We also have a weather description which, of course, gives a nice overview of the weather which I use my email so I can dig a bit deeper into this response body. I will go for, in fact, I will put response body, current then want to get exactly which section of this we want, which in this case is, weather_descriptions. And I'll get rid of that. And now run this over again, I've just got that description there now because this is descriptions, you can tell it's actually a list. When you keep doing many queries at the time, I just want the one item of this list. It's in a string format instead of in a list format. I'm just going to change this to say put item one of. And then if I run that, it would take just the first item of that list in there. And that would be useful for how we put it into our email. Now basically, I just want to stick this into a function that means I can call on it later. I'm going to get whether I'm actually going to pass the latitude longitude in. And I'll copy that through. I'm going to put that into weatherdesc. And I will return that as well. So that is what will be coming out. And I just need to parametrize this bit so that we can query it with any location. And I can do that like so. So that'd be a nice simple way of concatenating that and adding it in. And then lastly, we'll check that it works by log. Get weather, I'm going to use a simple latitude longitude just like that. And you say, we just get that overcast return to us to use later in our script.

The final part of this is just to bring it all together.

So I created a couple of scripts just using sort of simple OCR image recognition to get the longitude latitude cafe name from a virtual machine I've got. And then to send that email on a mobile phone. You'll see the script here. I've put in a function where we pass in the surname of the employee. We'll query the database to get their postcode, we'll then go into Google Maps, find a cafe nearby, find the latitude and longitude of that. Store that, then get the weather based on that latitude and longitude. Store that, get the email once again from the database. And then lastly, put all of those variables into this script that will send an email out. Let's see that running through our good friend Johnson. Already it's done the secret part of things, and it's moving to the virtual machine. And you'll see here it's just going to search for cafe shop near that postcode. It's going to look for one that's over four stars and get the information from that. We would have got the information you've seen from the URL of the Google Maps listing. And then we've connected to the phone just to send out a nice email inviting Mr. Johnson out for a coffee. And then we have it all done.

Thank you for paying attention to that.

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}