Serenity-core: Question::How to access the values of the variables defined in Serenity.Conf?

Created on 31 Jul 2019  路  8Comments  路  Source: serenity-bdd/serenity-core

environments {
default {
webdriver.base.url = "https://duckduckgo.com"
}
dev {
webdriver.base.url = "https://duckduckgo.com/dev"
}
staging {
webdriver.base.url = "https://duckduckgo.com/staging"
}
prod {
webdriver.base.url = "https://duckduckgo.com/prod"
}
}

* I want to access the webdriver.base.url in dev. *

I have tried the following code:

EnvironmentVariables variables = SystemEnvironmentVariables.createEnvironmentVariables();
String webserviceEndpoint = EnvironmentSpecificConfiguration.from(variables).getProperty("webdriver.base.url");

webserviceEndpoint is always populated with "https://duckduckgo.com".

How could I access the webdriver.base.url in dev?

question

All 8 comments

I think the value of webdriver.base.url is depend on the -Denvironment=staging that you push in your maven command

if mvn verify then _webserviceEndpoint_="https://duckduckgo.com"
if mvn verify -Denvironment=staging then _webserviceEndpoint_="https://duckduckgo.com/staging"
if mvn verify -Denvironment=prod then _webserviceEndpoint_="https://duckduckgo.com/prod"

I got same issue. it always opening "https://duckduckgo.com" even using openAt() method.

Thanks John for the quick reply. I have gone through the link you have shared. I could access the value of the key defined in default but not able to access anything mentioned in dev, staging or prod.

Below are the details:

environments {
default {
webdriver.base.url = "https://duckduckgo.com"
}
dev {
webdriver.base.url = "https://duckduckgo.com/dev"
accounts.service.url = "http://dev.accounts.myorg.com"
}
staging {
webdriver.base.url = "https://duckduckgo.com/staging"
}
prod {
webdriver.base.url = "https://duckduckgo.com/prod"
}
}

Code:
private EnvironmentVariables environmentVariables;

String webserviceEndpoint = EnvironmentSpecificConfiguration.from(environmentVariables).getProperty("accounts.service.url");

It throws ::"Method threw 'net.serenitybdd.core.environment.UndefinedEnvironmentVariableException' exception."

I want to access the value of "accounts.service.url" in dev on the page Object. How could I do it?

Note: I know it can be done using mvn command.

You can write environmentVariables.getProperty("environments.dev.accounts.service.url"), but it would defeat the whole point of having environment-specific variables, which is so that the tests don't need to know what environment they are running in at any point in time.

Presume answered.

how to use mvn verify -Denvironment=staging for gradle=

@santiagogf26 ...i was trying with gradle clean test -Denvironment but it is always picking up the environment variables inside default section. Any luck with you?

My Serenity.conf file looks like below

environments {
default {
authorization.endpoint = "xyz"
}
dev {
authorization.endpoint = "abc"
}

webdriver.chrome.driver=src/test/resources/chromedriver.exe
chrome_experimental_options.useAutomationExtension = "false"
webdriver.wait.for.timeout=80000
serenity.timeout=80000
webdriver.timeouts.implicitlywait=80000
chrome.switches = --start-maximized

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thePantz picture thePantz  路  4Comments

samangipudi picture samangipudi  路  5Comments

gkushang picture gkushang  路  4Comments

knludi picture knludi  路  4Comments

scormaq picture scormaq  路  3Comments