Last active
May 6, 2023 00:23
-
-
Save DinisCruz/516417b0e70a2ba5e8bb to your computer and use it in GitHub Desktop.
chrome-remote-interface test scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'fluentnode' | |
| #node ./node_modules/mocha/bin/mocha --compilers coffee:coffee-script/register --recursive -R list tests | |
| wd = require('wd') | |
| chai = require("chai"); | |
| getBrowser = (next)-> | |
| chaiAsPromised = require("chai-as-promised") | |
| chai.use(chaiAsPromised) | |
| chai.should() | |
| chaiAsPromised.transferPromiseness = wd.transferPromiseness; | |
| driver = wd.promiseChainRemote() | |
| driver.sessions (err, sessions)-> | |
| sessionId = sessions.first().id | |
| browser = driver.attach sessionId | |
| next(browser) | |
| describe 'test-WebDriver', -> | |
| it 'testing web-Driver', -> | |
| getBrowser (browser)-> | |
| browser.title() | |
| .then(console.log) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cheerio = require 'cheerio' | |
| processHtml = (html)-> | |
| localStorage['_html'] = html | |
| $ = cheerio.load(html) | |
| show($('a')) | |
| console.log($('a')) | |
| if not (localStorage['_html'] == null) | |
| setTimeout (()-> processHtml(localStorage['_html'] )), 200 | |
| else | |
| _browser.get('http://localhost:1337') | |
| .eval('document.body.innerHTML') | |
| .then(processHtml) | |
| return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async = require('async') | |
| elements_Attribute = (name, elements) -> | |
| values = [] | |
| get_Attribute = (elementId, name, next)-> | |
| _browser.getAttribute elementId, name, (err, value)-> | |
| values.push(value) | |
| next() | |
| async.each elements, ((element,next)->get_Attribute(element.value,name,next)), ()-> | |
| log(values) | |
| #_browser.elementsByTagName 'a', (err, elements)-> | |
| # elements_Attribute('href',elements) | |
| #return | |
| text = "webkit-repl" | |
| _browser.get('https://www.google.com') | |
| .elementByName('q').sendKeys(text) | |
| .elementByName('btnG').click() | |
| .elementsByTagName('a').then (elements)-> | |
| elements_Attribute('href',elements) | |
| return 'loading data' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //newWindow() | |
| $(iframe2).height('100%') | |
| _browser.get('http://www.google.com') | |
| .elementByName('q') | |
| .sendKeys('o2 platform') | |
| .elementByName('btnG', view) | |
| .elementByName('btnG') | |
| .click() | |
| //_browser.get('http://127.0.0.1:1337') | |
| //after fixed https://github.com/o2platform/webkit-repl/issues/2 this can now be executed in the main window | |
| _browser.get('http://www.google.pt' ) | |
| .get('http://news.bbc.co.uk' ) | |
| .get('https://www.google.com' ) | |
| .elementByName('q' ).sendKeys('123') | |
| .elementByName('btnG').click() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var chai = require("chai"); | |
| var chaiAsPromised = require("chai-as-promised"); | |
| chai.use(chaiAsPromised); | |
| chai.should(); | |
| wd = require('wd'); | |
| chaiAsPromised.transferPromiseness = wd.transferPromiseness; | |
| var browser = wd.promiseChainRemote(); | |
| about_page = 'http://localhost:1337/landing-pages/about.html' | |
| about_page = 'http://localhost:1337/' | |
| browser.attach(sessionId) | |
| .get(about_page) | |
| .title(function(err, value) { show(value)} ) | |
| .eval("window.location.href") | |
| .then(show) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //on parent window | |
| var gui = require('nw.gui'); | |
| var new_win = gui.Window.get( | |
| window.open('file:///Users/diniscruz/_Dev_Tests/node-webkit/my-first-test/index.html?sessionID=c3555e63-ab93-4dd5-8555-855bd6addcc7') | |
| ); | |
| //on child window | |
| about_page = 'http://localhost:1337/landing-pages/about.html' | |
| browser.get(about_page, function() { | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| url = require('url') | |
| find_SessionId = function(next) | |
| { | |
| var query = url.parse(document.location.href).query.split('='); | |
| if (query.length ==2 && query[0] == 'sessionID') | |
| sessionId = query[1] | |
| if(typeof(sessionId) == 'undefined') | |
| console.log('no sessionId') | |
| else | |
| next() | |
| } | |
| attach_To_SessionId = function(next) { browser.attach(sessionId, function(error) { next() }) }; | |
| select_Frame1 = function(next) { browser.frame('iframe1', next) } | |
| showHref = function() { browser.eval("window.location.href", function(err, data) { view(data) } ) } | |
| setWebDriver = function(next) | |
| { | |
| if (typeof(browser) != 'undefined') | |
| next() | |
| else | |
| var wd = require('wd'); | |
| browser = wd.remote(); | |
| find_SessionId(function() { | |
| attach_To_SessionId(function(){ | |
| select_Frame1(function() { | |
| //showHref(); | |
| //view('all good so far') | |
| next() | |
| }) | |
| }) | |
| }) | |
| } | |
| //browser.eval("window.location.href='http://www.google.com'", function() {}) | |
| //return | |
| setWebDriver(function() { | |
| browser.eval("window.location.href='http://www.google.com'", function() {}) | |
| }) | |
| return sessionId |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var webdriverio = require('webdriverio'); | |
| var options = { | |
| desiredCapabilities: { | |
| browserName: 'chrome' | |
| } | |
| }; | |
| webdriverio | |
| .remote(options) | |
| .init() | |
| .url('http://www.google.com') | |
| .title(function(err, res) { | |
| console.log('Title was: ' + res.value); | |
| }) | |
| .end(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var webdriver = require('selenium-webdriver') | |
| SeleniumServer = require('selenium-webdriver/remote').SeleniumServer; | |
| pathToSeleniumJar = './node_modules/protractor/selenium/selenium-server-standalone-2.44.0.jar' | |
| server = new SeleniumServer(pathToSeleniumJar, { | |
| port: 4444 | |
| }); | |
| server.start(); | |
| console.log(server) | |
| //return server.address() | |
| getDriver = function(capabilities) | |
| { | |
| return new webdriver.Builder() | |
| .usingServer(server.address()) | |
| .withCapabilities(capabilities) | |
| .build() | |
| } | |
| openTestPages = function(browser) | |
| { | |
| browser.get('http://www.google.com') | |
| browser.get('http://news.bbc.co.uk') | |
| browser.close() | |
| } | |
| openTestPages(getDriver(webdriver.Capabilities.chrome())) | |
| openTestPages(getDriver(webdriver.Capabilities.firefox())) | |
| openTestPages(getDriver(webdriver.Capabilities.safari())) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SeleniumServer = require('selenium-webdriver/remote').SeleniumServer; | |
| pathToSeleniumJar = './node_modules/protractor/selenium/selenium-server-standalone-2.44.0.jar' | |
| server = new SeleniumServer(pathToSeleniumJar, { | |
| port: 4444 | |
| }); | |
| server.start(); | |
| console.log(server) | |
| //return server.address() | |
| var driver = new webdriver.Builder() | |
| .usingServer(server.address()) | |
| .withCapabilities(webdriver.Capabilities.firefox()) | |
| .build() | |
| driver.get('http://www.google.com') | |
| driver.get('http://news.bbc.co.uk') | |
| driver.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //this is a really nice self contained script that does performs the search on top the top IFrame | |
| wd = require('wd'); | |
| browser = wd.remote(); | |
| find_SessionID = function(next) | |
| { | |
| if (typeof(sessionId) =='string') | |
| next() | |
| else | |
| browser.sessions(function(error, sessions) { | |
| view(sessions) | |
| sessionId = sessions[0].id | |
| next() | |
| } ) | |
| } | |
| attach = function(next) { browser.attach(sessionId, function(error) { next() }) }; | |
| resetToParentFrame = function(next) { | |
| browser._jsonWireCall( | |
| { | |
| method: 'POST' , | |
| relPath: '/frame/parent' , | |
| data: {} , | |
| cb: next | |
| }) | |
| } | |
| select_Frame1 = function(next) | |
| { | |
| browser.frame('iframe1', next) | |
| } | |
| open_Search_Google = function(text, next) | |
| { | |
| resetToParentFrame(function() { | |
| select_Frame1(function() { | |
| browser.eval("window.location='http://www.google.com'", function() { | |
| browser.elementByName('q', function(err, element){ | |
| element.clear(function(){ | |
| element.sendKeys(text) | |
| browser.elementByName('btnG', function(err, button) { | |
| button.click(next) | |
| }); | |
| }); | |
| }); | |
| }); | |
| }); | |
| }); | |
| }; | |
| find_SessionID(function() { | |
| attach(function() { | |
| open_Search_Google('o2platform', function() { | |
| open_Search_Google('owasp') | |
| }) | |
| }); | |
| }); | |
| return "done" | |
| /*viewData = function(error, data) | |
| { | |
| if (error) | |
| //view('error:' + error) // views on the top iframe | |
| show('error:' + error) // shows on the return value window | |
| else | |
| //view(data) | |
| show(data) | |
| } | |
| */ | |
| //showHref = function() { browser.eval("window.location.href", viewData)} | |
| //showHref() | |
| //return 'ok' | |
| //return browser.url | |
| //find_SessionID() | |
| // | |
| // { | |
| // }) | |
| return sessionId |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| wd = require('wd'); | |
| browser = wd.remote(); | |
| sessionId = '573b97cf-2f8c-4a07-b403-0e1e13688b8d' | |
| find_SessionID = function() | |
| { | |
| browser.sessions(function(error, sessions) { | |
| view(sessions) | |
| sessionId = sessions[0].id | |
| } ) | |
| } | |
| //find_SessionID() | |
| //return | |
| attach = function(next) { browser.attach(sessionId, function(error) { next() }) }; | |
| viewData = function(error, data) | |
| { | |
| if (error) | |
| //view('error:' + error) // views on the top iframe | |
| show('error:' + error) // shows on the return value window | |
| else | |
| //view(data) | |
| show(data) | |
| } | |
| //return browser.frame//(frames[0]); | |
| //.elementsByTagName('body', viewData); | |
| resetToParentFrame = function() { | |
| browser._jsonWireCall( | |
| { | |
| method: 'POST' , | |
| relPath: '/frame/parent' , | |
| data: {} , | |
| cb: viewData | |
| }) | |
| } | |
| select_Frame1 = function() | |
| { | |
| browser.frame('iframe1') | |
| } | |
| showHref = function() { browser.eval("window.location.href", viewData)} | |
| attach(function() | |
| { | |
| //showHref(); | |
| //return | |
| browser.elementsByTagName('a', function(err, elements) { | |
| elements.forEach(function(element) { | |
| element.getText().then(function(text) { | |
| console.log(text) | |
| }); | |
| }) | |
| show(elements) | |
| }) | |
| return ; | |
| //resetToParentFrame();showHref() | |
| //select_Frame1();showHref(); | |
| //showHref(); | |
| //browser.get('http://www.google.com') | |
| //browser.eval("window.location='http://www.google.com'", viewData); | |
| browser.elementByName('q', function(err, element){ | |
| element.clear(function(){ | |
| element.sendKeys('o2platform') | |
| browser.elementByName('btnG', function(err, button) { | |
| button.click() | |
| }); | |
| }); | |
| }) | |
| //showHref() | |
| }); | |
| //showHref() | |
| //return 'ok' | |
| return view(browser.switchTo + "") | |
| //return browser.url | |
| //find_SessionID() | |
| // | |
| // { | |
| // }) | |
| return sessionId |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| wd = require('wd'); | |
| browser = wd.remote(); | |
| sessionId = '67c3cb3f-838b-4ac2-bd93-2c6deb222c96' | |
| find_SessionID = function() | |
| { | |
| browser.sessions(function(error, sessions) { | |
| view(sessions) | |
| sessionId = sessions[0].id | |
| } ) | |
| } | |
| //find_SessionID() | |
| attach = function(next) { browser.attach(sessionId, function(error) { next() }) }; | |
| viewData = function(error, data) | |
| { | |
| if (error) | |
| view('error:' + error) | |
| else | |
| view(data) | |
| } | |
| //return browser.frame//(frames[0]); | |
| //.elementsByTagName('body', viewData); | |
| attach(function() | |
| { | |
| browser.get('http://www.google.com', viewData) | |
| //browser.url(viewData) | |
| return | |
| browser.elementById('iframe1', function(error, element) | |
| { | |
| show(element.innerHTML) | |
| }) | |
| }); | |
| //return browser.url | |
| //find_SessionID() | |
| // | |
| // { | |
| // }) | |
| return sessionId |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _chrome.Runtime.evaluate({expression:'alert(12'}, showData) | |
| _chrome.Runtime.evaluate({expression:'alert(document.body.innerHTML)'}, showData) | |
| _chrome.Runtime.evaluate({expression:'alert(require("util").inspect({a:12}))'}, showData) | |
| _chrome.DOM.getDocument(showData) | |
| _chrome.DOM.getOuterHTML({nodeId:2}, showData) | |
| _chrome.DOM.requestChildNodes({nodeId:71}, showData) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Chrome = require('chrome-remote-interface') | |
| var options = { host: '127.0.0.1', port: 9223} | |
| showTabs = function(error, tabs) | |
| { | |
| show(tabs) | |
| } | |
| connect = function(next) | |
| { | |
| onCreate = function(chrome) | |
| { | |
| _chrome = chrome; | |
| chrome.Network.enable(); | |
| chrome.Page.enable(); | |
| //chrome.close() | |
| next() | |
| } | |
| Chrome(options, onCreate) | |
| } | |
| //_chrome = undefined | |
| if (typeof(_chrome) == 'undefined') | |
| { | |
| connect(function() { show('connnected')}); | |
| return; | |
| } | |
| showData = function(err, data) | |
| { | |
| if (err) | |
| show("ERROR: " + err) | |
| else | |
| view(data) | |
| //show() | |
| } | |
| //return Chrome.listTabs(options, showTabs) | |
| //return _chrome.Page.getCookies(showData); | |
| _chrome.Page.getResourceTree(showData); | |
| //console.log('here') | |
| // | |
| //callback(_chrome) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Chrome = require('chrome-remote-interface') | |
| var options = { host: '127.0.0.1', port: 9223} | |
| showTabs = function(error, tabs) | |
| { | |
| show(tabs) | |
| } | |
| connect = function(next) | |
| { | |
| onCreate = function(chrome) | |
| { | |
| _chrome = chrome; | |
| chrome.Network.enable(); | |
| chrome.Page.enable(); | |
| //chrome.close() | |
| next() | |
| } | |
| Chrome(options, onCreate) | |
| } | |
| if (typeof(_chrome) == 'undefined') | |
| { | |
| connect(function() { show('connnected')}); | |
| return; | |
| } | |
| return _chrome.Page.navigate.help | |
| _chrome.Page.navigate({url:'http://www.google.com'}) | |
| //console.log('here') | |
| //return Chrome.listTabs(options, showTabs) | |
| //callback(_chrome) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Chrome = require('chrome-remote-interface') | |
| var options = { host: '127.0.0.1', port: 9223} | |
| showTabs = function(error, tabs) | |
| { | |
| show(tabs) | |
| } | |
| callback = function(chrome) | |
| { | |
| chrome.Network.enable(); | |
| chrome.Page.enable(); | |
| chrome.close() | |
| //show(chrome.Network) | |
| } | |
| //console.log('here') | |
| Chrome.listTabs(options, showTabs) | |
| //Chrome(options, callback) | |
| return 'done' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Chrome = require('chrome-remote-interface') | |
| var options = { host: '127.0.0.1', port: 9223} | |
| console.log(options) | |
| callback = function(err,data) | |
| { | |
| show(data) | |
| } | |
| //console.log('here') | |
| Chrome.listTabs(options, callback) | |
| return 'done' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Network.enable() | |
| Network.requestWillBeSent(console.log) | |
| Page.navigate({url: 'https://github.com'}) | |
| Page.navigate({url: 'file:///Users/diniscruz/_Dev_Tests/node-webkit/my-first-test/index.html'}) | |
| Page.captureScreenshot(function(err, image) {require('fs').writeFile('out.png', image.data, 'base64', function(err) {console.log(err);}); }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment