我正在努力确定为什么我的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();
}
}
答案 0 :(得分:3)
Firefox最近更新为13.您只需要升级到Selenium 2.23
答案 1 :(得分:0)
我在从属Jenkins节点上运行Selenium IDE测试套件时遇到了同样的问题。我也尝试删除FirefoxProfile目录但没有成功。我注意到该机器上的Firefox版本最近更新了。将更新回滚到版本12后,此问题消失了(不知道是否有其他版本可以执行此操作)。这是旧版Firefox发布的链接。