Jmeter:junit请求没有给出结果

时间:2016-09-14 13:36:20

标签: junit jmeter performance-testing

我在jmeter中使用junit请求来获取脚本的性能结果。当我运行脚本时,它没有给出任何错误,但它没有给出结果。 我正在添加junit请求的jav源代码,并且还将提供输出屏幕。 请检查是什么问题因为我已将所需的插件和jar添加到同一个

package com.seleniummaster.jmeterjunit;
import static org.junit.Assert.*;

import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.MarionetteDriver;


public class LoginTest {
  private WebDriver driver;
    private String baseUrl;
    private boolean acceptNextAlert = true;
    private StringBuffer verificationErrors = new StringBuffer();  
  @Before
  public void setUp() throws Exception {
    //use Firefox driver
//    driver = new FirefoxDriver();
    //use demo.mahara.org site for testing
	  System.setProperty("webdriver.gecko.driver",
				"D:\\Seleniumdriver\\geckodriver.exe");
		driver = new MarionetteDriver();
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      baseUrl = "http://demo.mahara.org";
      //timeout if site page does not load in 30 seconds
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }
  @After
  public void tearDown() throws Exception {
    //quit the test
    driver.quit();
      String verificationErrorString = verificationErrors.toString();
      if (!"".equals(verificationErrorString)) {
        fail(verificationErrorString);
      }
  }
  @Test
  public void test() throws InterruptedException {
    //navigate to base url
    driver.get(baseUrl + "/");
    //clear username filed
      driver.findElement(By.id("login_login_username")).clear();
      //enter user name
      driver.findElement(By.id("login_login_username")).sendKeys("student1");
      //clear password
      driver.findElement(By.id("login_login_password")).clear();
      //enter password
      driver.findElement(By.id("login_login_password")).sendKeys("Testing1");
      //click on submit button
      driver.findElement(By.id("login_submit")).click();
      //assert the Dashboard link text
      for (int second = 0;; second++) {
        if (second >= 60) fail("timeout");
        try { if (isElementPresent(By.linkText("Dashboard"))) break; } catch (Exception e) {}
        Thread.sleep(1000);
      }

      assertEquals("Dashboard", driver.findElement(By.linkText("Dashboard")).getText());
    }
  private boolean isElementPresent(By by) {
      try {
        driver.findElement(by);
        return true;
      } catch (NoSuchElementException e) {
        return false;
      }
    }

    private boolean isAlertPresent() {
      try {
        driver.switchTo().alert();
        return true;
      } catch (NoAlertPresentException e) {
        return false;
      }
    }

    private String closeAlertAndGetItsText() {
      try {
        Alert alert = driver.switchTo().alert();
        String alertText = alert.getText();
        if (acceptNextAlert) {
          alert.accept();
        } else {
          alert.dismiss();
        }
        return alertText;
      } finally {
        acceptNextAlert = true;
      }
    }
  }

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:0)

我最近遇到了同样的问题。我在Jmeter UI的Junit Request页面中检查了两个方框。

  • 追加断言错误
  • 追加运行时例外

此后,当我再次执行测试时,我在"查看结果树"中找到了错误。响应消息字段下的监听器。

希望这有帮助。

答案 1 :(得分:0)

请尝试将所有私有变量设为公开。 JMeter 可能无法访问这些。

另外,参考 JMeter 上的控制台,它应该会显示错误/异常。

enter image description here