使用junit和TAURUS运行多重播放测试

时间:2016-08-30 06:48:34

标签: java selenium junit jmeter performance-testing

我希望有人可以帮助我,这篇文章可以帮助他人。我有一个项目,我需要测试页面加载。性能工具是TAURUS。该项目带有登录页面(令牌)。

问题是:

当我有登录表单时,如何为特定页面执行页面加载测试。以下是我的代码示例。

或者当我有一个很大的依赖测试时,在测试中我有10个不同的页面,有些页面包含附件文件,怎么可以告诉测试我想测量不同页面的页面加载时间?

code:
TEST.yml
---
execution:
- executor: selenium
  scenario: simple
  concurrency: 1

scenarios:
 simple:
  requests:
  - http://10.32.1.114:9080
  method: GET
  script: /home/xxxxx/Desktop/XXXXX/src/test/java/Testing_2.java
  additional-classpath: ~/.bzt/jmeter-taurus/lib/selenium-java-2.53.1.jar

modules:
 selenium:
  selenium-tools:
   junit:
    path: ~/.bzt/jmeter-taurus/lib/junit-4.12.jar
    compile-target-java: 1.7
    hamcrest-core: ~/.bzt/jmeter-taurus/lib/hamcrest-core-1.3.jar

cli-aliases:
  report:
   reporting:
   - blazemeter


Testing_2.java
*****************************************************************''

WebDriver driver = new FirefoxDriver();

@Before
public void setup() {
    driver.navigate().to("http://10.111.111.114:9080");
}

@Test
public void login() throws InterruptedException {
    WebDriverWait wait = new WebDriverWait(driver, 60);

    driver.findElement(By.cssSelector("a[ng-click='vm.closeTokenForm()']")).click();

    driver.findElement(By.cssSelector("div[class='text-center']")).getText();

    driver.findElement(By.linkText(user)).click();

    Thread.sleep(2000);

    WebElement table = driver.findElement(By.cssSelector("table[class='large-12 columns ng-scope']"));
    java.util.List<WebElement> tr_collection = table.findElements(By.cssSelector("tbody > tr"));
    wait.until(ExpectedConditions.visibilityOfAllElements(tr_collection)).size();
}

@After
public void close() {
    driver.close();
}

链接到blazemeter论坛:LINK

1 个答案:

答案 0 :(得分:0)

如果要测试页面加载,可以使用场景的请求选项编写简单脚本。您可以编写简单的场景页面加载并运行它。

示例:

execution:
- executor: selenium
  scenario: simple
  concurrency: 1

scenarios:
 request-example:
  default-address://10.32.1.114:9080
  browser: Firefox
  timeout: 60
  think-time: 2s
  requests:
  - url: /
    actions:
    - clickByCSS("a[ng-click='vm.closeTokenForm()']")
    - waitByCSS("div[class='text-center']"):visible
    - clickByLinkText(user)
    - waitByCSS("table[class='large-12 columns ng-scope']"):visible

如果您想测量不同页面的页面加载时间(page1.html和page2.html),那么您可以写:

scenarios:
 request-example:
  default-address://10.32.1.114:9080
  browser: Firefox
  timeout: 60
  think-time: 2s
  requests:
  - url: /page1.html
    actions:
    - clickByCSS("a[ng-click='vm.closeTokenForm()']")
    - waitByCSS("div[class='text-center']"):visible
    - clickByLinkText(user)
    - waitByCSS("table[class='large-12 columns ng-scope']"):visible
  - url: /page2.html
    actions:
    - clickByCSS("a[ng-click='vm.closeTokenForm()']")
    - waitByCSS("div[class='text-center']"):visible
    - clickByLinkText(user)
    - waitByCSS("table[class='large-12 columns ng-scope']"):visible

我们在Taurus仪表板上看到的结果。每个页面分别显示平均时间。