私は、Jenkins経由でさまざまなテスト環境(Dev、Stagingなど)で実行する必要があるjunitテストを含むJavaプロジェクトを持っています。Maven、Jenkins - プロジェクトをさまざまなテスト環境に構築する方法は?
さまざまな環境にプロジェクトのビルドをセットアップし、URL、ユーザー名、およびパスワードをmavenに渡す方法を教えてください。
maven 3プロファイルを使用して、プロパティファイルから環境URL、ユーザー名、およびパスワードを読み取ることはできますか?
編集:私は、プロジェクトのPOMにプロファイルを追加しました:
<profiles>
<profile>
<id>Integration</id>
</profile>
<profile>
<id>Staging</id>
</profile>
<profile>
<id>PP1</id>
</profile>
<profile>
<id>PP2</id>
</profile>
<profile>
<id>PP3</id>
</profile>
</profiles>
これらのプロファイルへのURL、ユーザ名とパスワードを渡すためにどのように?
現在のテストはプロパティファイルからテスト環境の詳細を取得されています
public class BoGeneralTest extends TestCase {
protected WebDriver driver;
protected BoHomePage boHomePage;
protected static Properties systemProps;
String url = systemProps.getProperty("Url");
String username = systemProps.getProperty("Username");
String password = systemProps.getProperty("Password");
int defaultWaitTime = Integer.parseInt(systemProps.getProperty("waitTimeForElements"));
static {
systemProps = new Properties();
try {
systemProps.load(new FileReader(new File("src/test/resources/environment.properties")));
} catch (Exception e) {
e.printStackTrace();
}
}
を編集2:
テストランナークラスに実装の変更:
public class BoGeneralTest extends TestCase {
protected WebDriver driver;
protected BoHomePage boHomePage;
protected static Properties systemProps;
String url = systemProps.getProperty("Url");
String username = systemProps.getProperty("Username");
String password = systemProps.getProperty("Password");
int defaultWaitTime = Integer.parseInt(systemProps.getProperty("waitTimeForElements"));
String regUsername = RandomStringUtils.randomAlphabetic(5);
final static String appConfigPath = System.getProperty("appConfig");
static {
systemProps = new Properties();
try {
systemProps.load(new FileReader(new File(appConfigPath)));
} catch (Exception e) {
e.printStackTrace();
}
}
ありがとうございます!それはとても役に立ちます。私は今、プロパティファイルの読み込みのコードを変更するためにstrugglinです。どんな提案も歓迎されます。 –
@AtanasKanchevいくつかのポインタについては、[プロパティのロードに関するこのチュートリアル](http://docs.oracle.com/javase/tutorial/essential/environment/properties.html)を参照してください。私はそれが助けて欲しい:-) – Jonathan
ありがとうジョナサン私はあなたのアプローチを実装しており、うまくいきます。しかし、個々のテストは別々に実行することはできません。なぜなら、mavenからappConfigを受け取る予定であり、NullPointerExceptionを受け取っているからです。 –