在 Jenkins 中针对某个 selenium 实例运行 selenium 2 测试

发布于 2024-11-26 02:49:37 字数 322 浏览 0 评论 0原文

我正在尝试从詹金斯运行无头测试。当我指定 HTML 测试套件时,这对于 HTML 测试效果很好。但现在我想对同一台 selenium 服务器运行 selenium-2 测试。

我尝试了这个:

执行 shell:
导出 DISPLAY=":99" && java -jar /var/lib/selenium/selenium-server.jar

但这似乎一直挂起,直到我手动停止服务器。如何启动 selenium 服务器,以便通过 grails 调用我的 selenium RC 测试?

I'm trying to run headless tests from Jenkins. This works fine for HTML tests when I specify the HTML test suite. But now I want to run selenium-2 tests against the same selenium server.

I tried this:

Execute shell:
export DISPLAY=":99" && java -jar /var/lib/selenium/selenium-server.jar

But this seems to be hang until I stopped the server manually. How do I start the selenium server in such a way that my selenium RC tests invoked through grails ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攒一口袋星星 2024-12-03 02:49:37

没有特殊的方法来“启动”任何特定语言使用的 selenium 服务器。当您启动 selenium 服务器时,它将开始侦听端口上的传入请求。您的测试中应该有一行代码将您的测试指向 selenium 服务器。我不知道圣杯。在java中它将是

Selenium sel = new DefaultSelenium("host","port","browsername","baseurl")
  • > host - 启动服务器的机器的 IP
  • > port - selenium 服务器正在侦听的端口号。这是
    如果您不指定任何内容
  • ,通常为 4444 > browsername - 您希望测试的浏览器
  • >运行 baseURL - 您需要测试的 Web 应用程序的基本 URL。

grails 中的等效方法应该可以帮助您工作。

编辑-启动selenium服务器的JAVA代码:

    Selenium sel;
    int port=9999;
    public static SeleniumServer server;
        public void startSeleniumServer() throws Exception {
           try {
            ServerSocket serverSocket = new ServerSocket(port);
            serverSocket.close();
                    //Server not up, start it
                    try {
                     RemoteControlConfiguration rcc = new RemoteControlConfiguration();
                     rcc.setPort(port);
                     server = new SeleniumServer(false, rcc);

                    } catch (Exception e) {
                        System.err.println("Could not create Selenium Server because of: "
                                + e.getMessage());
                        e.printStackTrace();
                    }
                    try {
                        server.start();
                        System.out.println("Server started");
                    } catch (Exception e) {
                        System.err.println("Could not start Selenium Server because of: "
                                + e.getMessage());
                        e.printStackTrace();
                    }
                } catch (BindException e) {
                    System.out.println("Selenium server already up, will reuse...");
                }
        }

        public void stopSeleniumServer(){
            if (server != null)
              {
                 try
                 {
                    server.stop();

                 }
                 catch (Exception e)
                 {
                    e.printStackTrace();
                 }
              }
            System.out.println("Selenium server stopped..");
        }

    public void startSeleniumRC() throws Exception{
        sel=new DefaultSelenium("localhost",
                port,
                "*firefox",
                "http://www.google.com");
        sel.start();
    }

    public void stopSeleniumRC()
    {
        sel.shutDownSeleniumServer();
    }

There is no special method to "start" selenium server to be used by any particular language. When you start selenium server it will start listening on a port for incoming requests. You should be having a line of code inside your tests to point your tests to the selenium server. I don't know grails. In java it would be

Selenium sel = new DefaultSelenium("host","port","browsername","baseurl")
  • > host - IP of the machine where server is started
  • > port - port number on which selenium server is listening. This is
    usually 4444 if you don't specify anything
  • > browsername-Browser on which you want the tests to be
  • > run baseURL- base URL of the web app you need to test.

The equivalent method for this in grails should get you working.

EDIT - JAVA code to start selenium server:

    Selenium sel;
    int port=9999;
    public static SeleniumServer server;
        public void startSeleniumServer() throws Exception {
           try {
            ServerSocket serverSocket = new ServerSocket(port);
            serverSocket.close();
                    //Server not up, start it
                    try {
                     RemoteControlConfiguration rcc = new RemoteControlConfiguration();
                     rcc.setPort(port);
                     server = new SeleniumServer(false, rcc);

                    } catch (Exception e) {
                        System.err.println("Could not create Selenium Server because of: "
                                + e.getMessage());
                        e.printStackTrace();
                    }
                    try {
                        server.start();
                        System.out.println("Server started");
                    } catch (Exception e) {
                        System.err.println("Could not start Selenium Server because of: "
                                + e.getMessage());
                        e.printStackTrace();
                    }
                } catch (BindException e) {
                    System.out.println("Selenium server already up, will reuse...");
                }
        }

        public void stopSeleniumServer(){
            if (server != null)
              {
                 try
                 {
                    server.stop();

                 }
                 catch (Exception e)
                 {
                    e.printStackTrace();
                 }
              }
            System.out.println("Selenium server stopped..");
        }

    public void startSeleniumRC() throws Exception{
        sel=new DefaultSelenium("localhost",
                port,
                "*firefox",
                "http://www.google.com");
        sel.start();
    }

    public void stopSeleniumRC()
    {
        sel.shutDownSeleniumServer();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文