From the course: Software Testing: Exploratory Testing
Scripting with AI
From the course: Software Testing: Exploratory Testing
Scripting with AI
- [Presenter] In the last couple of videos, I've challenged you to try scripting some things. You can use scripts to generate some data or search through logs or even help you explore. Writing short scripts that don't need to fit a whole code base is one of the things that Lms can be fairly good at. So I'm gonna zip through an example that shows ChatGPT and Copilot set up in Visual Studio Code. I don't have time in one short video to walk through how to set up tools like this, but there are many other courses on this platform and in other places that can walk you through this kind of setup. I hope my example will inspire you what the possibilities are once you get those tools set up. So let's try it out and see what it could look like. We're going to use this parking calculator site and see if we can figure out what's going on with the times and some of the weird behavior that we've seen there. So I'll paste a prompt in here where I'm asking it to write a Python web scraper that I can use to input a bunch of different exit times and extract that data into a CSV file. Now I have given it some additional information here as well. So I've given it, this is what the form data looks like on the way in, and this is what the response data looks like on the way out. I got that by looking at the developer tools and then sending a request. And then here on the request I can see the source. So this is form data, this is the source, the payload that's being sent to the server, and then this is the response. And so for both of those, I just copied them and included them in the prompt. So let's copy the code for this. And here in visual studio code I'll add a new file and I will save it as parking_scraper.py and we can try running it. So Python parking_scraper.py, and you can see that it has NA here. Now I believe the reason for it is this cost tag is extracting the same way as the duration tag, but if we are to look at the actual results here, you can see there's a strong tag inside of there. So what I've done is I've asked ChatGPT if the strong tag is breaking things for it, and it says, 'Yes it is." And it suggests a couple of fixes for me. So it says you can find the ptag directly like this or a couple other things and it has this cleaner version of drop-in replacement. So let's try this one. Let's copy this code. And you can see that this code here is getting the duration and the cost. So let's replace this with that. And with Python you need to have proper indentation. So we'll try that. Let's save it and try running this. I can see that it now has got the estimated parking costs as we expect. This one is probably just an invalid time. It's before the the entry time. So let's try one more thing. Let's see if we can clean this up a little to just give us the dollar value, not all of this text. So here I will, "Can you get this to extract just the dollar value?" Okay, let's accept that and save it again and try running it again. And now we're getting just the dollar value and it says it saves these results to parking results.csv. So let's try opening that file and we can see that we've got it here in a nice table. We've got our exit dates and times and the dollar values in the number of days and so forth that we want. From here we could do some additional things. You know, we could extract those dates in a nicer format. We could add ourselves manually or even with a script to add a whole bunch of different ones. So we could try out a bunch of different combinations. But with that, you know, in a matter of a couple of minutes, we are able to generate a script that let us do some experimentation on this that we wouldn't be able to do otherwise. And that's the power of using AI to help you out with exploratory scripting.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.