Tôi có một dự án Java có chứa các bài kiểm tra junit cần chạy trên các môi trường thử nghiệm khác nhau (Dev, Staging, vv) thông qua Jenkins.Maven, Jenkins - làm thế nào để xây dựng dự án cho các môi trường thử nghiệm khác nhau?
Làm cách nào tôi có thể thiết lập việc xây dựng dự án cho các môi trường khác nhau và cách chuyển url, tên người dùng và mật khẩu cho maven?
Tôi có thể sử dụng 3 tiểu sử maven để đọc url môi trường, tên người dùng và mật khẩu từ tệp thuộc tính không?
Edit: Tôi đã thêm các cấu hình cho POM dự án:
<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>
Làm thế nào để vượt qua url, tên người dùng và mật khẩu để các cấu hình?
Hiện nay các thử nghiệm được thu thập các chi tiết môi trường thử nghiệm từ một tập tin bất động sản:
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();
}
}
Chỉnh sửa 2:
Sự thay đổi thực hiện trong lớp thử nghiệm Á hậu:
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();
}
}
Cảm ơn bạn! Điều đó rất hữu ích. Bây giờ tôi đang đấu tranh để thay đổi mã để tải tập tin thuộc tính. Bất kỳ lời đề nghị sẽ được hoan nghênh: cung. –
@AtanasKanchev Hãy xem [hướng dẫn này về tải thuộc tính] (http://docs.oracle.com/javase/tutorial/essential/environment/properties.html) cho một số gợi ý. Tôi hy vọng rằng sẽ giúp. :-) – Jonathan
Cảm ơn Jonathan Tôi đã thực hiện phương pháp tiếp cận của bạn và nó hoạt động tốt. Có một nhược điểm mặc dù bây giờ các bài kiểm tra cá nhân không thể chạy riêng vì họ mong nhận được appConfig từ maven và tôi nhận được NullPointerException –