动漫引擎

导航

WebApp的自动测试工具: protractor和selenium

Protractor是Selenium的扩充,支持Angularjs

 

element(by.css('my-css')).click();

 

一、用by的各种Locator定位元素

选中1个元素:

element(by.id('myid'));
element(by.css('.myclass')); (可以简写为: $('myclass'))
element(by.model('name'));  // 只适用于NG
element(by.binding('bindingname')); // 只适用于NG, // Find an element bound to the given variable.

选中多个元素,返回元素集合(数组)

var eList = element.all(by.css('.myclass')); (可以简写为: $('myclass'))

eList.count();  // 返回1个promise,不是简单的数字

eList.get(index);

eList.first();

eList.last();

 

多种选择and运算

element(by.css('myclass')).all(by.tagName('tag-within-css'));

 

二、给元素动作:

!!! 所有的action都是异步的, 返回值是promise !!!!

var  ele = element(by.id('myid'));

ele.click();

ele.clear().sendkeys('my text');

ele.clear();   clear the text

ele.getAttribute('value'); // 获取元素的值

ele.getText().then(function(text) { // 因为action是异步,

      console.log(text);

     // 这里也可以写expect

}

 

三、

 

安装protractor, 并update:

$npm install -g protractor

$webdriver-manager update

 

 

(版本匹配: Node 6.9.5, NPM: 3.10.10)  

 

附录: 注意事项:

** 每一个test case 都是一个新的instance, 浏览器没有上一个测试的cache (例如search String)

** 如果有多个action,那么是顺序执行的,(因为都是异步的, 都会放到event 列表中)

启动:  

    命令窗口1:

            $> webdriver-manager start

    命令窗口2

            $> protractor protractor.conf.js 

FAQ: 
Q: Unable to create new service: ChromeDriverService
A:

    $>webdriver-manager update --chromedriver

    

posted on 2017-09-23 05:45  动漫引擎  阅读(421)  评论(0编辑  收藏  举报