0

I have got browserstack working with a automation framework that I did not setup, while my local tests (the website I'm testing is in development still and so not on a DNS) do run on browserstack the environment/configuration used by browserstack is constantly changing.

It always runs a version of chrome sometimes 72 other times 49, 69 etc, its the same with the OS sometimes its windows 10, 7, 8, xp, and sometime a random version of OSX too!

I've tired looking at browserstack's page on serenity using and modifying examples from there as well as there git hub examples in my serenity.properties/BrowserStackSerenityTest.java and the class im running the test from but with no luck. I've been at few hours now tweaking and changing thease three files to get some constancy and don't know what else to do

I'm still pretty inexperienced with Java and automation and would like to move onto fixing up and good stack of test before trying to setup running tests and parallel in browserstack

My serenity.properties

        webdriver.driver = provided 
        webdriver.provided.type = mydriver
        webdriver.provided.mydriver = com.browserstack.BrowserStackSerenityDriver
        serenity.driver.capabilities = mydriver

        browserstack.user=MyUserName
        browserstack.key=MyKey
        browserstack.server=hub-cloud.browserstack.com
        browserstack.local=true
        browserstack.build=serenity-browserstack
        browserstack.project=MyProjectname
        browserstack.debug=true

        environment.local.name=TestRunner
        environment.local.browser=chrome
        environment.local.browser_version=72
        environment.local.browserstack.local=true
        browserstack.os = Windows
        browserstack.os_version = 10


        serenity.issue.tracker.url =

        serenity.project.name = Common UI testing using Serenity and Cucumber

        serenity.restart.browser.for.each = never

        serenity.browser.maximized = true
        serenity.dry.run=false        
        serenity.test.root=net.thucydides.showcase.cucumber.junit
        serenity.outputDirectory = target/site/reports           
        webdriver.timeouts.implicitlywait = 1
        webdriver.wait.for.timeout = 0
        serenity.take.screenshots=BEFORE_AND_AFTER_EACH_STEP

My TestRunner.java which I'm running the tests from

        import com.browserstack.BrowserStackSerenityTest;
        import cucumber.api.CucumberOptions;
        import net.serenitybdd.cucumber.CucumberWithSerenity;
        import org.junit.runner.RunWith;


        @RunWith(CucumberWithSerenity.class)
        @CucumberOptions(features = "src/test/resources/features", tags = "@fixing")
        public class TestRunner extends BrowserStackSerenityTest {

        //    @Managed(driver = "Chrome", uniqueSession = true)
        //    WebDriver driver;

My BrowserStackSerenityTest.java

package com.browserstack;

import com.browserstack.local.*;
import net.thucydides.core.util.EnvironmentVariables;
import net.thucydides.core.util.SystemEnvironmentVariables;
import org.junit.AfterClass;
import org.junit.BeforeClass;

import java.util.HashMap;
import java.util.Map;


public class BrowserStackSerenityTest {
    static Local bsLocal;

    @BeforeClass
    public static void setUp() throws Exception {
        EnvironmentVariables environmentVariables = SystemEnvironmentVariables.createEnvironmentVariables();

        String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY");
        if (accessKey == null) {
            accessKey = (String) environmentVariables.getProperty("browserstack.key");
        }

        String environment = System.getProperty("environment");
        String key = "browserstack.local";
        boolean is_local = environmentVariables.getProperty(key) != null && environmentVariables.getProperty(key).equals("true");

        if (environment != null && !is_local) {
            key = "environment."+environment+".browserstack.local";
            is_local = environmentVariables.getProperty(key) != null && environmentVariables.getProperty(key).equals("true");
        }

        if (is_local) {
            bsLocal = new Local();
            Map<String, String> bsLocalArgs = new HashMap<String, String>();
            bsLocalArgs.put("key", accessKey);
            bsLocal.start(bsLocalArgs);
        }
    }

    @AfterClass
    public static void tearDown() throws Exception {
        if (bsLocal != null) {
            bsLocal.stop();
        }
    }
}
alexrnov
  • 2,346
  • 3
  • 18
  • 34

1 Answers1

0

I had to tweak the serenity.properties file by trial and error, because it is not obvious by reading the Browserstack documentation and because the Browserstack code is relying on a very old Serenity framework version:

environment.parallel_1.name = parallel_test
environment.parallel_1.browser = Chrome
environment.parallel_1.browser_version = 73.0 beta
environment.parallel_1.os = OS X
environment.parallel_1.os_version = Mojave
environment.parallel_1.resolution = 1280x1024
environment.parallel_1.browserstack.local = true

environment.parallel_2.name = parallel_test
environment.parallel_2.browser = IE
environment.parallel_2.browser_version = 11
environment.parallel_2.os = Windows
environment.parallel_2.os_version = 7
environment.parallel_2.resolution = 1280x1024
environment.parallel_2.browserstack.local = true

you can see the code here: https://github.com/izaac/serenity-cucumber4

izaac
  • 1
  • 2