- Notifications
You must be signed in to change notification settings - Fork 781
Added execute_javascript_with_arguments keyword #1147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| Each new functionality must be backed up with tests. I think this one needs few. But before that, I should read more about the JavaScript. |
| I did read the Selenium API and I understand how that works. I agree that having separate keyword is easier in this phase but we should think what shall we do in the long run (not required in this PR). I also noticed that async JavaScript method in Selenium API supports arguments: http://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webdriver.WebDriver.execute_async_script For consistency reason we should create a similar keyword for http://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Execute%20Async%20Javascript |
| Not sure if you have worked out a design but I was thinking that we could use "docstring" markup to delineate the JavaScript allowing for multi-line JavaScript and then have the arguments following the "docstring". This should allow for any JavaScript code and multiple lines. It might also be helpful to provide a warning if an argument is not called out in the JavaScript. I do like, at least in the interim, have keywords named |
| You mean something like Pekka did propose in the #323 that keyword signature is That |
| I need to review Pekka proposal but I was thinking something like @horsewithnoname1985, what do you think? |
| Here is the comment that I was referring: #323 (comment) But it would be tempting to keep support for variable number of lines for the code and arguments. |
| Taking that example what I was thinking the markup, if you will, be would be where the docstring style is used to delineate a single argument. This of course was wishful thinking on my part. Here is my unit test to see if what I was thinking may be part of the robot framework language or if this idea was possible noting of course that This solution that I propose starts to take into consideration the concept of an object type - docstring - just as there are number variables or boolean variables. |
| Now I see your idea. The basic idea is to have keyword which has one The more I think about the idea, the more I like it. Would have to agree only with the marker. It should be clear and something which is not already reserved by Robot Framework or by JavaScript. |
| Yes, the same with a different marker. In my mind I do see a design where the triple docstring quotes would delineate into a single argument. So one could have whatever text in a docstring, like This, support of docstrings in robot framework, of course may not be widely useful and this may be a "extractive idea". |
| Hmmm. I would prefer a single marker, something similar that is used for |
| Sorry for the little mess I made with the recent commits here. I like the idea of supporting multiline JavaScript code. Enabling this by putting the code inside a docstring seems very straightforward, so I support that. I’d still prefer a keyword with two arguments though, where the first argument is for the (multi-line) JavaScript code and the other's a varargs for all passed in arguments, instead of assigning the first of multiple arguments as the code: As for the delimiter: Maybe a multi-line JavaScript code can be defined in the But I haven't tested that |
| The down side of two arguments is that then we lose capability to define JavaScript inline. Example this is not anymore possible. Instead the code should be created as a list with a separate keyword and that is a down side. Example something like this: In long term, this causes a big backwards compatible issue and means that it's almost impossible to to join the two keywords together. Therefore I am now against the two argument implementation. As a second issue, we should first decide one separator and not to support multiple different separators. Like the zen of python says: There should be one -- and preferably only one -- obvious way to do it. https://www.python.org/dev/peps/pep-0020/#id3 I am somewhat against the docstring, because the reasons I did explain above. Instead I would like to see something which is similar than what |
| The problem with the commits is easy to fix. Are you able to fix it by yourself or do you need help with it? If you need help with with it, would you be able to do |
| Seems the error has resolved already. How about using the backslash, like in the FOR LOOP syntax, here: Execute JavaScript ... :JAVASCRIPT ... \ element = arguments[0]; ... \ original_style = element.getAttribute('style'); ... \ element.setAttribute('style', original_style + "; background: yellow;"); ... \ setTimeout(function(){ ... \ element.setAttribute('style', original_style); ... \ }, 300);If used with arguments, those could be integrated either via a 'ARGUMENTS' attribute like this Highlight Element [Arguments] ${locator} ${unused_js_arg} ${element}= Get WebElement ${locator} Execute Javascript with arguments ... :JAVASCRIPT ... \ element = arguments[0]; ... \ original_style = element.getAttribute('style'); ... \ element.setAttribute('style', original_style + "; background: yellow;"); ... \ setTimeout(function(){ ... \ element.setAttribute('style', original_style); ... \ }, 300); ... ARGUMENTS ${element} ${unused_arg}or preferably like this Highlight Element [Arguments] ${locator} ${unused_js_arg} ${element}= Get WebElement ${locator} Execute Javascript with arguments ... :JAVASCRIPT ... \ element = ${element}; ... \ original_style = element.getAttribute('style'); ... \ element.setAttribute('style', original_style + "; background: yellow;"); ... \ setTimeout(function(){ ... \ element.setAttribute('style', original_style); ... \ }, 300); ... ARGUMENTS ${element} ${unused_js_arg}or even automatically imported into the JavaScript Highlight Element [Arguments] ${locator} ${unused_js_arg} ${element}= Get WebElement ${locator} Execute Javascript with arguments ... :JAVASCRIPT ... \ element = ${element}; ... \ original_style = element.getAttribute('style'); ... \ element.setAttribute('style', original_style + "; background: yellow;"); ... \ setTimeout(function(){ ... \ element.setAttribute('style', original_style); ... \ }, 300); |
| I am on mobile and need to take a look with device that has a bigger screen. |
| The first marker, But it would allow to change the order of the JavaScript code and arguments, example like this: Similar feature request was asked/proposed in the issue. But I do not see benefit of supporting the FOR like syntax and using I am thinking, would this be good proposal.
The point 4 is optional and largely depends which way is the implementation better, with the support or without it. What others think, @emanlove and @horsewithnoname1985? |
| Did forget to say that in this way, we do not need a new keyword and the new feature can be implemented with the existing JavaScript keywords. The change is backwards incompatible but it is unlikely that someone would have |
| I agree with the idea that docstrings is a bad idea and I like yours and Pekka's idea for ARGUMENTS as a delimiter (No. 2). |
| I also approve the ARGUMENTS marker and I also would very much appreciate the JAVASCRIPT marker to switch order, as it is more natural that arguments are defined before using them. @aaltat , I agree, that these feature are probably better implemented into the existing keywords instead of creating new ones. |
| It looks like we have an agreement. Lets go with the |
Adds ApprovalTests support the project.
| The support for ApprovalTests is added. The ApprovalTests now works with pypy and for Jython the tests must be skipped. There is an example in the test_javascript.py file. Although the reporter might require some tuning, to make it more configurable for different OS and needs, the basic idea works. Would you be willing to continue the work for the PR? |
| @horsewithnoname1985 Is there any progress on this PR? |
| @aaltat , sorry for my very late reply. I also had a holiday break. Yes, I will continue on this PR within these days. So I assume the unit tests using approvaltests for the new keyword are fine? Then I will work on the keyword implementation logic as you suggested on July 27th. |
| No worries, holiday should be spend in the sun rather than coding. I did also play with the ApprovalTest, just because I wanted to learn more about them and #1176 shows what I did have in mind. Please note that the I think you misunderstood how Your unit test do not have error testing. I did write some examples, how error handling can be tested by using ApprovalTests. Also there are missing test, from me and you, like reading the JavaScript from file. But because master has moved forward, there are few few conflicts which needs to be sorted out. Also your PR contains few commits which are already in master and should not be part of this PR. Are you able to sort out the problems or do you need help? |
…ipt_with_arguments keyword (will eventually be copied to execute_javascript keyword) added proper acceptance tests
…t with arguments' keyword ADD: a few more atests for above keyword
added approvaltests for execute_javascript_with_arguments keyword added another acceptance test for same keyword
Conflicts: .travis.yml requirements-dev.txt src/SeleniumLibrary/keywords/javascript.py utest/test/approvals_reporters.json utest/test/keywords/test_javascript.py
| Hi @aaltat , I see your point and will have a look on these tests next. I saw your def test_get_javascript(self): code, args = self.javascript._get_javascript_to_execute('code here') ...to def test_get_javascript(self): code, args = self.javascript._get_javascript_to_execute(tuple(['code here'])) ...? |
| Changing the unit test is fine, although I would change it like this: The Travis problem is related to your PR: how you solving the conflicts. But that is actually a small problem compared to the problem that the commit history in this PR is mixed, meaning that commits which are already merged in master are somewhere in the between of your commits. In practice, this commit tries to rewrite the history of SeleniumLibrary and that is not acceptable, because it will lead to greater problems. Instead commit history should be: all commits which are in the master are in the bottom of the There is at least two ways to fix the problem: cherry-pick and rebase. By quickly looking, I would assume that cherry-pick might be the easiest way, but I am not sure. Are you able to solve the problem or do you want me to do it for you? |
| Closing in favor of #1176 |
| Hi @Tattoo , sorry for not dealing with this issue in time. I see you moved this issue into a less confusing PR |
| @horsewithnoname1985 I'm not @aaltat :) |
| No worries. I did try to recover the commit history from this PR, but it was actually quite a big task. Therefore I did decide to create a new one. |
Added PR as discussed in
#323