Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cant pass browser for multiple browser #1446

Closed
galaxianape opened this issue Nov 6, 2018 · 11 comments
Closed

cant pass browser for multiple browser #1446

galaxianape opened this issue Nov 6, 2018 · 11 comments

Comments

@galaxianape
Copy link

I cant pass a browser of my choice for serenity to manage.

I want to use multiple browser for my tests which will be read from serenity.properties file. I read it in my code and it sets up a driver. how can we set it for serenity to manage without mentioning @Managed(driver = "chrome")..can i pass a variable instead of chrome so that throughout the cucumber test serenit uses that driver ?

@wakaleo
Copy link
Member

wakaleo commented Nov 6, 2018

Use the webdriver.driver property:

mvn verify -Dwebdriver.driver=chrome

@longk15t
Copy link

longk15t commented Nov 7, 2018

Hi @wakaleo , can I run one test with parallel + multiple browser ?

@wakaleo
Copy link
Member

wakaleo commented Nov 7, 2018

This isn’t currently supported; typically you would do this at the CI level.

@galaxianape
Copy link
Author

Use the webdriver.driver property:

mvn verify -Dwebdriver.driver=chrome

Thanks for your reply..but I am trying to run from intellij.. by right clicking on testrunner file

@wakaleo
Copy link
Member

wakaleo commented Nov 9, 2018

You can also set the property in the serenity.properties file.

@galaxianape
Copy link
Author

Yes this is my serenity prop file looks like
browser = chrome
webdriver.driver=chrome
webdriver.chrome.driver=src\test\resources\drivers\chromedriver.exe
webdriver.ie.driver = src\test\resources\drivers\IEDriverServer.exe

this is how my base class looks like

static EnvironmentVariables variables = SystemEnvironmentVariables.createEnvironmentVariables();
public static String loginurl;
public static String browsername, browserFromCmdLine;
public WebEndUserSteps endUser;

@Managed
public static WebDriver driver;

public WebDriver manageDriver(){

    browserFromCmdLine = System.getProperty("browser");

    if (browserFromCmdLine == null) {
        browsername = variables.getProperty("browser");
    }
    else {
        browsername = browserFromCmdLine;
    }
    if(browsername == null) {
        System.out.println("browser is not specified in the environment.properties file or specified in mvn commandline arguments");
        System.exit(1);
    }

    switch (browsername) {
        case "firefox" :
            String firefoxdriverpath = variables.getProperty("firefoxDriverPath");
            variables.setProperty("webdriver.gecko.driver", firefoxdriverpath);
            break;
        case "chrome" :
            String chromedriverpath = variables.getProperty("chromeDriverPath");
            variables.setProperty("webdriver.chrome.driver", chromedriverpath);

            break;
        case "ie" :
            String iedriverpath = variables.getProperty("ieDriverPath");
            variables.setProperty("webdriver.ie.driver", iedriverpath);
            //new WebDriverFacade("webdriver.ie.driver", iedriverpath, iedriverpath);
            break;
        case "edge" :
            String edgedriverpath = variables.getProperty("edgeDriverPath");
            variables.setProperty("webdriver.edge.driver", edgedriverpath);
            break;
        default :
            System.out.println("ERROR: Browser specified is not correct");
            System.out.println("Please mention one of the required browser as below \n\tbrowser = chrome \n\tbrowser = ie \n\tbrowser = edge \n\tbrowser = firefox \nin environment.properties file");
            System.out.println("\nOR if you run from command line then as below \n\tmvn test -Dbrowser=chrome \n\tmvn test -Dbrowser=ie \n\tmvn test -Dbrowser=edge \n\tmvn test -Dbrowser=firefox \n");
            System.exit(1);
    }

    return driver;
}

So when I use different browser in serenity prop file..and right click on my testrunner file in intellij ..correct driver should be picked up by serenity driver and act upon it throughout the test

Same thing should happen when run from commandline for given parameters in command and when right clicked on feature file in intellij

@wakaleo
Copy link
Member

wakaleo commented Nov 12, 2018

That is not how Serenity works, at multiple levels.

  1. Never use statics
  2. Dont try to manage the driver location programmatically (it can all be done within the properties file).
  3. in fact, you probably don’t need to use a base class at all.

The correct configuration for multiple browsers is described in the documentation - I will post a link shortly.

@galaxianape
Copy link
Author

yes please....

there are 3 possible ways to execute the test. one is right click feature file in intellij, right click test runner in intellij and giving command through maven. so I am able to get correct driver when executingthrough command line but not with other 2 options. I need to understand how can we do it so all possible ways work well?

@galaxianape
Copy link
Author

Thanks...so what I understand is after passing browser as parameter from the prop file......I wont be able to execute runner file on all the 3 browsers when right clicked on it through intellij.

@cvarshn-cloud
Copy link

See https://serenity-bdd.github.io/theserenitybook/latest/web-testing-in-serenity.html.

IntelliJ does not support running Serenity tests directly from the feature files (see https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000324710-Serenity-BDD-with-Cucumber-is-showing-a-lot-of-promise-and-improved-considerably-over-the-last-2-years-It-would-be-good-if-you-provide-a-individual-Feature-Scenario-Runner-within-Intellij-IDE-for-Serenity-BDD-just-like-it-is-available-with-Cucumber?flash_digest=40e97f0c9ba85268606bf43398ef0b23593f7dd8).

IntelliJ provides excellent integrated support for Cucumber feature files. You can even run features simply by right-clicking on the feature file. But this won't work when you are using Cucumber with Serenity, as Serenity needs to instrument the feature file before execution. Fortunately, this is easy to fix. Here's how:

Click on the feature file you want to run
In the Run menu Select Run...
In the contextual menu, select the feature, then "Edit..."
You should now see the 'Edit Configuration Settings' window. Set the main class to 'net.serenitybdd.cucumber.cli.Main'
Change the Glue field to the root package of your project (or of your step definitions)
Click Apply
Now you can run your feature directly by right-clicking on the feature file.

@wakaleo wakaleo closed this as completed Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants