Dec 26, 2013

GalenJs. Unleash the power of javascript in Galen Framework

In my previous posts I wrote about layout testing in Galen Framework. But what if we need to perform some actions on the browser to get to some specific page? For instance lets say we have to test a blog website. And to do it properly we should come up with a realiable automation so we need to post an article on the website so we can later open it and check the layout. To perform all these complex actions Galen Framework provides an action called run. It is used in order to invoke a javascript where you can take over the WebDriver and perform some actions on the page like clicking, typing text and basically anything that WebDriver allows.

For the demo purpose lets use this page
What we need to do is to log in using the form on the page. Lets start writting a basic test. First of all we need to download the latest galenjs.js file. You can get it from GitHub repository. Just put this file in your test project folder. Now lets create a login.js file.

// Include the GalenJs library load("galenjs.js"); // Create a GalenJs instance from driver var $ = GalenJs.create(driver); // Create a login page object var loginPage = $.page({ email: "#login", password: "#password", submit: ".login-form a.button" }); // Perform login flow"testuser"); loginPage.password.typeText("P@ssw0rd");;

That’s it. Now we can execute this script in our test suite. Lets create a file my.test

User profile test 1024x768 run login.js

Now you can run it with this command:

galen test my.test --htmlreport reports

So this is the basic stuff that you can do with GalenJs. As you see it is quite usefull since it allows to write a better code in javascript with minimal effort. And what is more important it allows you to get to any resource on your website so you can also test its layout with Galen Framework.

Posted in Galen, Selenium, Web, Automation
comments powered by Disqus