How to code Selenium-Java with ChatGPT

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in today's video we're going to talk about using chat gbt to Aid coding so chat gbt aided coding refers to the practice of leveraging the chat GPT language model to assist with various aspects of software development and coding tasks this involves using chat GPT to generate code Snippets explain complex programming Concepts debug code provide recommendations for best practices and even help with testing and documentation the goal of chat GPT AED coding is to enhance productivity improve code quality and simplify the development process for programmers of all skill levels code generation so chat GPT can generate code Snippets based on user prompts this can range from simple functions to more complex algorithms depending on the user's request and specificity of the instructions provided you can also use chat GPT for code explanation and learning it helps in understanding code by explaining programming Concepts language syntax and the functionality of code Snippets this is particularly useful for beginners or developers working with unfamiliar languages or Frameworks you can also use chat GPT for debugging assistance chat GPT can assist in identifying errors or bugs in Code by analyzing error messages or reviewing code Snippets it can suggest potential fixes or point out where things might be going wrong some other things you can use with chat GPT is best practices and recommendations it can offer advice uncoding best practices design patterns and performance optimization techniques this guidance helps ensure that the code is not only functional but also efficient maintainable and scalable you can also use chat gbt to create test cases and scenario generation in the context of software testing chat gbt can help generate test cases and scenarios including providing test data sets which are crucial for ensuring the application behaves as expected under various conditions and finally you can use chbt for documentation and comments for example you can generate documentation or comments for code to make it more understandable and maintainable is another area uh that you can use and so those are some basic things that you can do with chat GPT but there are much more things you can do um and we're just going to be covering those things that we mentioned but first in order to for J chat GPT uh to Aid selenium coding you have to have selenium Java installed on your computer after you do that make sure you can download and install the intell J IDE and this is from jetbrains so if you don't have it already just go to Jet brain's website and search up intellig and install it for your system configurations because we'll be using intellig in our project today next what we're going to be do uh is we're going to install chpt plugins and this is why we need intellig IDE because inside the intellig IDE we're going to install a chat gbt plugin called easy code and we'll walk you through the steps on how to do this later but in general you can just go to your file settings and the plugins and then you can search for the chat GPT plugin and also you can view your different plugins by going to view tools Windows and then chat GPT to see your plugin and then uh because chat GPT uh might not be accessible to everybody sometimes you might have to sign in to your chat GPT account to see if it's uh to get everything configured properly okay so now I'm going to show you how you can use chat GPT in your own project for selenium Java so the first thing I have here is I have my intell J IDE open and so I'm first going to show you how you can get the plugin for chat GPT so I have it right here but for those that don't have it already you just go to file and then you'll go to settings and then you'll go to plug-in right here and you can just search up chat GP uh GPT so I have it right here and it's chat GPT D easy code and since I already have it installed this says disable but for you that don't have installed you can just click install and this should work there are other chat gbt ones as well uh these other plugins I haven't tried it personally myself because some of them require you uh to pay some sort of monetary value um but once you have this chat GPT plugin installed you can go ahead and close this and then you can go to your view you can go to your tools window and then you can click on chat GPT and you'll open up this chat GPT here so the first time you open it up it'll usually ask you to sign into your chat GPT account since I've already signed in it's not asking me to do that um another thing is note that on this chat GPT account I've actually paid for GPT 4 and you might only have GPT 3.5 but all it uh should have the same functionality so I'm going to stay at the easy code window right here and before I show you how I can use chat GPT I just want to show you how I set up this project so first thing I did to set up this project is I'm using junit uh in my main test folder so under my project my test one I created a test folder and then under Java I created test one and in this test folder I created a before test and after uh and test and after which is the standard format for a junit project note that because I'm using for example sonum Java junit and all those different type of packages I'm going to have to update my pal. XML file like you always do and so for example in here I have my palm. XML uh commands uh for selenium Java junit I also have it for some other things in here as well um but for those that are not familiar how to do this I would suggest you go to the Maven website and they have these commands that you can just paste into your pmda XML file and it'll basically allow you to configure your space and build your project okay so now that we're done with setting up all those things we can go back to our test project right here and then um so for this test project I basically created some general framework of it so I have the setup uh function I have the we function the chat GPT function and the tear down function and what I want to do is I want chap GPT to write this for me so I have some basic things right here um and so uh let me show you how we can do this so first I'm going to delete all the code that we have and then for those that I've commented out that will basically serve as a reference to see if we've done the right thing so the first thing we want to do is we want to work in the setup function and in the setup function the main thing we want to do is we want to set the Chrome driver so that later on we can use the Chrome driver to access various different websites so what I'm going to do is I'm going to highlight this commented line right here I'm going to right click I'm going to click ask GPT but before I do that uh I want you to note that right here under easy code tab there's a check ask codebase if this is not already checked make sure you have it checked because if you don't have a checked then it won't give you code in response so again I'm going to highlight this I'm going to right click I'm going to say ask GPT and I'm going to write write code that's what I'm going to say I'm press enter and now it'll basically write some code for us and so for this right here um we see that it's giving us some general things and um again this is going to require a little bit of knowledge of selenium Java but this the purpose of this is just to speed up it's not to replace the coding process but just so that you don't have to write any everything by yourself and you don't have to know all the syntax by yourself but uh I'm going to go ahead and copy what they have here I'm not going to copy driver quit because that's something that you typically include in the end of your project so we'll include that in our tear down but I'm going to copy what I have here and I'm going to paste this and I paste it over so now we see that they have system. set property and you're setting the property to web Chrome do web driver. Chrome and this is not ideal you don't use this in the most recent versions of selenium and so I'm going to go ahead and delete this actually uh so I know that it's not ideal because of my knowledge of selenium so I'm going to delete that we won't need that and then another thing is in this project already we created a variable web driver driver inside the uh scope of the class so within this function we don't actually have to uh do this so we can just say uh the driver we'll delete the web Driver part and we'll just do driver is equal to new Chrome driver and now this should be able to open a chrome driver and we don't have anything else in here so I can actually go ahead and I can um I can test this so I'll just go here um and then I'll basically just run this and what it should do is it should just open a chrome driver for us and that's it and actually it does so it opens a chrome driver and it passes so it says test pass so go ahead and close this now we can move on into the uh the test function that we will have so under the test function what we want to do is we want to go to this URL uh as the first step so what I'm going to do is I'm going to highlight this again right click and I'm going to tell it to write code again uh and this time uh we'll let some time so uh if we see on this window right here it has what we specified earlier so it has the web driver Chrome driver but it also has this line right here which is is really what we're interested in so I'm going to go ahead and copy that copy that and I'm going to paste it under here and we see it says driver. getet IDM Lucid Golf and that's the exact same as what we had earlier that we commented out so we know that it's right um I'm not going to test this yet because we already know it's right but I'm actually going to copy and paste this copy this one and then right click again and say write code again and I'm going to tell to search for Tiger a on the website so we see again it generates some new code I'm going go ahead and I'm going to copy all of this and I'm actually going to paste under here and so there's a few things we have to note the first thing is right here um it doesn't know the attribute or or the uh the locator for uh the place that we want to search the input and so it just uses search but we know that it's uh the locator is actually search screen uh for the name and how do we know this well again we can always go to our website right here so this is our website we can rightclick the element and then we can click inspect and we see that the name is search string right here so go ahead and close that so we're replacing it with search string right here and then it says sending Keys tiger a and then it's using return instead earlier before what we had was we actually located the button and did send Keys return but this should work as well so if I go ahead and I right click this and let's see if it works give it some time to run and basically it opened up this browser right here it searched up tiger a it found the golf course and we see that the test passed so yeah so jav gbt it it wrote everything we wanted it to write although it's not perfect but it did speed up the process by a lot more so after you finish that uh I'm going to show you something else you can do with chat GPT so I'm actually going to show you an old project that we have right here and the first thing I'm going to do is for example I'm going to go to this uh this class right here and I'm just going to copy or maybe I'll go to another one I'll go to login one right here uh and I'll go to this one right here we know that what it does is it logs in and I'll basically ask what does this uh function do and basically this code uh this uh chat GPT will tell you exactly what this function does for example clicks on a link with the text login enters the email address enters the password and then clicks login so uh uh we know that this is a very simple example but we just see the power of what chbt can do with more complex functions there's some other things you can do as well for example with chpt if I go ahead and hover this uh and right click this there's actually you can actually refractor the code so basically what this means is CH GPT will uh fix up your code if it's a little bit messy and make it into a more readable and more uh more presentable format and this is really good if uh you were just typing some draft code and um you just had your ideas all over the place but you wanted to clean it up afterwards you can also use chat GP to write unit test so to test your code um and these are all things that you can explore on your own time or you can use custom prompts right here for example you can tell it to do some other things maybe create documentations and so on but in the end yeah this is what chat gbt can now do um and this is what people have been using chat GPT for um to basically Aid themselves into um uh into creating their own projects uh in today's video we showed an application of chat GPT and creating your own selenium Java automation testing project uh if you found this video interesting and helpful please give this video like and follow our channel uh and yeah we look forward to seeing you next time uh thank you
Info
Channel: Test Automation 101
Views: 1,292
Rating: undefined out of 5
Keywords: Selenium Java, ChatGPT, AI in programming, AI for coding, How to use ChatGPT, ChatGPT tutorial, Automated web testing
Id: MAF15GPLCns
Channel Id: undefined
Length: 14min 39sec (879 seconds)
Published: Mon Apr 08 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.