[JVM ]Cross Browser Testing using Cucumber

1,894 views
Skip to first unread message

Kunal Mehta

unread,
Dec 28, 2014, 4:49:17 AM12/28/14
to cu...@googlegroups.com
Hello All,
I want to run Cucumber JVM test on list of browser on single instruction. I have set up my code structure using this article. (adding Modules & Logging)

My requirement is to build and run selected test\s on configured browser\s and execute them on CI\local environment.Currently I am using Junit and MVN. I am using SharedDriver (Dependency Injection via PICO) way of opening and closing browser.

As logging was becoming another hassle in multi threading environment, I am flexible if on execution all the test are run on single browser first and then pick up the next browser in sequence. Any reference to git repo will really help.

I really appreciate if any body can assist or direct me to sources.

Thanks

Kunal Mehta

unread,
Jan 6, 2015, 5:59:02 AM1/6/15
to cu...@googlegroups.com
Hello wonderful people,

wish you all a very happy new year.

any leads on this post is more than appreciated.

AFAIK, Cucumber isn't intended to be a cross browser testing tool.

I just want to understand how teams already using cucumber JVM are coping up with cross browser testing. There must be a way of saving time by running test in parallel.

Thanks

Richard Lawrence

unread,
Jan 6, 2015, 9:13:48 AM1/6/15
to cu...@googlegroups.com
Without getting into the specifics of CucumberJVM, since I've only done this in Ruby myself, the general approach I've used is this...

1. Choose a main browser for testing the overall behavior of my app. I usually prefer a headless browser for this for speed. Use this most of the time when I run Cucumber on my dev machine.

2. Tag scenarios that are likely to expose differences between browsers.

3. Allow the browser driver to be chosen via a configuration setting of some sort, e.g. an environment variable or maybe through Maven. 

4. Run the tagged scenarios with other browsers as needed on my dev machine and regularly on a CI machine.


A few important things to note here:

1. Cucumber doesn't care about browsers. All the browser-related stuff goes in your own code in step defs, hooks, etc.
2. You'll do a separate run of your Cucumber scenarios for each browser. 
3. Not every scenario is worth running in every browser, especially if you're good about keeping scenarios that test non-UI behaviors from touching the UI. 


Hope that helps,

Richard

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kunal Mehta

unread,
Jan 7, 2015, 5:44:21 AM1/7/15
to cu...@googlegroups.com
Thanks Richard, each point is worthy enough.

Currently I am already picking up browser from properties file. properties file exist in .gitignore too, which saves me from any confusion , whilst running\pushing test on CI.
Locally I keep toggling between browser. this approach works well for few test but in that case too I want some mechanism by which I can log each browser log4j logs in different file.

On the other thoughts, would it be good idea to run test on each browser overnight on CI build. The test & browser can be managed by the time of test run.

Thanks again for your valuable suggestion.




public class SharedDriver extends EventFiringWebDriver {
    private static final WebDriver REAL_DRIVER;
    private static final Thread CLOSE_THREAD = new Thread() {
        @Override
        public void run() {
            REAL_DRIVER.quit();
        }
    };
static Properties OR = null;
static String browser_name = null;
    static {
   
    System.out.println("I am in shareddriver static block ");
    System.out.println("setting property ");
    setProperty();
    System.out.println("fetching browser now ");
    browser_name=fetchBrowser();
    System.out.println(browser_name);
    System.out.println("I am in shareddriver static block- Property Set ");
    //System.setProperty("webdriver.chrome.driver", "C:/KM/dOWNLOADS_new/ChromeDriver/chromedriver.exe");
      REAL_DRIVER= getInstance(browser_name);
    // REAL_DRIVER = new ChromeDriver();
        REAL_DRIVER.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        Runtime.getRuntime().addShutdownHook(CLOSE_THREAD);
    } 
    
    
    
    public static void setProperty(){
// initialize properties
System.out.println("***************Initializing Properties file*******************");
try{
OR = new Properties();
FileInputStream fs = new FileInputStream(System.getProperty("user.dir")+"\\src\\test\\resources\\OR.properties");
OR.load(fs);
}catch(Exception e){
System.out.println("Error in initializing Properties file");
}
}
    
    
    public static String fetchBrowser() {
    browser_name=OR.getProperty("browser");
    System.out.println("values fetched is"+browser_name);
    return browser_name;
   
    }
    static WebDriver driver;
    public static WebDriver getInstance(String browserName) {
        
        

        switch (browser_name) {
            case "firefox":
            System.out.println("in firefox");
                driver = new FirefoxDriver();
                break;
            case "chrome":
            System.out.println("in chrome");
            System.setProperty("webdriver.chrome.driver", "C:/KM/dOWNLOADS_new/ChromeDriver/chromedriver.exe");
                driver = new ChromeDriver();
                break;
            case "ie":
            System.out.println("in IE");
              driver = new FirefoxDriver();
                break;
            default:
            System.out.println("in Deafault");
                driver = new FirefoxDriver();
                break;
        }
        // maximize browser's window on start
        driver.manage().window().maximize();
        return driver;
    }

Nick Mellor

unread,
Feb 7, 2017, 10:57:17 PM2/7/17
to Cukes
Hi Kunal,

We used Gradle tasks to switch browsers, the Gradle task setting an environment variable for the browser and environnent, eg

gradle testDevFirefox

Then we had a Bamboo setup that executed separate tasks for each browser, triggered by a change in the test of Dev codebase. Each Bamboo track ran in a separate AWS instance, executing a Gradle task each.

Hope this helps,

Nick

Nick Mellor

unread,
Feb 7, 2017, 10:57:17 PM2/7/17
to Cukes

naga triveni Medici

unread,
Sep 26, 2018, 8:16:59 AM9/26/18
to Cukes
Hi Kunal,  

Hope you are doing good. I want to  know if we can implement cross browser testing using cucumber . it would be really great if you take few minutes to help me out.

I have a feature file and i want to execute that feature file parallel in all the 3 browser ie, chrome, firefox.....i am using cucumber with maven. Can i please know if there is a way to get that done.

thanx in advance

naga triveni Medici

unread,
Sep 26, 2018, 8:16:59 AM9/26/18
to Cukes
Hi Richard,

Hope you are doing good. I want to  know if we can implement cross browser testing using cucumber . it would be really great if you take few minutes to help me out.

I have a feature file and i want to execute that feature file parallel in all the 3 browser ie, chrome, firefox.....i am using cucumber with maven. Can i please know if there is a way to get that done.

Thank you in advance.
Reply all
Reply to author
Forward
0 new messages