Using protractor to test non angular sites
Intro:- Using Protractor to test non angular sites
What is Protractor?
Protractor is an end-to-end test framework for AngularJS applications. Protractor runs tests against your application running in a real browser, interacting with it as a user would. [ref]. However, it is often used but not restricted to angular apps. This blog will show how it can be used to test non angular sites.
This is in continuation to the previous blog in which we discussed how, we can use protractor for testing angularjs apps. Now we will see, how protractor can be used beyond angularjs apps.
Technology stack as usual remains pretty much the same based on familiarity/needs and convenience, viz. nodejs, npm for package management and dependency injection, grunt or gulp, selenium web driver or can also use phantomJS (used for DOM handling/manipulation).
This blog will showcase , scraping a coffee company website and ordering a kg of a particular coffee. It will automate the entire process till payment stage. This is achieved through protractor and selenium web driver.
Below is a small video of this demo
We now discuss, how what’s shown in the video can be achieved using protractor and selenium web driver.
Grunt file is the same as in previous blog and can be seen below
This gruntfile combines running the webdriver manager (selenium server) and launching the browser and automating the coffee order process. The grunt default task takes care of that. It runs the server in background, halts for 5 sec until the server is up and running and then launches the website in browser.
Below is the test script file which takes care of opening the browser and automating the coffee order process:
[gistpen id=”1589″] The main difference when using protractor and selenium to test non-angularjs apps is, keyword browser is to be replaced by browser.driver and element to be replaced by browser.driver.findElement. That’s because keywords browser and element are recognized if the app being tested has angularjs libs included. Rest all other things remain pretty much the same. You can compare angular and non-angular test suites side by side by referring to this blog here
Stay tuned for more interesting stuff. Please don’t forget to like our page here.