Using Protractor to test canvas drawing (i)

Source: Internet
Author: User



Protractor is the angular of a e2e test framework, essentially a webdriver.



Test canvas, mainly image comparison, search, did not find too good Nodejs library, all or used before the Resemblejs.



RESEMBLEJS uses image and canvas, so it cannot be used directly in the Nodejs.



A person on GitHub had a node-resemble, but used a C write Node-canvas, to make up this again with the installation of Python and VC run library, it sounds very troublesome, it is no wonder only 2 stars.



Is it OK to let resemble run directly in the browser?



This will use the Executeasyncscript method of browser.



First, talk about Executeasyncscript.



This method is to put the JS code in the browser environment to run, that is, in the browser environment to run, the DOM of things can be used, Image,canvas God horse all alone.



and is asynchronous, actually has a synchronous executescript, the usage is similar.



API is not posted, directly say usage.



Executeasyncscript method, which is a variable parameter method



The first parameter must be a method, that is, the code to execute in the browser.



Like what:





function(){
    console.log("I'm a method");
};


You can then write any parameters later, and in the method of the first argument you can use the arguments array to get the arguments in order.



Like what:





Function () {
Console. Log ("I'm a method, I have three parameters")
var p1=arguments[0];
var p2=arguments[1];
var p3=arguments[2];
}

Because it is asynchronous, the result of execution needs to be returned with a callback function, the callback function Webdriver is ready, is the last parameter of arguments.





So the full appearance of the first parameter should be





function(){
    console.log("
I'm a method, I have three parameters
") var p1=arguments[0]; var p2=arguments[1]; var p3=arguments[2]; var callback=arguments[arguments.lenght-1]; callback("return"); };
The return value of the Executeasyncscript method is a promise








So the whole function should be called this way.





Browser. Executeasyncscript ("function() {console. Log" ("I will not write")} ", P1, P2, P3)
.then(function(result){
Console. Log ("result is" + result);
}; 

Then the result of the result callback in the method.


If not protractor only with Webdriver should also be the same.



Well, wrote for a long while did not go to the point, first of all, and then write in the next article.






Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.



Using Protractor to test canvas drawing (i)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.