I am using the Playwright library to create a program that executes a navigation in a web application by interacting in different ways/actions, with the browser interface. The main purpose of my project is to monitor and gather information about the execution time of these actions.
The only output I receive after an execution of my program is the trace that is saved using the same Playwright library (I'm also logging at the beginning and the end of the execution of a certain group of actions, but the precision is not enough).
In this trace the actions are named after the action type (click, fill, typing...) and the action argument (the locator, for example, the name of a button), this is not a problem when the argument is simple and understandable. My problem is that sometimes the locator, or simply the argument of the action, is not human redable (for example, "textarea[name='textarea-test']").
Is it possible to "label" or rename the action name thay will be saved in the trace.trace file so it can be easily understood, without having to edit the file to change the names?
So it looks like your question has 2 parts. The first part (timing issue), if you need to capture the accurate time between starting an action and finishing an action I would recommend doing this:
long startTime = new Timestamp(System.currentTimeMillis());
//an action goes here
long finishedTime = new Timestamp(System.currentTimeMillis());
long executionTime = (finishedTime - startTime)/1000 //the division is so that it can be read back in seconds
As for the other part (unreadable locators) you can do one of 2 things, you can change the locator to use something else that is more readable for example an ID or create a custom XPath
//div[@value = 'name_input_area']/textarea[@name='textarea-test']
Or you could just name the locator in your code:
Locator textAreaForNameInput = page.locator("textarea[name='textarea-test']"); //this is for inputting a name into the form
textAreaForNameInput.fill("My Name"); //fill in my name
Hope this helps :)