Imported javascript routine is not recognized as Keyword

Hi

I would like to check, whether a button on the screen is active, or not. I use Playwright, not Selenium.

I would like to check the activity without pressing the button.

This is the javascript code for the check :

async function buttonTest(page, args) {
** const isValid = await page.evaluate(() => {**
** const payButton = document.querySelector(‘.app-pay-button’);**
** return payButton.classList.contains(‘form-is-valid’);**
})
}

exports.__esModule = true;
exports.buttonTest = buttonTest;

I want to import this .js file as described on page A new option for web automation: Using the Robot Framework Browser library, based on Playwright | Robocorp documentation
under section Build keywords with JavaScript

This is how I import it in Robot Framework :

Library Browser jsextension=…/…/Resources/pay_button_test.js

And the way I want to use :

${test_result}= buttonTest
** Should Be True ${test_result}**

The error comes at running : No keyword with name ‘buttonTest’ found.

How can I import/use the javascript function above ?

I thank you for any help in advance !

Hi Fran,

  • one option if you are really set on useing that java script would be to use the Execute JavaScript keyword to call the buttonTest function

  • some another options would be not bother with javascript and just use the existing Browser Library keywords to test the button

Assuming the XPATH //button[contains(@class, 'app-pay-button')] will select the button regardless of whether the button is active or not then you could do this:

${payButtonClasses}=    Get Attribute    //button[contains(@class, 'app-pay-button')]    class
Should Contain    ${payButtonClasses}    form-is-valid

but you could potentially do the entire test with a single keyword by using a more complex XPATH like this which will fail if the button doesn’t have both classes:

${payButtonClasses}=    Get Attribute    //button[contains(@class, 'app-pay-button') and contains(@class, 'form-is-valid')]    class

or even by using the Get Attribute assertion arguments

${payButtonClasses}=    Get Attribute    //button[contains(@class, 'app-pay-button')]    class    contains    form-is-valid

All three of these are possibly easier to use and to read/understand (for future testers maintaining your tests)

Hope this helps,

Dave.

1 Like

Hi Dave,

Thank you very much for the help !

After a little modification of one of your advices, it works !

The following part succeeds :

${payButtonClasses}= Get Attribute //app-pay-button[contains(@class, ‘app-pay-button’)] class
Should Contain ${payButtonClasses} form-is-valid

I have accepted your solution.

Kind regards, Fran

1 Like