我正在努力确定为什么我的 Selenium 测试脚本现在在我的构建服务器上失败了,因为它们一直工作到上周。下面的脚本在本地运行良好,但从 Jenkins 运行时出错。我正在运行 Selenium Server (v.selenium-server-standalone-2.21.0.jar),并尝试执行一个简单的登录脚本。
我已经确认没有打开的 Firefox 会话,并且我已经删除了所有配置文件以确保没有争用。
这是错误输出:
[junit] 08:38:27.016 INFO - Command request: getNewBrowserSession[*firefox, http://gamma:31640/aferewrite/login/, ] on session null
[junit] 08:38:27.016 INFO - creating new remote session
[junit] 08:38:27.032 INFO - Allocated session b61c10f039764b0fa49ef3c85b9d0648 for http://gamma:31640/aferewrite/login/, launching...
[junit] 08:38:27.110 INFO - Preparing Firefox profile...
[junit] 08:38:48.173 ERROR - Failed to start new browser session, shutdown browser and clear all session data
[junit] java.lang.RuntimeException: Firefox refused shutdown while preparing a profile
[junit] at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.waitForFullProfileToBeCreated(FirefoxChromeLauncher.java:367)
[junit] at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.populateCustomProfileDirectory(FirefoxChromeLauncher.java:120)
[junit] at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.launch(FirefoxChromeLauncher.java:90)
[junit] at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.launchRemoteSession(FirefoxChromeLauncher.java:412)
[junit] at org.openqa.selenium.server.browserlaunchers.FirefoxLauncher.launchRemoteSession(FirefoxLauncher.java:114)
[junit] at org.openqa.selenium.server.BrowserSessionFactory.createNewRemoteSession(BrowserSessionFactory.java:381)
[junit] at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:125)
[junit] at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:86)
[junit] at org.openqa.selenium.server.SeleniumDriverResourceHandler.getNewBrowserSession(SeleniumDriverResourceHandler.java:811)
[junit] at org.openqa.selenium.server.SeleniumDriverResourceHandler.doCommand(SeleniumDriverResourceHandler.java:437)
[junit] at org.openqa.selenium.server.SeleniumDriverResourceHandler.handleCommandRequest(SeleniumDriverResourceHandler.java:407)
[junit] at org.openqa.selenium.server.SeleniumDriverResourceHandler.handle(SeleniumDriverResourceHandler.java:151)
[junit] at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
[junit] at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
[junit] at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
[junit] at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
[junit] at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
[junit] at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
[junit] at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
[junit] at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
[junit] at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
[junit] Caused by: org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher$FileLockRemainedException: Lock file still present! C:\WINDOWS\TEMP\customProfileDirb61c10f039764b0fa49ef3c85b9d0648\parent.lock
[junit] at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.waitForFileLockToGoAway(FirefoxChromeLauncher.java:318)
[junit] at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.waitForFullProfileToBeCreated(FirefoxChromeLauncher.java:365)
[junit] ... 20 more
[junit] 08:38:48.188 INFO - Got result: Failed to start new browser session: Error while launching browser on session null
[junit] 08:38:48.188 INFO - Stopping Acceptor ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=4444]
[junit] 08:38:48.298 INFO - Stopped SocketListener on 0.0.0.0:4444
[junit] 08:38:48.344 INFO - Stopped HttpContext[/selenium-server/driver,/selenium-server/driver]
[junit] 08:38:48.376 INFO - Stopped HttpContext[/selenium-server,/selenium-server]
[junit] 08:38:48.407 INFO - Stopped HttpContext[/,/]
[junit] 08:38:48.407 INFO - Stopped org.openqa.jetty.jetty.servlet.ServletHandler@1cfb802
[junit] 08:38:48.454 INFO - Stopped HttpContext[/wd,/wd]
[junit] 08:38:48.454 INFO - Stopped org.openqa.jetty.jetty.Server@da2cef
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 21.907 sec
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 21.907 sec
[junit]
[junit] ------------- Standard Output ---------------
[junit] 08:38:26.829 INFO - Java: Sun Microsystems Inc. 19.1-b02
[junit] 08:38:26.829 INFO - OS: Windows 2003 5.2 x86
[junit] 08:38:26.829 INFO - v2.21.0, with Core v2.21.0. Built from revision 16552
[junit] 08:38:26.938 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
[junit] 08:38:26.938 INFO - Version Jetty/5.1.x
[junit] 08:38:26.938 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
[junit] 08:38:26.938 INFO - Started HttpContext[/selenium-server,/selenium-server]
[junit] 08:38:26.938 INFO - Started HttpContext[/,/]
[junit] 08:38:26.969 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@1cfb802
[junit] 08:38:26.969 INFO - Started HttpContext[/wd,/wd]
[junit] 08:38:26.969 INFO - Started SocketListener on 0.0.0.0:4444
[junit] 08:38:26.969 INFO - Started org.openqa.jetty.jetty.Server@da2cef
[junit] 08:38:27.016 INFO - Checking Resource aliases
[junit] 08:38:27.016 INFO - Command request: getNewBrowserSession[*firefox, http://gamma:31640/aferewrite/login/, ] on session null
[junit] 08:38:27.016 INFO - creating new remote session
[junit] 08:38:27.032 INFO - Allocated session b61c10f039764b0fa49ef3c85b9d0648 for http://gamma:31640/aferewrite/login/, launching...
[junit] 08:38:27.110 INFO - Preparing Firefox profile...
[junit] 08:38:48.188 INFO - Got result: Failed to start new browser session: Error while launching browser on session null
[junit] 08:38:48.188 INFO - Stopping Acceptor ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=4444]
[junit] 08:38:48.298 INFO - Stopped SocketListener on 0.0.0.0:4444
[junit] 08:38:48.344 INFO - Stopped HttpContext[/selenium-server/driver,/selenium-server/driver]
[junit] 08:38:48.376 INFO - Stopped HttpContext[/selenium-server,/selenium-server]
[junit] 08:38:48.407 INFO - Stopped HttpContext[/,/]
[junit] 08:38:48.407 INFO - Stopped org.openqa.jetty.jetty.servlet.ServletHandler@1cfb802
[junit] 08:38:48.454 INFO - Stopped HttpContext[/wd,/wd]
[junit] 08:38:48.454 INFO - Stopped org.openqa.jetty.jetty.Server@da2cef
[junit] ------------- ---------------- ---------------
以下是测试脚本:
package com.mapfre.afetest.util;
import java.util.Arrays;
import java.util.Collection;
import java.util.Vector;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.logging.StreamHandler;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.openqa.selenium.server.SeleniumServer;
/*
* Execute Selenium test case using Excel data
*/
public class AfeSimpleLoginLogout extends SeleneseTestBase {
private static SeleniumServer seleniumServer;
public static Vector paramData = new Vector();
public static Vector testMethod = new Vector();
TestData td = new TestData("C:\\tools\\jexcelapi\\afe_testdata.xls");
@Before
public void setUp() throws Exception {
td.getDatafromXL();
paramData = td.getParamData();
testMethod = td.getTestMethods();
selenium = new DefaultSelenium("localhost", 4444, "*firefox",
"http://gamma:31640/aferewrite/login/");
seleniumServer = new SeleniumServer();
seleniumServer.start();
selenium.start();
}
@Test
public void testAfeSimpleLogin() throws Exception {
// set up new logger with output directed to standard out
Logger logger = Logger.getLogger("my.test.logger");
StreamHandler sh = new StreamHandler(System.out, new SimpleFormatter());
logger.addHandler(sh);
logger.info("-- Starting login process");
String workspace;
workspace = System.getProperty("workspace");
logger.info("-- is there a value for workspace? val: " + workspace);
// turn off parent handlers
logger.setUseParentHandlers(false);
// login based on Excel values and wait for main page
selenium.open(paramData.get(0).toString());
selenium.type("j_username", paramData.get(1).toString());
selenium.type("j_password", paramData.get(2).toString());
logger.info("-- Clicking the submit button and waiting");
selenium.click("css=button.submitBtn");
selenium.waitForPageToLoad("300000");
logger.info("-- Looking for 'Policy changes should be requested' string on screen");
assertTrue(selenium.isTextPresent("Policy changes should be requested through one of the following contact points"));
logger.info("-- Now logout");
selenium.click("link=Logout");
// FLUSH THE STREAM HANDLER !!!
sh.flush();
}
@After
public void tearDown() throws Exception {
selenium.stop();
seleniumServer.stop();
}
}