亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Maven 中為 Selenium/Cucumber 使用不同環境的配置文件屬性

在 Maven 中為 Selenium/Cucumber 使用不同環境的配置文件屬性

眼眸繁星 2021-12-10 10:46:07
我使用基于 Maven 構建的 Selenium WebDriver 和 Cucumber-jvm 創建測試。接下來我想實現:我想擁有帶有屬性的配置文件,并根據環境在我的步驟中使用此屬性。我在其中創建了一個文件夾src/test/resources并在其中添加了 2 個子文件夾:Staging和Dev.在每個文件夾中,我都有一個config.properties保存username.我的 POM 看起來像:<profiles>    <profile>        <id>staging</id>        <activation>            <activeByDefault>true</activeByDefault>        </activation>        <properties>        </properties>    </profile>    <profile>        <id>dev</id>        <properties>        </properties>    </profile></profiles>現在我想將配置文件的屬性更改為這樣的:<properties> test/resources/dev/config.properties</properties><properties> test/resources/staging/config.properties</properties>我希望當我在我的步驟 defs 中使用活動暫存配置文件運行我的測試時:system.getProperty("username")我希望它返回usernamestaging 的屬性中提供的。當我在devprofile 處于活動狀態時運行它時,我想獲取dev的屬性。
查看完整描述

2 回答

?
撒科打諢

TA貢獻1934條經驗 獲得超2個贊

向您的個人資料添加屬性,例如:


<propertiesFile>staging.properties</propertiesFile>



<propertiesFile>dev.properties</propertiesFile>

相應地命名不同的屬性文件并src/test/resources直接放置它們。

使用 Maven 復制文件的最佳實踐中config.properties描述的選項之一將相應的屬性文件復制到${propertiesFile}。我更喜歡 Wagon Maven 插件。

更新


這意味著:忘記包含兩個屬性文件的兩個額外目錄。將它們都放入src/test/resources/并根據以下內容復制它們:


staging

src/test/resources/staging.properties 復制到:


src/test/resources/config.properties

或者 target/config.properties

取決于您將復制過程綁定到的階段。


dev

src/test/resources/dev.properties 復制到:


src/test/resources/config.properties

或者 target/config.properties

取決于您將復制過程綁定到的階段。


查看完整回答
反對 回復 2021-12-10
?
拉莫斯之舞

TA貢獻1820條經驗 獲得超10個贊

我的解決方案是這樣的:

  1. 使用 Spring Boot外部配置。我們可以設置application-{profile}.propertiesapplication-{profile}.yaml根據您的喜好設置。將環境變量(例如主機名、uri、憑據等)放在那里。如果我們需要所有環境的變量,只需將它們放入application.propertiesor 中application.yaml。

  2. 使用 maven 參數相應spring.profiles.active地激活配置文件。以下命令是 CI/CD 中的一個用例:

    mvn clean verify -Dspring.profiles.active={profile} ..........


查看完整回答
反對 回復 2021-12-10
  • 2 回答
  • 0 關注
  • 225 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號