-
Notifications
You must be signed in to change notification settings - Fork 48
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
JsModifier - Running JavaScript command as in the browser console. #69
JsModifier - Running JavaScript command as in the browser console. #69
Conversation
Hi @Pnad .. going forward please consider making "JavaScript Collector"... which would gather output of executed JavaScript Command and then 'source comparator' could be used to compare that output. |
@Override | ||
public CollectorStepResult collect() throws ProcessingException { | ||
if (LOG.isDebugEnabled()) { | ||
LOG.debug("Execute JS cmd: {} on page: {} properties url: {}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
properties.getUrl() x2 ?
((JavascriptExecutor) driver).executeScript(cmd); | ||
|
||
result = CollectorStepResult.newModifierResult(); | ||
} catch (Exception e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to always return result even if something went wrong we want to have this information on report not just in logs.
please return newProcessingErrorResult as a result with message from WebDriverException (catch it first)
|
||
result = CollectorStepResult.newModifierResult(); | ||
} catch (Exception e) { | ||
throw new ProcessingException("Can't execute cmd = " + cmd, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider changing 'cmd' to something more meaningful e.g. 'Can't execute JavaScript command'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @Pnad !
Thank you for your contribution.
I've added some comments in this Pull Request.
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class JsModifier implements CollectorJob { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check formatting in this class - AET project follows those coding conventions. Please apply google styleguide.
|
||
public class JsModifier implements CollectorJob { | ||
|
||
public static final String NAME = "js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modifier named js
is not very descriptive. How about renaming it to execute-js
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imho shorter is better in this case -this will be used as a tag in xml suite and probably 'cmd' value will be long as hell ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree. We already have js-errors collector. It may be misleading having js
tag.
I suggest renaming cmd
param to script
also.
About long script - I thought about this some time ago and there is just an idea, how about providing script as a web resource and script
value should be just a link for it?
E.g.
<execute-js script="http://my-site-to-test/aet/some-script.js" />
This solution has its disadvantages, however it will not obscure the suite XML definition.
@@ -0,0 +1,88 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a documentation for this modifier. The instruction how to do this can be found in our contributing rules.
You should create a new page in documentation
module.
ParametersValidator.checkNotBlank(cmd, "cmd parameter is mandatory"); | ||
} | ||
|
||
public CollectorStepResult jsElement(WebDriver driver, String cmd) throws ProcessingException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change method name to e.g. ''executeJavaScript"
Hello @Pnad, |
@Skejven Yes, I'm going. |
…ser console. ___ I hereby agree to the terms of the AET Contributor License Agreement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, Check the current version.
The changes I made on the basis of the existing code (HideModifer).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Pnad for fixes.
The last thing missing are integration tests.
Please see tests that existing modules already have:
https://github.com/Cognifide/aet/tree/master/integration-tests/test-suite/partials
And try add one for this modifier.
E.g. change some random value to constant one with js script before taking screenshot, so the test will pass.
Example of the test could look like this:
<open />
<sleep duration="1000" />
<executejavascript cmd"..."/>
<screen />
|
||
import java.util.Map; | ||
|
||
import static org.mockito.Mockito.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use *
imports.
} | ||
|
||
@Test | ||
public void ExecuteJavaScriptModifier_HideElements() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure... What this test proves exactly?
I don't have much experience in AET and java. I created the code analogously to AET code. |
JsModifier - Running JavaScript command as in the browser console.