galenframework / galen

Layout and functional testing framework for websites
http://galenframework.com
1.41k stars 161 forks source link

allow "default" browserfactory in config #103

Open newcron opened 10 years ago

newcron commented 10 years ago

In our company, we're using proxies to connect to out integration environment.

http://kleinanzeigen.ebay.de/ with no proxy ==> production http://kleinanzeigen.ebay.de/ with qaproxy:80 ==> qa environment

to get galen work through a proxy, we're writing a jsfactory that configures a Proxy in selenium. Now, as every automation test has to go through a browser created by that factory, it's really redundant to specify that jsfactory in every test:

@@ set
   specsDir specs

Ensure Box Modules are fine
    jsfactory belen_browser_factory.js http://kleinanzeigen.ebay.de/static/styleguide/section-2.html 1024x768
        check ${specsDir}/styleguide/box-section.spec

Ensure Button Modules are fine
    jsfactory belen_browser_factory.js http://kleinanzeigen.ebay.de/static/styleguide/section-1.html 1024x768
        check ${specsDir}/styleguide/button-section.spec

Therefore, I would propose to have a configurable default jsfactory in the global config, that is used if no other jsfactory is specified. For me (preferrably) the solution should also support Java browser factories and not only jsfactories.

ishubin commented 10 years ago

Hi,

Thanks for the idea. Will try to do something. In the meantime I would definetely recommend you to switch to Javascript Tests and forget about the Basic Test runner. That way you can push testing to Frontend engineers and they prefer Javascript :) And also with that you can build your own mini-framework around Galen and make your tests much more advanced. Because if you go further with layout tests you will end up with the need for interacting with browser (clicking, typing etc) and for that the Javascript is much more suitable. The Basic tests runner was the first thing implemented before introducing the proper Java API and Javascript based tests and it is more of a quick start rather than a reliable solution for automation.

Also as a temporary solution you can use variables:

@@ set
   specsDir specs
   domain   kleinanzeigen.ebay.de
   browser  jsfactory belen_browser_factory.js
   url      http://${domain}

Ensure Box Modules are fine
    ${browser} ${url}/static/styleguide/section-2.html 1024x768
        check ${specsDir}/styleguide/box-section.spec

Ensure Button Modules are fine
    ${browser} ${url}/static/styleguide/section-1.html 1024x768
        check ${specsDir}/styleguide/button-section.spec

But for a more advanced testing I can demonstrate an example for Javascript Tests where you can go really crazy with your tests Write an init.js file:

this.domain = "kleinanzeigen.ebay.de";

/* 
Taking over instantiation of WebDriver and storing driver instance in 
session so in the afterTest event we can quit the driver
*/
function openDriver(url, size) {

    // Here is the place where you can implement your way of instantiating driver through proxy
    var driver = createDriver(null, size);

    session.put("driver", driver);

    if (url != null) {
        if (url.indexOf("http://") != 0 && url.indexOf("https://") != 0) {
            url = "http://" + domain + url;
        }
        driver.get(url);
    }
    else {
        driver.get("http://" + domain);
    }
    return driver;
}

/*
  Quiting the WebDriver and attaching screenshot in case of failure
 */
afterTest(function (test) {
    var driver = session.get("driver");
    if (driver != null) {
        if (test.isFailed()) {
            session.report().info("Screenshot").withAttachment("Screenshot", takeScreenshot(driver));
        }
        driver.quit();
    }
});

/*
 Defining your own function for a test  
*/
this.myTest = function (testName, url, size, callback) {
   test(testName, function (device) {
         var driver = openDriver(url, size);
         callback.call(this, driver);
    });
};

And now the way your tests would look like. Create a file homePage.test.js:

myTest("Ensure Box Modules are fine", "/static/styleguide/section-2.html", "1024x768", function (driver) {
    checkLayout(driver, "specs/styleguide/box-section.spec");
});

myTest("Ensure Button Modules are fine", "/static/styleguide/section-1.html", "1024x768", function (driver) {
    checkLayout(driver, "specs/styleguide/button-section.spec");
});

Or if you go even further you can create a function called simpleTest that would do all the stuff you need (open driver, checkLayout, kill browser) you can implement something like this in your tests:

simpleTest("Ensure Box Modules are fine", "/static/styleguide/section-2.html", "1024x768", "specs/styleguide/box-section.spec");
simpleTest("Ensure Button Modules are fine", "/static/styleguide/section-1.html", "1024x768", "specs/styleguide/button-section.spec");