Adding New Framework Features with Copilot Agent | Bondar Academy
Course: Playwright API Testing with TypeScript
Module: AI-Assisted Scripting with Copilot
Instructor: Artem Bondar
Lesson Summary
In this lesson, we explore how to leverage AI and Copilot to enhance existing frameworks by adding or updating features efficiently. Key Concepts The focus is on a utils file named schema validator.ts , which validates and generates schemas. Currently, manual edits are required for schema formats, such as adding date and time formats, which can be inconvenient. The goal is to automate the addition of format properties based on the API response. Implementation Steps Identify the need for additional logic in the schema generation process. Use Copilot to assist in writing the necessary code by providing context and specific instructions. Formulate a prompt for Copilot to check for properties like created_at and updated_at and to add a format property if they exist. Review the code generated by Copilot, ensuring it meets the requirements. Best Practices Do not blindly accept AI-generated code; always review and understand it. Use AI not just for speeding up development, but also for enhancing your coding skills. Invest time in understanding the generated code to improve your own knowledge and capabilities. By following these practices, developers can efficiently enhance their frameworks while also growing their skills.
Video Transcript
Hey guys, welcome back. And in this lesson, I will show you how to leverage AI and Copilot to update the features of existing framework or add new features to your framework to save a lot of time. All right, so let's jump into it. So in our framework, we have a utils file schema validator.ts. So this file is responsible for basically two operations, to validate the schema and generate the schemas automatically if we don't have a schema. The generation of the schema happens based on the response. But we know that if we want to use the AGV format, the formats edit manually to the file. For example, over here, we added formats date and time. If we run this test and regenerate the get article schema again, this values will be wiped out from the schema and we need to add them back again. So it's quite inconvenient, right? So if you want to use the formats automatically added to your schema, for example, if our response has created add, which is related to the date, we want not only validate the type that this is a string, we also want to validate the format. And we want this value added to the schema automatically, instead of adding this later manually. Currently, the logic in our application over here generates schema doesn't have it. So it's just generating the schema just by default and writing this file right away. So technically somewhere right here, we need to add a logic something like this. Like, hey, parse the entire JSON object and if you have created add or updated add keys inside of the JSON object, add additional property format with the value date time. So that's the logic that have to be added over here. From one perspective, you can figure this out by yourself, right? So you can spend two, three hours parsing the JSON, trying the different code options, googling some stuff. But on the other way, you can ask Copilot to add this feature because we can feed the context about our application, give the task what we want to do and ask, hey, do this small change for us. So let's do it using a Copilot. So going back to the Copilot in the agent mode. And first of all, let's add some context to it. So I want to add open editor, so everything what is open. Right now we have schema, we don't need smoke test.spec.ts. We want to add schema validator. I will remove the duplication of the JSON file. So we need a JSON file schema validator. And also let's add the instruction created before related to schema validation. So let Copilot know what the schema validator is about, how the schema validation works in our framework. And now let's just give a task and explaining what we want to do. So writing the prompt in the agent mode. What do we start with? Okay, we have methods. Method generate new schema in the file schema validator.ts responsible for generation of new schema, schema based on the response from API. Then what we want to do before writing the schema to file, I want you to add the logic to check if the schema have properties. Properties, the properties we are looking for created at, have properties created at and updated at. Okay, if the property exists, add a new property format date time next to the type. Next to the type. I think it's descriptive enough. And let's provide the example. Example, and let's provide the example of the object that we are looking for. So an example and like this. So let's check it one more time. So before writing, I want you to add the logic to check if the schema have properties created and updated at. If property exists, add the new property format date time next to the type. Example, I think it's good enough. So let's try to run this prompt and see what's going to happen. All right, so it is thinking about the logic. Let's check this out. All right, so and it figured out a function for us at date time format right here. So look, it is checking if it is object or schema is null. If null, just return nothing. Also, it adds a logic if the response is an array instead of the object, just to make sure. So it will loop through each value of the array and call itself. It's called recursive function. And at the end, if this is an object, it checks the type of the object schema properties. If the key at an updated at has value any type of string and format at date time. So it looks good to me. And it's also added this function exactly where it have to be. So I think all we have to do is just trying to run this and see if it is working. So for the validation, I think we can use this post article schema. And post article schema currently does not have the created at or updated at data format because it's using just a standard generated schema. But with our new logic, it should update a schema with a new format. So let's check this out. We need to find create an update article and let's generate a new schema running this test. Not test, it should be true. Okay, true, let's run this test. Okay, test is executed. Let's check it out. Was it updated? And yeah, look, our logic worked perfectly fine. So created at added a new value of format, date and time and updated as well. So now we can go back, remove the true, run this test one more time and it should pass validating our new format for the post request. Post article schema as well. All right, guys, so this is how you can use AI and Copilot to speed up the framework development. Of course, you could spend probably a couple of hours to figure out the parsing of JSON by yourself, but why spending this time if the new technologies can help you with this, right? So leverage AI, use it to add new features, improve the existing features of the framework. The only ask that I have is that don't blindly approve all the code generated by AI. Try to understand what is generated. If you don't understand the code that is generated, ask AI to explain you what this code is doing. By understanding this, you first of all can improve the code by yourself. You can delete what is not needed, what is irrelevant to your actual logic. And the second thing that by understanding the code, you invest in yourself, first of all, in development of your real coding knowledge and your real coding skills. And trust me, this is way more valuable than just speeding up the framework development or just completing the ticket in your dashboard. So invest in yourself and use AI for speed up learning as well, not just for speed up development. So that's it and see you in the next lesson.