接一下来讲一讲api的使用 http://macacajs.github.io/macaca-wd/api/
var _config = { //本程序的host host: 'http://test.3dker.cn/' } module.exports = _config;
var wd = require('webdriver-client')({ platformName: 'desktop', browserName: 'chrome' }); var config = require('../configs.js'); describe('macaca desktop 3dker article', function() { this.timeout(5 * 60 * 1000); const driver = wd.initPromiseChain(); const initialURL = config.host + 'article/list'; before(() => { return driver .initDriver() .setWindowSize(1280, 1200); }); it('#0 should go into macaca', function() { return driver .get(initialURL) .sleep(6000); }); it('#1 should works with macaca', function() { return driver .elementByClassName('search-article') .sendKeys('aaaa') .sleep(5000) .elementByClassName('btn-search') .click() .sleep(5000) .source() .then(function(html) { //html.should.containEql('aaaa'); }) .takeScreenshot(); }); it('#2 should go into web', function() { return driver .get(initialURL + '?classify=知识分享#atc-select') .sleep(3000); }); it('#3 write article', function(){ return driver .elementByClassName('write') .click() .sleep(3000) .elementByClassName('username') .sendKeys('username') .elementByClassName('password') .sendKeys('pwd') .elementByClassName('do-login') .click() .sleep(3000) }); after((done) => { return driver .quit(done); }); });
get(initialURL)---就可以用chrome打开一个页面,
elementByClassName('search-article')--获了一个class名叫search-article的element
sendKeys('aaaa')----接下来是这个对象输入框输入我们想要的值,,,也可以用下面这个方法
或 safeEval('$(".search-article").val("56fa2fa3433e3fb103792fcf50806f54"')) 这个是通过脚本来赋值,因为网站有引用jquery,所有支持jquery,
接下来只要去出发搜索按按钮即可,代码如下
.elementByClassName('btn-search')
.click()
如下代码,取类名为smoke-base的对象,如果他包含这个class名为 smoke-visible,触发点击事件,关闭弹出层
.elementByClassName('smoke-base')
.hasElementByClassName('smoke-visible')
.safeEval('$(".dialog-buttons button").trigger("click")')