Tag: 自动测试

获得价值无法理解

我正在编写一个selenium代码来执行以下操作。 在文本框中输入值。 选择下拉值。 选择一个单选按钮。 按下go按钮。 当我这样做时,我将得到一个结果列表,我想得到第一个结果块的标题。 以下是我的代码。 import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; public class Test1 { public static void main(String[] args) throws InterruptedException { WebDriver driver; System.setProperty(“webdriver.gecko.driver”, “C:\\Users\\home\\Downloads\\geckodriver.exe”); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); driver = new FirefoxDriver(capabilities); driver.get(“https://www2.chubb.com/us-en/find-agent-page.aspx”); driver.findElement(By.xpath(“.//*[@id=’tbAddress’]”)).sendKeys(“60089”); driver.findElement(By.xpath(“.//*[@id=’cphHeroContent_drpDistanceMiles’]”)).sendKeys(“2”); driver.findElement(By.xpath(“.//*[@id=’cphHeroContent_rdType_0′]”)).click(); driver.findElement(By.xpath(“.//*[@id=’cphHeroContent_btnSearch’]”)).click(); String title = driver.getTitle().toString(); System.out.println(title); Thread.sleep(10000L); […]

如何在Intellij中运行单个黄瓜场景?

我有一个简单的问题 – 我想运行一个Cucumber场景,但我似乎无法找到任何选项/配置。 我有5-6个场景,我可以设置配置来运行所有测试,但是当我纠正一个场景时需要花费太多时间……

TestNG.xml套件包含所有包的所有文件

即将用Maven + TestNG + Selenium实现测试框架。 如何声明一个告诉TestNG运行所有测试的suite.xml? 我已经尝试了所有这些无济于事: 我需要指定具有不同参数的不同套件配置,但所有测试都运行。 我可以明确地挖掘的每个例子都列出了每个对我来说都不太理智的类或包。

如何正确设置Java / Selenium配置以运行自动化测试?

我正在尝试设置selenium webdriver与Browserstack一起使用Java进行自动化测试。 我安装了Selenium for java,我从browserstack的网站https://www.browserstack.com/automate/java#configure-capabilities复制并粘贴了代码,以建立一个示例自动化测试。 我从我的终端运行了javac -classpath selenium-server-standalone-2.48.2.jar JavaSample.java (JavaSample.java是带有selenium配置代码并带有示例测试的文件),我收到以下错误: JavaSample.java:1: error: package org.openqa.selenium does not exist import org.openqa.selenium.By; ^ JavaSample.java:2: error: package org.openqa.selenium does not exist import org.openqa.selenium.Platform; ^ JavaSample.java:3: error: package org.openqa.selenium does not exist import org.openqa.selenium.WebDriver; ^ JavaSample.java:4: error: package org.openqa.selenium does not exist import org.openqa.selenium.WebElement; ^ JavaSample.java:5: error: package org.openqa.selenium.remote does […]

在maven测试期间找不到persistence.xml

我正在尝试在用于集成测试的maven构建期间将测试数据加载到测试数据库中。 persistence.xml正在被正确地复制到target/test-classes/META-INF/ ,但是在运行测试时我得到了这个exception。 javax.persistence.PersistenceException:没有名为aimDatabase的EntityManager的持久性提供程序 看起来它没有找到或加载persistence.xml。

如何以编程方式使用TestNG运行Selenium Java测试?

我使用Selenium RC和Java一起使用TestNG作为测试框架。 我正在使用Eclipse作为IDE。 我想非常轻松地从我自己的程序中调用TestNG。 我怎样才能做到这一点?

在Spring Boot IntegrationTest上禁用@Schedule

如何在Spring Boot IntegrationTest上禁用计划自动启动? 谢谢。

WebDriver无法可靠地单击链接或按钮

我一直在拼命想让WebDriver可靠地点击按钮或链接,但它只是不想合作。 我尝试了不同的方法,从设置隐式超时,到下面的代码,假设点击并等待元素出现。 下面的代码片段是在互联网上找到的,它是我最接近可靠的按钮或链接点击。 除了它在调试模式下的工作方式与我在夜间回归测试中执行时的工作方式不同。 有没有人知道在浏览器中点击按钮或链接的另一种方法? 或者我应该使用Selenium 1而不是WebDriver,因为它太新了而无法可靠地使用。 public void waitAndClick(WebDriver driver, By by) { WebDriverWait wait = new WebDriverWait(driver, 10000, 2000); Function waitForElement = new waitForElement(by); wait.until(waitForElement); Actions builder = new Actions(driver); builder.click(driver.findElement(by)) .perform(); } private class waitForElement implements Function { private final By by; private String text = null; public waitForElement(By by) { this.by […]

在Selenium中每个元素使用多个定位符的优点/缺点?

我正在测试一个仍在开发中的网站。 DOM中元素的id,类,文本或位置通常会发生变化。 然后我一直在使用的定位器将无法再找到该元素。 但function仍然正常运行。 当没有实际的回归时,我不希望几个测试失败。 因此,我没有为每个元素设置一个定位器,而是有一组定位器。 public static final ArrayList LOGIN_ANCHOR_LOCATORS = new ArrayList(); static { LOGIN_ANCHOR_LOCATORS.add(By.id(“loginLink”)); LOGIN_ANCHOR_LOCATORS.add(By.linkText(“Login”)); LOGIN_ANCHOR_LOCATORS.add(By.xpath(“/html/body/div[5]/a”)); } 我找到元素的方法如下所示: public WebElement locateElement(ArrayList locators){ // create an element to return WebElement element = null; // until the desired element is found… while (element == null){ // loop through the locators for (By locator : […]

如果其他测试失败,我可以跳过Junit测试吗?

我正在使用Junit与Seleniun WebDriver一起运行测试。 我正在尝试将我的测试分解为function区域,以便更好地报告错误。 我已经创建了测试页面加载/移动文档到其他工作流程的测试。 如果页面加载测试失败,或者工作流程移动失败,我想跳过后续页面/工作流程测试。 如果测试A失败,我怎么能跳过类中的其余测试或在B类中运行测试? 注意:我意识到我所问的是“ UNIT TESTS的不良实践*。但是,我实际上正在使用Junit进行集成和/或自动化测试。(根据您的定义。)我已经找到了@Suite.SuiteClasses和@FixMethodOrder订购我的测试类和测试方法。我正在尝试命令它们在逻辑上运行,测试页面加载,首先,然后将页面的每个function作为单独的测试。一些function,移动信息到其他页面,意味着其他课程。我的课程中有一个可能需要花费半小时才能完成。如果请求前测试失败,我想简短地进行“依赖”测试,以获得我的结果/报告越早越好。