Install the Lighthouse Node.js module using the following command:
npm install -g lighthouse
Create a new RF test case and add the following steps:
javascriptOpen Browser https://www.example.com chrome Execute JavaScript lighthouse('https://www.example.com', {output: 'json', logLevel: 'info'}).then(results => console.log(JSON.stringify(results))) Close Browser
In the above code, we are using the "Execute JavaScript" keyword to execute the Lighthouse command to analyze the performance of the web page. The output of the Lighthouse command is in JSON format and is printed to the console.
You can also use the RF "Run Keyword If" keyword to run the Lighthouse command only when the test is initiated and stop monitoring when the test is over. For example:
bash${browser} Open Browser https://www.example.com chrome ${lighthouse_command} Set Variable If '${TEST NAME}' == 'My Test Case' lighthouse('https://www.example.com', {output: 'json', logLevel: 'info'}).then(results => console.log(JSON.stringify(results))) ${EMPTY} ${lighthouse_output} Execute JavaScript ${lighthouse_command} Log ${lighthouse_output} Close Browser
In the above code, we are using the "Set Variable If" keyword to set the Lighthouse command in a variable only when the test case name matches "My Test Case". The Lighthouse command is executed using the "Execute JavaScript" keyword and the output is printed to the log file.
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/robotframework-users/eed7c168-960f-4a94-a736-9307c66b57f7n%40googlegroups.com.