Any way to integrate Robot Framework Selenium Tests with Google Lighthouse?

415 views
Skip to first unread message

Chinmaya Karve

unread,
Apr 20, 2020, 5:51:21 PM4/20/20
to robotframework-users
Hi Community,

Is there any way to integrate Google Lighthouse with RF driven UI tests? The use case is, when a new browser instance is initiated through RF test, I want to initiate Lighthouse analysis of the opened page and stop monitoring when the test is over.

Has this been tried before? Does this make sense> Any way to achieve this?

Thank much!

Niharika Bhatt

unread,
Mar 16, 2023, 8:22:42 PM3/16/23
to robotframework-users
Any update on this??

Premkumar V

unread,
Mar 17, 2023, 1:42:40 PM3/17/23
to niharik...@gmail.com, robotframework-users
  1. Install the Lighthouse Node.js module using the following command:

    npm install -g lighthouse
  2. Create a new RF test case and add the following steps:

    javascript
    Open 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
  1. 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.

  2. 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.

Niharika Bhatt

unread,
Mar 18, 2023, 5:10:33 AM3/18/23
to Premkumar V, robotframework-users
Thank you so much!

Premkumar V

unread,
Mar 18, 2023, 6:12:37 AM3/18/23
to Niharika Bhatt, robotframework-users
Did it works for you?
Reply all
Reply to author
Forward
0 new messages