Java 使用selenium登录所有浏览器
有一个问题我两天内无法解决。我需要在同一站点上的多台机器上的多个浏览器中登录。这是一项耗时的任务,所以我决定使用Selenium。我认为问题在于,在运行测试时,selenium并没有保存cookies。我发现将cookie保存在文件中,然后在下一个selenium测试中打开它们是真实的,但我需要所有浏览器都登录以进行手动测试。这是我的密码Java 使用selenium登录所有浏览器,java,selenium,login,Java,Selenium,Login,有一个问题我两天内无法解决。我需要在同一站点上的多台机器上的多个浏览器中登录。这是一项耗时的任务,所以我决定使用Selenium。我认为问题在于,在运行测试时,selenium并没有保存cookies。我发现将cookie保存在文件中,然后在下一个selenium测试中打开它们是真实的,但我需要所有浏览器都登录以进行手动测试。这是我的密码 package automationFramework; import java.io.File; import java.util.concurrent.T
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);
}
}
你到底是什么意思?您是否尝试实现同时访问同一站点的多个浏览器?如果是这样,您将需要设置多个驱动程序实例
如果您想按顺序实现,只需使用一个循环,在该循环中打开驱动程序并获取URL,然后执行操作,然后杀死驱动程序实例,重复操作。请定义所有浏览器。你是说同一浏览器的多个实例吗?我知道我需要设置多个驱动程序实例。但一开始我想用ff来做。我希望用户在运行selenium Test后保持登录到浏览器中,然后您应该使用一个循环,在该循环中打开驱动程序并获取URL,执行您的操作,然后杀死驱动程序实例,重复。