Tag: selenium

使用Selenium测试Angularjs应用程序

我正在测试角度js应用程序 链接Angular js App 当我点击Web应用程序上的UI工具包链接时,我收到以下错误 – at demoaj.Ajapp.main(Ajapp.java:16)引起:org.openqa.selenium.NoSuchElementException:无法找到元素:{“method”:“xpath”,“selector”:“html / body / div 1 / div 1 / aside / div / div / ul / li [2] / a“}命令持续时间或超时:51毫秒有关此错误的文档,请访问: http : //seleniumhq.org/exceptions/no_such_element.html 我是新手,我对这个AngularJS进行了一些研究 java代码 package demoaj; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class Ajapp { public static void main(String[] args) […]

每次在selenium中GWT id元素都在变化

selenium.click(“gwt-uid-204”); // this is recorded from Selenium IDE 我点击了我的(gwt)java应用程序中的复选框。 gwt-uid正在改变,所以如果id改变了,那么我的应用程序中找不到我的元素。 正则表达式对我不起作用,我不确定我做错了什么。 谢谢你的帮助 selenium.click(“gwt-uid-[0-9]); 我使用的是selenium 1.0.3,Java

如何将标头或参数添加到使用Selenium Webdriver处理的HTTP请求中?

我正在使用Selenium Webdriver进行Web应用程序的unit testing。 它在JUnit测试中使用尽管广泛阅读可用文档并搜索,我找不到一种方法: 将标头添加到驱动程序传递的HTTP请求中。 向这样的请求添加参数,就好像驱动程序在提交表单后获得目标URL一样。 可以创建一个具有适当forms的测试网页,并让Webdriver反弹以自动获取这些参数,但这是一个非常难看的黑客。 我想避免它,特别是为了测试primefaces性。 (这是unit testing。) 在Wendriver之前,我使用Spring的MockHttpServletRequest和MockHttpServletResponse来做这个,它就像一个魅力,但我想利用Webdriver的强大function来断言目标页面的内容。

Selenium Java(maven项目):TestNG结果与ReportNG不同

我尝试运行testng.xml ,结果如下: =============================================== 默认测试 测试运行:14,失败:6,跳过:0 默认套件 总测试运行:14,失败:6,跳过:0 =============================================== 现在,我禁用了deafult TestNG监听器并在testng.xml添加了ReportNG testng.xml 。 testng.xml 。 看起来像这样: 按照这些步骤,我在maven的pom.xml添加了velocity , guice和reportng依赖项。 执行testsuite testng.xml ,创建了以下文件夹(标记为红色框)。 打开index.html ,结果如下: 正如预期的那样,ReportNG应该创建一个输出文件夹,在我的场景中没有注意到。 其次,结果不同。 另外,报告index.html看起来不应该是它应该是多少。 有人能说出什么问题吗? 一些细节供您参考: 操作系统:Windows 7 Guice.jar版本: guice-4.1.0 ReportNG版本: reportng-1.1.4 速度版本: velocity-dep-1.4 TestNG版本: testng-6.11 Selenium版本: selenium-java-3.5.3 Eclipse: eclipse oxygen 我的测试用例如下: public class MwSites { WebDriver driver; @BeforeTest public void setup () […]

如何使用selenium和junit测试多个浏览器(版本)

我刚刚发现了selenium – 一个很棒的工具! 我计划运行/使用selenium-ide生成的junit4代码。 但我需要它与许多浏览器/网络驱动程序运行。 这个用例是否有junit / java-pattern? 我的第一个想法是使用@RunWith(Parameterized.class)并提供WebDrivers列表(该类的参数 – 可能作为列出浏览器和版本的外部文件提供?!)。 这是一个好主意吗? 是否有可能提供一个中心@Parameters -method供我所有的Selenium测试使用? 有什么替代品? 可能有可能更改Selenium导出的“格式”以最小化手动更改?

如何使用selenium设置“value”来输入web元素?

我的代码中的元素看起来像这样: 我想设置它的值,所以我用它的xpath创建了一个web元素: val test = driver.findElements(By.xpath(“””//*[@id=”invoice_supplier_id”]”””)) 但现在我没有看到设置值的选项……

如何使用selenium复制和粘贴值?

我目前需要复制订单ID,然后将其粘贴到搜索字段中。 到目前为止我尝试过: driver.findElement (By.xpath(“/html/body/main/div/div/div[2]/div/div/div[2]/div/table/tbody/tr[2]/td[2]”)).sendKeys(Keys.chord(Keys.CONTROL, “c”)); , 然而,这无法复制任何东西,粘贴时粘贴我之前自己复制的内容。 点击这里

action.sendKeys(body,Keys.CONTROL +“j”)不要打开下载页面

我正在使用Java和Selenium为Chrome编写测试。 我需要在某一点打开下载页面,所以我使用了: action.sendKeys(Keys.CONTROL + “j”).build().perform(); 但它不会打开页面。 然后我在它之前添加了这一行,因为我虽然它可能有效,但它没有: WebElement body = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(“//body[@id=’body’]”))); action.sendKeys(body, Keys.CONTROL + “j”).build().perform(); 奇怪的是 action.sendKeys(Keys.CONTROL + “a”).build().perform(); 作品!! 注意:我不想使用Robot类,因为如果焦点不在测试目标浏览器上,它将在其他浏览器上打开页面。

使用testng中的DataProvider从文件中读取数据

假设我有一个包含以下数据的文本文件 username=testuser password=testpassword email=test@test.com address=testaddress zipcode=12345 或者我有一个包含以下数据的XML testuser testpassword test@test.com testaddress 我有一个测试如下 public class DPTest { @Test(dataprovider=”testdp”) public void userTest_01(String username, String Password) { //Test goes here } } 另一堂课 public class DPTest2 { @Test(dataprovider=”testdp”) public void userTest_02(String email, String address, String password) { //Test goes here } } 我的dataprovider可以读取上面提到的文本文件或XML中的值并将其提供给测试方法吗? 根据我的理解,数据提供程序将读取文本文件中的所有行并将其提供给测试方法,并抛出错误说“数据提供程序正在尝试提供6个参数,但测试只能接受2个参数”? 请帮帮我。

当JUnit类有多个导入时,如何从Windows CMD窗口运行JUnit测试?

这是我的JUnit测试类:package com.bynarystudio.tests.storefront; import java.util.List; import org.junit.Assert; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import com.bynarystudio.tests.BaseWebTest; public class SmokeTests extends BaseWebTest { @Test public void StoreFrontMegaNavTest(){ webDriver.get(default_homepage); String source = webDriver.getPageSource(); Assert.assertTrue(source.contains(“some text”)); } } 如何从命令行运行此测试? 当我尝试使用时从其目录中运行它 java -cp junit.textui.TestRunner SmokeTests.java 我收到以下错误 Could not find the main class: SmokeTests.java. Program will exit. 我认为这与我的类路径设置不正确这一事实有关。 但我不知道因为我是Java的新手。 来自.NET,C#和Visual Studio,整个类路径事情毫无意义。 即使我已将所有文件正确添加到Eclipse中的项目中(我知道因为Eclipse内部的测试运行良好),它绝对不会从命令行运行或编译。