문제

I am using Selenium Grid with TestNG to run my tests in parallel. I have certain tests that require a user to be logged in, so I have a user account configured for testing.

I have been careful to ensure that any tests involving logging in as my test user are run on separate virtual machines so that sessions are not interrupted, however after investigating some regularly failing tests it turns out that this is not enough. I therefore either need to:

  • Set up a new user for each test (I understand this may be the ideal solution, but it'll take some time to configure/run.

  • Have multiple test user accounts, and ensure that only one is used at a time.

If I could identify the host of the machine running the test I could set up test accounts accordingly. Is there any way to do this, or is there another solution that I haven't thought of?

도움이 되었습니까?

해결책 2

I solved my problem by setting up several unique user accounts purely for testing, all ending with a number (for example: selenium.test1). This was simple to automate as a one off task using Selenium.

I store this number in code, and every time a test needs to login the number is incremented and the username is constructed.

I did consider 'releasing' and subsequently reusing these accounts when the tests finish, but decided it was easier just to make sure I had plenty of test accounts for my tests.

다른 팁

I solved the problem of identifying the remote by putting up a "who am I page". Within my remote webdriver (or Selenium) factory, I visit that page, store it in that class I use to hold the session, and log it. This page reports Host name, IP, Browser type and version.

Another solution offered here:

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;
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top