java - 如何在 Jenkins 上为 Maven/Java 项目实现 selenium 测试?

标签 java maven selenium jenkins junit

friend 。我试图了解 Selenium 是如何工作的。我用 JUnit 4 编写了一些测试。当我的应用程序正在运行时,这些测试工作正常,我将 URL localhost:8077 作为我的应用程序的启动位置。所有测试都按我的需要通过。但现在我希望我的 war 构建将取决于这些测试。在这些之后,我希望自动发布 (Jenkins) 也将取决于 selenium 测试。 我不明白一些事情:

  1. selenium 测试应该包含在我的应用程序中,还是应该组合在一个独立的应用程序中? (我阅读了有关 Selenium Grid 的信息,但不确定是否需要它)?
  2. 我有一台开发机器、一台装有 jenkins 的服务器和一台生产服务器。实现 Selenium 测试需要哪些步骤?测试中应该使用什么网址? Tomcat Server是否需要和Jenkins安装在同一台服务器上?
  3. 如果 selenium 测试未通过,我能否使构建无效并在 Jenkins 上删除发布?

最佳答案

Should the selenium test be included in my application or they should be assembled in a standalone application? (I read about Selenium Grid but I am not sure that I need it)?

这取决于您希望如何运行测试。最佳实践是在您的 Maven 项目中调用测试配置,测试将在您的构建作业期间运行。您也可以在构建完成后调用您的 Maven 目标。

Selenium Grid 很有用,但前提是您有专门的机器进行适当的设置来运行这些测试,否则您的测试可能经常失败。您应该考虑使用 Saucelabs 等服务在云端远程运行测试。

I have one developer machine, one server with jenkins and the production server. What are the needed steps to implement Selenium test? What Url should be used in test? Is it needed to install Tomcat Server on the same server with Jenkins?

Selenium 测试可以按照 here 中的步骤在 Jenkins 上使用 Maven 实现, herehere .

应使用开发或测试 URL 来运行测试。

如果您在 Jenkins 机器上托管您的应用程序,我认为您将需要 Tomcat 服务器,否则不需要它。

Can I invalidate the build and drop the release on Jenkins if selenium tests are not passed?

当您在项目配置中包含测试配置时,如果测试失败,则构建可能会在构建作业期间失败。您可以设置在测试失败时如何继续构建,例如构建失败或通过警告构建。您可能还想收到构建失败的通知。

例。 Jenkins marks good build as failure because of test failed

Jenkins plugins可以根据需要使用。

You may like to read more about How to do Integration tests here.

关于java - 如何在 Jenkins 上为 Maven/Java 项目实现 selenium 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31012601/

相关文章:

java - 来自 Vaadin Grid ButtonRender 的 PopupView

java - 尝试从多个 Maven 模块构建 uberjar

javascript - 在 Selenium/Python 中清除 Chrome 浏览器日志

java - 无法连接到端口 7056 上的二进制 FirefoxBinary(C :\Program Files (x86)\Mozilla Firefox\firefox. exe);处理输出如下: null

selenium - 使用 Robot Framework Test 在浏览器中上传文件

java - joda 时区 id 与 java 时区 id 相同吗?

java - 在 IBM Websphere 8 中使用 axis2 (Sales Force) 访问 Web 服务时出现异常

java - 从 List<CompletableFuture> 转换为 CompletableFuture<List>

java - 如何将 spring mvc 应用程序打包到 jar 中?

maven - 从依赖项加载资源