Azure Pipeline - Opening RemoteWebDriver with different credentials

故事扮演 提交于 2021-01-29 11:18:42

问题


Basically we set up test automation in one environment(DEV). For this environment we use a users credentials to open the browser for all tests. So in our dev environment we have the same password set up for all users. This will be the same approach in UAT but with a different password

When testing we launch the browser using impersonation and launch the browser as 'run as' for that user

private static RemoteWebDriver OpenChromeBrowser(string username) {
var service = ChromeDriverService.CreateDefaultService(driverpath)

if user is not null then we do this

var pwd = new SecureString()

service.StartDomain = Configurationhelper.Domain
service.StartupUserName = username
service.StartupPassword= = pwd
service.StartupLoadUserProfile = true

we store domain and password and other environmental variables in a separate config file as constants.

Our Azure pipeline has 2 separate clients now UAT and DEV pointing to the same artifact. The tasks and Variable are the same for both environments but with different values for urls and db connections

Main issue: This wont work now as when we run the tests in UAT they fail straight away with' Password is incorrect' as we have hardcoded the password into our code. So i am looking for the best solution to this

Is there a way to modify this code and to maybe store passwords as secrets in AZURE pipeline variables? so for example in our pipeline variables we would have password for both Dev and UAT. Then launch chromedriver with user credentials set as variables from azure pipeline?

What is the recommended approach in this situation?


回答1:


Is there a way to modify this code and to maybe store passwords as secrets in AZURE pipeline variables?

The answer is yes.

We are doing the same thing "store domain and password and other environmental variables in a separate config file as constants", Let's call it app.config, I am not sure if my solution fully meets your requirements, but you can try it.

I defined following in the app.config:

<configuration>
    <connectionStrings>
        <add name="DatabaseName" connectionString="DatabaseURL" />
    </connectionStrings>
</configuration>

To modify the DatabaseName and DatabaseURL based on the different environments by the variables in the pipeline Variables, I use the task Replace Tokens to modify the DatabaseName and DatabaseURL.

I change the app.config in the repo to:

<configuration>
    <connectionStrings>
        <add name="#{DatabaseName}#" connectionString="#{DatabaseURL}#" />
    </connectionStrings>
</configuration>

The format of variable in .config file is #{DatabaseName}# & #{DatabaseURL}#.

Then define the variables DatabaseName and DatabaseURL on the Variables based on the stage as secrets:

In this case, the connectionStrings will be modified to different value based on the stage.



来源:https://stackoverflow.com/questions/65262975/azure-pipeline-opening-remotewebdriver-with-different-credentials

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!