Search code examples
seleniumselenium-rc

Is it possible to start few seleniums for one selenium server?


Is this valid code?

selenium = new DefaultSelenium("localhost", 4444, "*iehta",
        "http://www.google.com/");

selenium.start();

...

selenium.stop();

...

selenium.start();

...

selenium.stop();

Solution

  • That was my fault.

    Unexpected behaviour caused by this code and occurs because I stop selenium two times (selenium object never become null):

    public class SeleniumController {
        private static Selenium selenium; 
    
        public static Selenium startNewSelenium(){
            // if already exists stop it and replace with new one 
            if(selenium != null){
                selenium.stop();
            }
    
            selenium = createNewSelenium(getCurContext());
            return selenium;
        }
    
        public static void stopSelenium() {
            if(selenium != null){
                selenium.stop();
            }
        }   
    
        private static Selenium createNewSelenium(TestContext testContext){
            TestProperties testProps = new TestProperties(testContext);
            ExtendedSelenium selenium = new ExtendedSelenium("localhost", RemoteControlConfiguration.DEFAULT_PORT,
                    testProps.getBrowser(), testProps.getServerUrl());
            selenium.start();
            selenium.useXpathLibrary("javascript-xpath");
            selenium.allowNativeXpath("false");     
            return selenium;
        }  
    }
    

    The correct class code is:

    public class SeleniumController {
        private static Selenium selenium; 
    
        public static Selenium startNewSelenium(){
            // if already exists stop it and replace with new one 
            stopSelenium();        
            selenium = createNewSelenium(getCurContext());
            return selenium;
        }  
    
        public static void stopSelenium() {
            if(selenium != null){
                selenium.stop();
                selenium = null;
            }
        }       
    
        private static Selenium createNewSelenium(TestContext testContext){
            TestProperties testProps = new TestProperties(testContext);
            ExtendedSelenium selenium = new ExtendedSelenium("localhost", RemoteControlConfiguration.DEFAULT_PORT,
                    testProps.getBrowser(), testProps.getServerUrl());
            selenium.start();
            selenium.useXpathLibrary("javascript-xpath");
            selenium.allowNativeXpath("false");     
            return selenium;
        }  
    }