selenium-ide icon indicating copy to clipboard operation
selenium-ide copied to clipboard

Allow plugin to access variables

Open ChrisLMerrill opened this issue 5 years ago • 13 comments

🚀 Feature Proposal

The plugin support should allow plugins to access variables.

Motivation

My plugin collects data during the test which the test author might like access to. If I could access variables, then I could implement a store data command.

Example

My plugin allows test authors to measure the duration of events. If I could store a result in a variable, then the test author could use assert to fail a test if the site is too slow.

ChrisLMerrill avatar May 17 '19 13:05 ChrisLMerrill

Does the absence of this feature mean that it is impossible for a custom command to pass information back to the IDE to be used in other commands? Is there any work around?

darichey avatar Aug 08 '19 21:08 darichey

Plugins can set a variable, but they can't ask selenium IDE for the value, we should add a getter.

corevo avatar Aug 08 '19 21:08 corevo

Sorry for polluting this issue, but is there docs on setting? I'm struggling to find them.

darichey avatar Aug 08 '19 21:08 darichey

I don't see one either. We'll need to add it.

tourdedave avatar Aug 11 '19 07:08 tourdedave

Do you mean just that the documentation is missing, but the functionality is present? If so, can you point me in the right direction for getting this working? Thanks.

darichey avatar Aug 12 '19 14:08 darichey

Found it.

browser.runtime.sendMessage(seleniumExtId, {
  uri: "/playback/var",
  verb: "put",
  payload: {
    name: "my_var",
    contents: "value of var"
  }
})
.then(() => sendResponse(true))
.catch(console.error);

return true;

Would be great to get documentation on this page.

darichey avatar Aug 12 '19 15:08 darichey

Yes, that's the one. I'll get it added to the docs.

tourdedave avatar Aug 13 '19 05:08 tourdedave

@tourdedave @darichey @corevo can anyone of you please post a working example. So I successfully added a chrome plugin, my plugin is visible in command list of selenium ide, When I select my command and run, it returns a proper value but I am unable to stored that returned value in variable. So can you please advice me how to achieve this. Here I attach my background.js and manifest.json for reference. Your response will be appreciated. Thanks!

manifest.txt background.txt

Shreypatel07 avatar Nov 27 '19 18:11 Shreypatel07

You can't put a variable unless a playback started, your code tries to do it even before the plugin registered.

corevo avatar Nov 27 '19 20:11 corevo

@corevo Thanks a lot for your prompt response, So as per your suggestion, I have made changes to my script file and now I am adding variable after playback started. But now I am getting "Selenium IDE: Unable to add variable fname" error. For your reference I have attached my script file. Thanks!

background.txt

Shreypatel07 avatar Nov 27 '19 21:11 Shreypatel07

Same problem for me. I'am also getting "Selenium IDE : Unable add variable xxx" error.

krichtof avatar Apr 03 '22 14:04 krichtof

From the code reference shared by @darichey , looks like the put fails if the contents is not a valid JSON. That means the variable needs to be a Object rather a String, which makes it more par to store JSON command, rather than just plain store.

Found it.

browser.runtime.sendMessage(seleniumExtId, {
  uri: "/playback/var",
  verb: "put",
  payload: {
    name: "my_var",
    contents: "value of var"
  }
})
.then(() => sendResponse(true))
.catch(console.error);

return true;

Would be great to get documentation on this page.

The below code works but is there a way to put raw String instead of JSON? Checking if any variable getters were added anytime recently?

browser.runtime.sendMessage(seideId, {
    uri: "/playback/var",
    verb: "put",
    payload: {
        name: "var1",
        contents: "{\"complex\" : \"varObject\"}"
    }
}).then(() => {
    console.log("Successfully added variable.")
}).catch(console.error);

pratikritwick avatar Nov 13 '23 10:11 pratikritwick

@pratikritwick - Because of the basically insurmountable permission changes of Manifest v3, nobody has committed anything to v3 in a while. It's pretty darn near end of life. V4 is under development as an electron binary here:

https://github.com/SeleniumHQ/selenium-ide/releases/tag/4.0.0-alpha.56

If neither of those appeal to you, I'd recommend the nightwatch js browser extension for the chrome devtools recorder.

toddtarsi avatar Nov 13 '23 14:11 toddtarsi