Selenium webdriver 如何让Selenium 2 webdriver每晚使用(Firefox 64位)
我希望对夜间浏览器(FireFox 64位)执行Selenium 2测试。它使用Selenium IDE(v1.8.1)记录良好。使用IDE,它也可以正常播放。然后我将代码导出为TestNG格式。顺便说一句,我已经加载了Webdriver支持的插件,因此它导出了Selenium 2版本的Webdriver代码。我遇到的问题是,当我将代码导出为TestNG格式(Java)并执行它时,断言永远不会在屏幕上找到文本。它执行得很好,所以不是代码没有转换。这似乎与资产有关。如果我从IDE插件播放它,它会找到文本并断言,但是一旦它在Java中执行,所有断言都会失败。任何关于可能发生的事情的想法。我的代码如下。多谢Selenium webdriver 如何让Selenium 2 webdriver每晚使用(Firefox 64位),selenium-webdriver,testng,Selenium Webdriver,Testng,我希望对夜间浏览器(FireFox 64位)执行Selenium 2测试。它使用Selenium IDE(v1.8.1)记录良好。使用IDE,它也可以正常播放。然后我将代码导出为TestNG格式。顺便说一句,我已经加载了Webdriver支持的插件,因此它导出了Selenium 2版本的Webdriver代码。我遇到的问题是,当我将代码导出为TestNG格式(Java)并执行它时,断言永远不会在屏幕上找到文本。它执行得很好,所以不是代码没有转换。这似乎与资产有关。如果我从IDE插件播放它,它会找
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static junit.framework.Assert.*;
import com.thoughtworks.selenium.Selenium;
public class TestWithConfig {
WebDriver driver;
Selenium selenium;
@BeforeMethod
public void startSelenium() {
driver = new FirefoxDriver();
selenium = new WebDriverBackedSelenium(driver,
"http://en.wikipedia.org/wiki/Main_Page");
}
@AfterMethod
public void stopSelenium() {
driver.close();
}
@Test
public void testTest() {
selenium.setSpeed("600");
selenium.open("/wiki/Main_Page");
assertTrue("face not found",selenium.isTextPresent("face"));
selenium.click("link=Contents");
selenium.waitForPageToLoad("30000");
assertTrue("Below not found",selenium.isTextPresent("Below"));
selenium.click("link=Toolbox");
selenium.click("link=What links here");
selenium.waitForPageToLoad("30000");
assertTrue("Pages not found",selenium.isTextPresent("Pages that link to"));
selenium.click("link=exact:Talk:Wine");
selenium.waitForPageToLoad("30000");
assertTrue("Some not found",selenium.isTextPresent("Some"));
}
}
由于您使用的是selenium 2和webdriver,Assert的工作有些不同。我可以看到您正在使用WebDriverBackedSelenium。但是请记住。那不是硒。这只是一种轻松进入selenium 2的方法。我会用这样的东西
WebElement tooltip = driver.findElement(By.xpath("the xpath of the element"));
assertNotNull("Name:","IP Address:",tooltip);
我在这里做的是。我正在寻找工具提示。在该工具提示中,有两个主要标签保持不变:名称和IP地址:。所以我正在测试这些单词是否存在于工具提示中。输出应为名称:IP地址:。这告诉我答案是正确的。如果您a)降级Firefox并重新运行测试,b)尝试使用其他驱动程序,会发生什么情况?我已尝试加载3.6版本,但失败了。同时,我也在尽可能地做到最新,以便测试是相关的。我的要求是尽可能使用最新版本的FF。对于你的第二个建议,你会建议其他的驱动程序吗?听起来是个不错的解决方案。一、 然而,有一个团队愿意使用Selenium IDE Firefox插件来记录他们的脚本。如果我没记错的话,脚本并不能真正转换成这种类型的代码。我可能最终会手工编写我所有的脚本。这是正确的吗?接受这个答案。如果有人知道是否有一个与Selenium IDE密切合作的好驱动程序,那就太好了。目前,我将使用这里给出的建议。我对语法感到困惑:assertNotNull(“名称:”,“IP地址:”,工具提示);据我所知,有两个参数:assertNotNull(工具提示,“名称:”);如果我错了,请纠正我