-
Notifications
You must be signed in to change notification settings - Fork 3
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
How to run scripts #34
Comments
No worries, that is not at all a basic question (since I kinda droped a bit crome-driver support for this version (and have not update the docs)) Here is how you get it to work git clone git@github.com:o2platform/nwr.git
cd nwr
npm install ... The command to run the version with selenium/chrome-driver support is: coffee src/selenium/app.coffee is because you need to do this (from the README)
for example with: cd node_modules/nodewebkit/nodewebkit/
curl -O http://dl.nwjs.io/v0.11.2/chromedriver-nw-v0.11.2-osx-x64.zip
unzip chromedriver-nw-v0.11.2-osx-x64.zip
mv chromedriver-nw-v0.11.2-osx-x64/chromedriver .
ls now it should be a case of cd ../../..
coffee src/selenium/app.coffee which should look like this: If all went well you should see something like this (with the console log messages confirming that the WebDriver was driving the requests) The script that is shown by default already the main thing that you get from that gist you linked text = "o2platform node-webkit-repl"
browser.eval "window.location.href='http://www.google.com'", ()->
browser.elementByName 'q', (err, element)->
element.clear ->
element.sendKeys text, nop
browser.elementByName 'btnG', (err, button) ->
button.click(text)
value = 'The answer is ' + 42;
return value; For reference here is the updated version of that script (in coffee script) # same as example 91 but written in coffee script
resetToParentFrame = (next)->
browser._jsonWireCall
method: 'POST' ,
relPath: '/frame/parent' ,
data: {} ,
cb: next
select_Frame1 = (next)->
browser.frame('iframe1', next)
open_Search_Google = (text, next)->
resetToParentFrame ()->
select_Frame1 ()->
browser.eval "window.location='http://www.google.com'", ()->
browser.elementByName 'q', (err, element)->
element.clear () ->
element.sendKeys(text)
browser.elementByName 'btnG', (err, button)->
button.click(next)
open_Search_Google 'o2platform', ()->
open_Search_Google 'owasp', ->
return "done" Btw, the script above can sometimes lose the bottom frame (although it will still run), you can get it back by clicking on the back button (or refreshing the window) also if you lose a script that you were writing take a look at #9 |
Btw, I actually found much more powerful (and faster) to execute browser automation commands directly via chrome-remote-debugger, which you can see in action if you run npm run repl-gui or bin/node-webkit-repl gui In that UI you could do something like if (iframe1.contentWindow.location.href.indexOf 'google') is -1
iframe1.src='https://www.google.com'
else
document = iframe1.contentDocument
document.getElementsByName('q')[0].value = 'Node WebKit REPL'
document.getElementsByName('btnG')[0].click() Here are the Node-Webkit window commands/api: https://github.com/o2platform/nwr/blob/master/src/api/NodeWebKit-Service.coffee Here are the chrome commands/api: https://github.com/o2platform/nwr/blob/master/src/api/Remote-Chrome-API.coffee The main use I get from this module everyday is to use it to run mocha tests which use this https://github.com/TeamMentor/TM_4_0_QA/blob/master/tests/API/QA-TM_4_0_Design.coffee to create the environment you can see at https://vimeo.com/116027788 btw there are tons of example in that repo on how to use this NWR module to drive chrome an insane speeds. See for example https://github.com/TeamMentor/TM_4_0_QA/blob/master/tests/API/Jade-API.coffee and https://github.com/TeamMentor/TM_4_0_QA/blob/master/tests/regression-sprint-1.coffee |
@DinisCruz Thank you. Everything works like your described. I'll try to work with this now. |
cool, let me know if you have more questions (don't be afraid to open more issues, even for small things/questions, since that is a great way to document how it works). I'm using it every day, but have not had time to update this (I did start a refactoring which you can see https://github.com/o2platform/nwr/tree/nwr-refactoring which needs more work) |
Hi, I just came across this project and unable to figure out how to use this project.
I want to run the sample script mentioned, https://gist.github.com/DinisCruz/516417b0e70a2ba5e8bb#file-91-multiple-google-searches-js
I installed
nwr
usingsudo npm install nwr -g
.How do I run the script?
node 91-multiple-google-searches-js
does not work.Sorry for the basic question!
The text was updated successfully, but these errors were encountered: