This thread is trying to answer question "Why is the script saving the current date instead of a date two years from now?"
Related Ask AI answer for "How do I save a date two years from now in a script using Playwright?".
If you're wondering why your script is saving the current date instead of a future date, it's likely because there's no code telling it to do otherwise. To save a date two years from now, you need to add code that calculates this.
Here's how you can do it using TypeScript:
// Get current date const currentDate = new Date(); // Add two years const futureDate = new Date(currentDate.getFullYear() + 2, currentDate.getMonth(), currentDate.getDate()); console.log(futureDate);
Date object to get the current date. Then, we're adding two years to the current date by modifying the year component. We do this using the
getFullYear() method. Finally, we create a new
Date object with the modified year value.
Remember, without more information about your script, it's hard to provide a solution tailored to your situation. If you can provide more details about your script and where you expect a future date value, I can help you find a suitable solution.
For more tips on writing efficient Playwright test scripts, check out this blog post.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email firstname.lastname@example.org.