Azure管道-使用不同的凭据打开RemoteWebDriver [英] Azure Pipeline - Opening RemoteWebDriver with different credentials

查看:52
本文介绍了Azure管道-使用不同的凭据打开RemoteWebDriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我们在一个环境(DEV)中设置测试自动化.在这种环境下,我们使用用户凭据打开浏览器以进行所有测试.因此,在我们的开发环境中,我们为所有用户设置了相同的密码.这与UAT中的方法相同,但密码不同

在测试时,我们使用模拟功能启动浏览器,并以该用户的运行身份"启动浏览器

 私有静态RemoteWebDriver OpenChromeBrowser(字符串用户名){var service = ChromeDriverService.CreateDefaultService(driverpath) 

如果用户不为空,那么我们这样做

  var pwd = new SecureString()service.StartDomain = Configurationhelper.Domainservice.StartupUserName =用户名service.StartupPassword = =密码service.StartupLoadUserProfile = true 

我们将域和密码以及其他环境变量作为常量存储在单独的配置文件中.

我们的Azure管道现在有2个单独的客户端UAT和DEV指向同一工件.两种环境的任务和变量均相同,但url和db连接的值不同

主要问题:由于我们已将密码硬编码到我们的代码中,因此当我们在UAT中运行测试时,它们立即失败并显示密码不正确",因此无法正常工作.所以我正在寻找最好的解决方案

是否可以修改此代码,以及将密码作为秘密存储在AZURE管道变量中?因此,例如在管道变量中,我们将同时具有Dev和UAT的密码.然后从Azure管道启动将用户凭据设置为变量的chromedriver吗?

在这种情况下推荐的方法是什么?

解决方案

是否可以修改此代码并将密码作为秘密存储在AZURE管道变量中?

答案是肯定的.

我们正在做同样的事情将域和密码以及其他环境变量作为常量存储在单独的配置文件中",我们将其称为 app.config ,我不确定我的解决方案是否完全满足您的要求,但是您可以尝试.

我在 app.config 中定义了以下内容:

 < configuration>< connectionStrings>< add name ="数据库名称"connectionString =" DatabaseURL"/></connectionStrings></configuration> 

要根据不同的环境通过管道变量中的变量来修改 DatabaseName DatabaseURL ,我使用任务

然后根据阶段在变量上将变量 DatabaseName DatabaseURL 定义为秘密:

在这种情况下,将根据阶段将 connectionStrings 修改为其他值.

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?

解决方案

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.

这篇关于Azure管道-使用不同的凭据打开RemoteWebDriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆