代码之家  ›  专栏  ›  技术社区  ›  Dave Hunt

如何从测试中识别运行测试的Selenium网格主机?

  •  5
  • Dave Hunt  · 技术社区  · 16 年前

    我使用Selenium网格和TestNG并行运行测试。我有一些测试需要用户登录,所以我配置了一个用户帐户进行测试。

    • 拥有多个测试用户帐户,并确保一次只使用一个。

    3 回复  |  直到 16 年前
        1
  •  1
  •   Precipitous    14 年前

    我通过设置“我是谁”页面解决了识别遥控器的问题。在我的远程webdriver(或Selenium)工厂中,我访问该页面,将其存储在用于保存会话的类中,并记录它。此页面报告主机名、IP、浏览器类型和版本。

        2
  •  0
  •   Dave Hunt    16 年前

    我通过设置几个纯粹用于测试的唯一用户帐户来解决我的问题,所有帐户都以一个数字结尾(例如:selenium.test1)。使用Selenium,这很容易作为一项一次性任务进行自动化。

    我将这个数字存储在代码中,每次测试需要登录时,这个数字都会递增,并构造用户名。

    在测试结束时,我确实考虑了“释放”,然后重新使用这些帐户,但我认为,为了确保我的测试有大量的测试帐户,比较容易。

        3
  •  0
  •   Slavik    10 年前

    https://groups.google.com/forum/#!topic/selenium-users/8eNRW9JnayQ

     public static String[] getHostNameAndPort(String hostName, int port, SessionId session) {
            String[] hostAndPort = new String[2];
            String errorMsg = "Failed to acquire remote webdriver node and port info. Root cause: ";
    
            try {
                HttpHost host = new HttpHost(hostName, port);
                DefaultHttpClient client = new DefaultHttpClient();
                URL sessionURL = new URL("http://" + hostName + ":" + port + "/grid/api/testsession?session=" + session);
                BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST",
                        sessionURL.toExternalForm());
                HttpResponse response = client.execute(host, r);
                JSONObject object = extractObject(response);
                URL myURL = new URL(object.getString("proxyId"));
                if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {
                    hostAndPort[0] = myURL.getHost();
                    hostAndPort[1] = Integer.toString(myURL.getPort());
                }
            } catch (Exception e) {
                logger.log(Level.SEVERE, errorMsg, e);
                throw new RuntimeException(errorMsg, e);            
            }
            return hostAndPort;
        }
    
    推荐文章