尝试使用MVN测试命令行运行selenium测试时,出现此错误。奇怪的是,我三天前尝试了一下,并成功运行了:
------------------------------------------------------ T E S T S ------------------------------------------------------- Running GoogleNavigationTest Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 45.672 sec <<< FAILURE! Results : Failed tests: testApp(GoogleNavigationTest): Unable to bind to locking port 70 54 within 45000 ms Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
这是我的测试:
import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.testng.annotations.Test; public class GoogleNavigationTest { @Test public void testApp(){ // The Firefox driver supports javascript FirefoxProfile firefoxProfile = new FirefoxProfile(); WebDriver driver = new FirefoxDriver(); // Go to the Google Suggest home page driver.get("http://www.google.com/webhp?complete=1&hl=en"); // Enter the query string "Cheese" WebElement query = driver.findElement(By.name("q")); query.sendKeys("Cheese"); // Sleep until the div we want is visible or 5 seconds is over long end = System.currentTimeMillis() + 5000; while (System.currentTimeMillis() < end) { WebElement resultsDiv = driver.findElement(By.className("gssb_e")); // If results have been returned, the results are displayed in a drop down. if (resultsDiv.isDisplayed()) { break; } } // And now list the suggestions List<WebElement> allSuggestions = driver.findElements(By.xpath("//td[@class='gssb_a gbqfsf']")); for (WebElement suggestion : allSuggestions) { System.out.println(suggestion.getText()); } } }
我只是使用chromeDriver,它工作正常。