我对TestNG有一个非常不愉快的问题.当我尝试使用我分配给它们的组启动我的一些测试时发生NullPointerException.
测试示例:
public class DemonstrationTest01 extends FundamentalTest {
private static final String LOGIN = "Fruzenshtein";
private static final String PASSWORD = "111111";
@Test(priority=1, groups="foo")
public void test01() throws InterruptedException {
basePage.logIn(LOGIN, PASSWORD)
.checkTextPresent("Welcome, "+LOGIN+"!")
.clickSiteLogo()
.checkTextPresent("Welcome, "+LOGIN+"!")
.logOut();
}
}
Run Code Online (Sandbox Code Playgroud)
第二次测试:
public class DemonstrationTest03 extends FundamentalTest {
@Test(priority=1, groups="foo")
public void test03() throws InterruptedException {
ProductPage productPage = basePage.navToCategory("Homewear")
.checkCategoryTitle("Mugs")
.navToProductPage(2)
.checkTextPresent("0 items")
.addToCart()
.checkTextPresent("1 items");
Assert.assertEquals(basePage.getShoppingCartTotal(), productPage.getProductPrice());
productPage.addToCart()
.checkTextPresent("2 items");
Assert.assertEquals(basePage.getShoppingCartTotal(), 2*productPage.getProductPrice());
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个FundamentalTest:
public class FundamentalTest { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用CssSelector在我的网页上找到一个元素.我正在使用Firefox驱动程序.
这是我使用定位器的方式(我检查过Selenium IDE能够找到我的元素
[FindsBy(How = How.CssSelector, Using = "label:contains('Version: 2.0.')")]
public IWebElement labelVersion;
Run Code Online (Sandbox Code Playgroud)
但是当在C#代码中使用它并在我的构造函数中使用PageFactory.InitElements初始化它时.
我遇到了这个错误...(错误本身很清楚,但我不知道如何解决它)
感谢任何输入.
OPC.Tests.SmokeTest(TestFixtureSetUp):设置:OpenQA.Selenium.InvalidSelectorException:给定的选择的CSS =标签:含有( '版本:2.0')是无效或不导致WebElement.出现以下错误:[异常..."无效或非法字符串指定"代码:"12" nsresult:"0x8053000c(NS_ERROR_DOM_SYNTAX_ERR)"的位置:"文件:/// .......... /anonymous439571104.webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js行:5811"]
我搜索了很多,但我没有得到答案......是否有可能将sikuli(使用dll或其他东西,某些代码)包含(附加或其他东西)到c#中编写的selenium webdriver test中2010年工作室
我有一个按钮,其代码如下:
<input type="button" onclick="someFunction();" value="doSomething">
Run Code Online (Sandbox Code Playgroud)
我想在Selenium2中点击这个按钮.我设法获取元素,但click()函数在Chrome中不起作用.
我尝试直接在JavaScript上执行此操作,但它仍无法在Chrome中运行.
如果您直接单击该按钮,它就可以工作,它也适用于Firefox.
任何人都知道如何解决这个问题?
编辑:我忘记了我的例子中的括号.它们存在于"真实"代码中.
Edit2:用于模拟点击的Selenium 2代码是:
driver.findElement(By.tagName("input")).click();
Run Code Online (Sandbox Code Playgroud)
在有人问之前,页面中没有其他tagName"输入".
我是测试的新手.
我在Linux上工作.我正在阅读有关无头模式的测试,并遇到了两件事.一个是X虚拟帧缓冲区,它在内存中进行图形操作.因此,不显示任何输出.我在此链接http://www.seleniumtests.com/2012/04/headless-tests-with-firefox-webdriver.html中找到的实施细节.
我遇到的另一个是HtmlUnitDriver.这也不会在运行测试时打开任何浏览器.我使用HtmlUnitDriver编写了一个基本的示例代码,断言似乎工作正常.
我知道HtmlUnitDriver与javascript的效果不太好.但除此之外,选择其中一个有什么重大差异吗?
我将测试一个确实有一些javascript的web应用程序.
我是这个领域的新手.所以,任何答案,建议等将不胜感激.先感谢您
我在选择框架中的项目时遇到问题.我到了某一点然后失败了.我尝试了很多选项,但无济于事,下面是代码.我进入第一帧然后:
selenium.open("http://localhost/Clockwise/Main.htm");
// grabs back to driver
WebDriver driver = ((WebDriverBackedSelenium) selenium).getWrappedDriver();
driver.switchTo().frame("MainFrame");
//selenium.selectFrame("MainFrame");
driver.findElement(By.xpath("//li[contains(.,'Reports')]")).click();
//selenium.click("//li[contains(.,'Reports')]")
driver.findElement(By.xpath("//li[contains(.,'Reports')]")).click();
driver.findElement(By.xpath("//li[contains(.,'Reports')]"));
Thread.sleep(3000);
//FAILS HERE
driver.findElement(By.id("SELECTALL2")).click();
Run Code Online (Sandbox Code Playgroud) 在我的Ubuntu工作站上本地运行使用Firefox的Selenium(Webdriver)测试不再有效.
完全相同的设置之前工作,但我认为Firefox在某些时候升级(现在从Ubuntu包中升级到16.0.2 16.0.2+build1-0ubuntu0.11.04.1),之后它停止工作.在正常使用中,Firefox工作正常.
使用Webdriver,当我运行一个测试用例(通过我的IDE)时,会打开一个空的Firefox窗口,但测试无法启动.45秒后,它会超时,并显示以下错误消息:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
*** LOG addons.xpi: startup
*** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: /tmp/anonymous5012217980260937474webdriver-profile/extensions/webdriver-staging
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi-utils: Opening database
*** LOG addons.xpi: Add-on {2204c510-88f3-11db-b606-0800200c9a66} modified in app-profile
*** LOG addons.xpi: Add-on yslow@yahoo-inc.com modified in app-profile
*** LOG addons.xpi: Add-on {02450954-cdd9-410f-b1da-db804e18c671} modified in app-profile
*** LOG addons.xpi: Add-on {c45c406e-ab73-11d8-be73-000a95be3b12} …Run Code Online (Sandbox Code Playgroud) 例如,我想从多选选项列表字段中选择特定optgroup下的选项
<select id="xyz">
<optgroup label="Group1">
<option value="1">pick1</option>
<option value="2">pick2</option>
</optgroup>
<optgroup label="Group2">
<option value="3">pick3</option>
<option value="4">pick4</option>
</optgroup>
</select>
Run Code Online (Sandbox Code Playgroud)
如果选项列表字段如上所述,我可以使用
new Select(driver.findElement(By.id("xyz"))).selectByVisibleText("pick1");
new Select(driver.findElement(By.id("xyz"))).selectByVisibleText("pick2");
Run Code Online (Sandbox Code Playgroud)
从上面选择optgroup -Group1下的所有选项.
在这里,我知道Group1中存在哪些选项,因此我可以选择如上所述.
但我的要求是动态的,我需要选择optgroup-Group1下的所有选项.
如果我想要动态选择包括组1和组2的所有选项
然后我就可以用了
new Select(driver.findElement(By.id("xyz"))).getOptions();
Run Code Online (Sandbox Code Playgroud)
将所有选项作为List获取,我可以将其存储为数组,然后我可以使用数组逐个选择所有选项
但是,我怎样才能在一个特定的optgroup下获得所有选项,比如Group1或Group2?

如何使用Java在webdriver中使用xpath获取webtable中的确切行数.使用下面的xpath我也可以使用标头计数.我不希望计数包含标题行并获得网表的计数.
//table[@id='ctl00_MasterPlaceHolder_GrdHistory']/tbody/tr
Run Code Online (Sandbox Code Playgroud)
HTML代码:
<table id="ctl00_MasterPlaceHolder_GrdHistory" cellspacing="2" cellpadding="0" border="0" style="color:#333333;width:100%;">
<tbody>
<tr style="color:Black;background-color:#DFC065;font-weight:bold;">
<tr style="background-color: rgb(251, 247, 234); text-decoration: none;" onclick="javascript:__doPostBack('ctl00$MasterPlaceHolder$GrdHistory','Select$0')" onmouseout="javascript:setMouseOutColor(this);" onmouseover="javascript:setMouseOverColor(this);">
<tr style="background-color: rgb(251, 247, 234); text-decoration: none;" onclick="javascript:__doPostBack('ctl00$MasterPlaceHolder$GrdHistory','Select$1')" onmouseout="javascript:setMouseOutColor(this);" onmouseover="javascript:setMouseOverColor(this);">
<tr style="background-color: rgb(251, 247, 234); text-decoration: none;" onclick="javascript:__doPostBack('ctl00$MasterPlaceHolder$GrdHistory','Select$2')" onmouseout="javascript:setMouseOutColor(this);" onmouseover="javascript:setMouseOverColor(this);">
<tr style="background-color: rgb(251, 247, 234); text-decoration: none;" onclick="javascript:__doPostBack('ctl00$MasterPlaceHolder$GrdHistory','Select$3')" onmouseout="javascript:setMouseOutColor(this);" onmouseover="javascript:setMouseOverColor(this);">
<tr style="background-color: rgb(251, 247, 234); text-decoration: none;" onclick="javascript:__doPostBack('ctl00$MasterPlaceHolder$GrdHistory','Select$4')" onmouseout="javascript:setMouseOutColor(this);" onmouseover="javascript:setMouseOverColor(this);">
<tr style="background-color: rgb(251, 247, 234); text-decoration: none;" onclick="javascript:__doPostBack('ctl00$MasterPlaceHolder$GrdHistory','Select$5')" onmouseout="javascript:setMouseOutColor(this);" onmouseover="javascript:setMouseOverColor(this);">
<tr style="background-color: rgb(251, 247, 234); text-decoration: none;" onclick="javascript:__doPostBack('ctl00$MasterPlaceHolder$GrdHistory','Select$6')" …Run Code Online (Sandbox Code Playgroud)