简体   繁体   中英

Selenium error on Win7

I'm starting Selenium server with the following on a command line:

java -jar selenium-server.jar

Here is the code:

import com.thoughtworks.selenium.*;  
import java.util.regex.Pattern;  

import org.openqa.selenium.server.SeleniumServer;

import junit.framework.*;  

public class orkut extends SeleneseTestCase {   
    public void setUp() throws Exception {    
        //SeleniumServer server = new SeleniumServer();
        //server.start();


        setUp("https://www.google.com/", "*firefox C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");   
    }  

    public void testOrkut() throws Exception {    
        selenium.setTimeout("10000");    
        selenium.open("/accounts/ServiceLogin?service=orkut&hl=en-US&rm=false&continue=http%3A%2F%2Fwww.orkut.com%2FRedirLogin%3Fmsg%3D0&cd=IN&skipvpage=true&sendvemail=false");    
        selenium.type("Email", "username");    
        selenium.type("Passwd", "password");    
        selenium.click("signIn");    
        selenium.selectFrame("orkutFrame");    
        selenium.click("link=Communities");    
        selenium.waitForPageToLoad("10000");   
        }   

    public static Test suite() {    
        return new TestSuite(orkut.class);   
        }   

    public void tearDown(){    
        selenium.stop();   
    }   

    public static void main(String args[]) {    
        junit.textui.TestRunner.run(suite());  
    }  
}

Here is the error:

.E
Time: 33.386
There was 1 error:
1) testOrkut(orkut)java.lang.RuntimeException: Could not start Selenium session:     Failed to start new browser session: Unable to delete file     C:\Users\user\AppData\Local\Temp\customProfileDir78cf02e3efca4772a71525c4a7523cac\parent.lock
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:89)
at com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:123)
at com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:104)
at com.thoughtworks.selenium.SeleneseTestCase.setUp(SeleneseTestCase.java:78)
at orkut.setUp(orkut.java:14)
at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:212)
at orkut.main(orkut.java:37)
Caused by: com.thoughtworks.selenium.SeleniumException: Failed to start new browser session: Unable to delete file C:\Users\M022534\AppData\Local\Temp\customProfileDir78cf02e3efca4772a71525c4a7523cac\parent.lock
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:262)
at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:223)
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:81)
... 16 more

FAILURES!!!
Tests run: 1,  Failures: 0,  Errors: 1

On the advise of answerers - I've modified the code to this:

package file;

import com.thoughtworks.selenium.*; import org.openqa.selenium.server.SeleniumServer;

public class Reset extends SeleneseTestCase {

private SeleniumServer seleniumServer;

private Selenium selenium = new DefaultSelenium("localhost", 4444,
        "*chrome", "http://");

public void setUp() throws Exception {
    seleniumServer = new SeleniumServer();
    seleniumServer.start();
    selenium.start();
}

// Test methods shd go here
public void tearDown() throws Exception {
    selenium.stop();
    seleniumServer.stop();
}

public void testOrkut() throws Exception {    
    selenium.setTimeout("10000");    
    selenium.open("/accounts/ServiceLogin?service=orkut&hl=en-US&rm=false&continue=http%3A%2F%2Fwww.orkut.com%2FRedirLogin%3Fmsg%3D0&cd=IN&skipvpage=true&sendvemail=false");    
    selenium.type("Email", "username");    
    selenium.type("Passwd", "password");    
    selenium.click("signIn");    
    selenium.selectFrame("orkutFrame");    
    selenium.click("link=Communities");    
    selenium.waitForPageToLoad("10000");   
    }   

}

This now hangs with the output:

11:22:15.571 INFO - Java: Sun Microsystems Inc. 16.3-b01
11:22:15.571 INFO - OS: Windows 7 6.1 x86
11:22:15.586 INFO - v1.0.1 [2696], with Core v@VERSION@ [@REVISION@]
11:22:15.686 INFO - Version Jetty/5.1.x
11:22:15.686 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
11:22:15.686 INFO - Started HttpContext[/selenium-server,/selenium-server]
11:22:15.686 INFO - Started HttpContext[/,/]
11:22:15.686 INFO - Started SocketListener on 0.0.0.0:4444
11:22:15.686 INFO - Started org.mortbay.jetty.Server@1f630dc
11:22:15.748 INFO - Checking Resource aliases
11:22:15.748 INFO - Command request: getNewBrowserSession[*chrome, http://, ] on session null
11:22:15.764 INFO - creating new remote session
11:22:16.435 INFO - Allocated session dc869f4254414d05b7f1d028dcf33123 for http://, launching...
11:22:16.559 INFO - Preparing Firefox profile...

There do appear to be two firefox processes running - but no screens appearing.

This occurs whether I run eclipse in Administrator mode or not.

If I kill one firefox process, then a Firefox window appears, but doesn't open anything.

What's wrong with Selenium in Win7?

It looks like you need to initialize selenium in your setup (Point to the correct selenium server, port, browser, etc). Put the following code in the setup and see if this works better. Also, try out using the *chrome command for firefox instead of *firefox. It seems to work better.

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

This link has program structure which can be used in all test cases,

http://seleniumready.blogspot.com/2010/12/code-to-start-and-stop-selenium-server.html

have a look at it.. Cheers!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM