从命令行使用headless chrome执行单个Javascript文件
我们使用PhantomJS作为简单的测试运行程序,如下所示:从命令行使用headless chrome执行单个Javascript文件,javascript,google-chrome,command-line-interface,chromium,Javascript,Google Chrome,Command Line Interface,Chromium,我们使用PhantomJS作为简单的测试运行程序,如下所示: phantomjs path/to/test.js 无头铬也有类似的方法吗?您正在寻找的无头铬/铬API 一旦你有了脚本(它们都很好),你就可以用node script.js来运行它。你可以选择使用node或Selenium,在这两种情况下,你都必须重新编写部分测试用例,以使用新的api而不是新的api 以下选项基于节点: 我建议你到他们那里去获取安装和使用说明 您的测试用例应使用和编写: 这里有一个列表,您可以使用木偶演员和
phantomjs path/to/test.js
无头铬也有类似的方法吗?您正在寻找的无头铬/铬API
一旦你有了脚本(它们都很好),你就可以用node script.js
来运行它。你可以选择使用node
或Selenium
,在这两种情况下,你都必须重新编写部分测试用例,以使用新的api而不是新的api
以下选项基于节点
:
我建议你到他们那里去获取安装和使用说明
您的测试用例应使用和编写:
这里有一个列表,您可以使用木偶演员
和
是一个比Puppeter的API级别更低的库。如果您想接近金属并直接使用DevTools协议,我建议您使用它
您需要或使用或nodejs
:
node --inspect=9222 path/to/test.js
使用编写javascript
测试用例,并按照上的说明安装和运行测试
另一个选项是使用Selenium
configured。使用Selenium
:
您可以使用Karma和无头Chrome运行测试。这是做那件事的秘诀 木偶演员也有很好的装备来做这件事。下面也是一个例子。试试下面的例子:
const chrome = require('../chrome');
const firefox = require('../firefox');
const {Builder, By, Key, until} = require('..');
const width = 640;
const height = 480;
let driver = new Builder()
.forBrowser('chrome')
.setChromeOptions(
new chrome.Options().headless().windowSize({width, height}))
.setFirefoxOptions(
new firefox.Options().headless().windowSize({width, height}))
.build();
driver.get('http://www.google.com/ncr')
.then(_ =>
driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN))
.then(_ => driver.wait(until.titleIs('webdriver - Google Search'), 1000))
.then(
_ => driver.quit(),
e => driver.quit().then(() => { throw e; }));
这个的依赖关系是什么<代码>要求(“..”)使我很难知道应该首先安装什么。
const chrome = require('../chrome');
const firefox = require('../firefox');
const {Builder, By, Key, until} = require('..');
const width = 640;
const height = 480;
let driver = new Builder()
.forBrowser('chrome')
.setChromeOptions(
new chrome.Options().headless().windowSize({width, height}))
.setFirefoxOptions(
new firefox.Options().headless().windowSize({width, height}))
.build();
driver.get('http://www.google.com/ncr')
.then(_ =>
driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN))
.then(_ => driver.wait(until.titleIs('webdriver - Google Search'), 1000))
.then(
_ => driver.quit(),
e => driver.quit().then(() => { throw e; }));