有問題我無法解決2天。我需要在同一網站上的許多計算機上的許多瀏覽器中登錄。這是一項耗時的工作,所以我決定用Selenium來做。我認爲問題在於,運行測試硒時不保存cookie。我發現它真的把文件保存在文件中,然後在下一次硒測試中打開它們,但我需要所有瀏覽器都登錄進行手動測試。這裏是我的代碼用硒登錄所有瀏覽器
package automationFramework;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class FirstTestCase {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
File profileDirectory = new File(
"C:\\Users\\User\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\n8a2y7sp.default");//path to firefox profile
FirefoxProfile profile = new FirefoxProfile(profileDirectory);
driver = new FirefoxDriver(profile);
baseUrl = "http://facebook.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testVk() throws Exception {
driver.get(baseUrl);
driver.findElement(By.id("email")).clear();
driver.findElement(By.id("email")).sendKeys(""); // login
driver.findElement(By.id("pass")).clear();
driver.findElement(By.id("pass")).sendKeys(""); //password
driver.findElement(By.id("loginbutton")).click();
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
請定義**所有瀏覽器**。你的意思是許多同一瀏覽器的實例嗎? – Saifur