Selenium Grid,Xvfb节点和Jenkins

时间:2016-09-18 15:11:57

标签: selenium jenkins selenium-webdriver selenium-grid xvfb

使用Jenkins作业在Xvfb节点的firefox浏览器中运行测试时出现以下错误

    Starting Xvfb firefox setup
FAILED CONFIGURATION: @BeforeMethod setUp("firefox", "http://xxxx:5555/wd/hub")
org.openqa.selenium.WebDriverException: java.util.HashMap cannot be cast to java.lang.String
Command duration or timeout: 295 milliseconds
Build info: version: '2.52.0', revision: '4c2593cfc3689a7fcd7be52549167e5ccc93ad28', time: '2016-02-11 11:22:43'
System info: host: 'bg-bci-sip', ip: '192.168.78.44', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-279.el6.x86_64', java.version: '1.7.0_111'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:158)
    at com.sip.helper.BrowserFactory.getDriver(BrowserFactory.java:84)
    at com.sip.tests.JbpmWorkflowTest.setUp(JbpmWorkflowTest.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:653)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.access$000(SuiteRunner.java:37)
    at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:368)
    at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String
    at org.openqa.selenium.firefox.FirefoxDriver.getBinary(FirefoxDriver.java:200)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:128)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.openqa.selenium.remote.server.FirefoxDriverProvider.callConstructor(FirefoxDriverProvider.java:91)
    at org.openqa.selenium.remote.server.FirefoxDriverProvider.newInstance(FirefoxDriverProvider.java:68)
    at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:60)
    at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:222)
    at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
    ... 3 more

以下是我的设置

机器A(CentOS) -
1)执行以下命令......

yum install Xvfb firefox
Xvfb :1 -screen 0 1024x768x24 &
export DISPLAY=:1

2)安装Jenkins

3)启动Grid Hub

4)使用以下命令

启动网格节点(Xvfb)
xvfb-run java -jar selenium-server-standalone-2.25.0.jar -role node -hub http://localhost:4444/grid/register

以下是我的测试代码

BrowserFactory.java类

public class BrowserFactory {
static RemoteWebDriver driver;
static String baseUrl;
static String nodeUrl;
public static RemoteWebDriver getDriver(String browser, String remoteUrl) throws MalformedURLException {
    return new RemoteWebDriver(new URL(remoteUrl), getBrowserCapabilities(browser));
}

private static DesiredCapabilities getBrowserCapabilities(String browserType) {
    DesiredCapabilities capabillities = null;
    switch (browserType) {
    case "firefox":
        System.out.println("Starting Xvfb firefox setup");
        String Xport = System.getProperty("lmportal.xvfb.id", ":1");
        final File firefoxPath = new File(System.getProperty("lmportal.deploy.firefox.path", "/usr/bin/firefox"));
        FirefoxBinary firefoxBinary = new FirefoxBinary(firefoxPath);
        firefoxBinary.setEnvironmentProperty("DISPLAY", Xport);
        capabillities=new DesiredCapabilities().firefox();
        capabillities.setCapability(FirefoxDriver.BINARY,firefoxBinary);
        capabillities.setBrowserName("firefox");
        capabillities.setPlatform(Platform.LINUX);
        return capabillities;
    case "chrome":
        System.out.println("Opening chrome driver");
        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
        capabillities= new DesiredCapabilities().chrome();
        capabillities.setBrowserName("chrome");
        capabillities.setPlatform(Platform.VISTA);
        return capabillities;
    default:
        System.out.println("browser : " + browserType + " is invalid, Launching Firefox as browser of choice..");
        return DesiredCapabilities.firefox();
    }
    }

JbpmWokflowTest.java类

public class JbpmWorkflowTest {
static RemoteWebDriver driver;
public static LoginPage loginPage;
public static BasePage basePage;
public static EmailConnectorRoutinePage emailConnectorRoutine;
public static EmailTemplateEditorPage emailTemplateEditorPage;
public static MailboxScannerPage mailboxScannerPage;
public static ProcessDeploymentPage processDeploymentPage;
public static ProcessDefinitionPage processDefinitionPage;
public static CommonActions commonActions;
private static ExtentReports report;
ExtentTest logger;

@BeforeSuite
public void beforeSuite() {
    report= new ExtentReports("result-output/SIP-UI-Automation.html", true);
}

@BeforeMethod
@Parameters({ "browser", "remoteUrl" })
public void setUp(String browser, String remoteUrl) throws MalformedURLException {
    System.out.println("*******************");
    driver = BrowserFactory.getDriver(browser,remoteUrl);
    driver.get("http://xxxxxx:8080/jbpm-console");
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    commonActions = new CommonActions(driver);
}

@Parameters({ "username", "password", "browser" })
@Test
public void checkValidUser(String username, String password, String browser) throws Exception{
    try{
        System.out.println("-----------------------------Starting Checkvalid user test case----------------------");
        logger= report.startTest("checkValidUser"+browser+"");
        loginPage = PageFactory.initElements(driver, LoginPage.class);
        loginPage.LogIn_Action(username,password);
        logger.log(LogStatus.INFO, "Login Details Entered "+browser+"");
        basePage = PageFactory.initElements(driver, BasePage.class);
        basePage.UserDropDownClick();
        logger.log(LogStatus.INFO, "User Drop down clicked");
        Assert.assertEquals(true,basePage.VerifyPresenceLogout());
        logger.log(LogStatus.PASS, "User logged in successfully");

    }
    catch(Exception e)
    {
        e.printStackTrace();
        throw new Exception(e.getMessage());
    }
 }
@AfterMethod
    protected void afterMethod(ITestResult result) 
    {
        if (result.getStatus()==ITestResult.FAILURE){

            String screenShot_path=commonActions.captureScreenshot(driver, result.getName());
            String image=logger.addScreenCapture(screenShot_path);
            logger.log(LogStatus.FAIL,result.getName(),image );
        }
        report.endTest(logger);
        report.flush();
        //driver.close();
        driver.quit();
    }
}

0 个答案:

没有答案