当前位置: 首页 > 知识库问答 >
问题:

响应消息:org.apache.jorphan.util.JMeterException:调用bsh方法时出错:eval源文件:的内联计算:

戚承业
2023-03-14

响应消息:org.apache.jorphan.util.JMeterException:调用bsh方法时出错:eval源文件:内联计算:``Import java.io.file;导入java.io.FileReader;导入java.io.FileWriter;重要的。..''

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

import au.com.bytecode.opencsv.CSVReader;
import au.com.bytecode.opencsESRv.CSVWriter;

Boolean result=true;
public WebDriver driver;
try
{
     System.setProperty("webdriver.chrome.driver","Projects\\chromedriver.exe");
     driver=new ChromeDriver();

     driver.manage().window().maximize();
    driver.get("https://something.com/registration/");
     WebDriverWait wait = new WebDriverWait(driver, 20000);

     String uname= bsh.args[0];
     String pass= bsh.args[1];

      // Logged In 
     driver.findElement(By.xpath("//*[contains(@id,'menu-item')]//*[text()='Log In']")).click();
     driver.findElement(By.id("username")).sendKeys(new String[] {uname});
     driver.findElement(By.id("password")).sendKeys(new String[] {pass});
     driver.findElement(By.xpath("//*[@id='woocommerce-login-nonce']/following-sibling::*[@name='login']")).click();

     // Logged Out
     driver.findElement(By.xpath("//*[@id='masthead']//*[text()='Sign out']")).click();
}
catch (Exception ex) 
{
    ex.printStackTrace();
    IsSuccess = false;
    ResponseCode = "500";
    ResponseMessage = ex.getMessage();
    log.error(ex.getMessage());
    System.err.println(ex.getMessage());
} 
catch (Throwable thex) 
{
    System.err.println(thex.getMessage());
}
finally 
{
    driver.quit();
}
IsSuccess=result;
return result;

代码是在JMeter中的Beanshell采样器中编写的。

共有1个答案

伍溪叠
2023-03-14

>

  • 仅替换一个Selenium库是不够的,您还需要升级其他依赖项

    • 安装干净的JMeter
    • 下载http://selenium-release.storage.googleapis.com/3.1/selenium-java-3.1.0.zip文件并将所有.jar解压到JMeter类路径(JMeter的“lib”文件夹也可以)
    • 重新启动JMeter以启动.jars

    为了看到“正常的”stacktrace,请修改您的catch块,使其看起来像:

    catch (Exception ex) {
        log.error("Something went wrong", ex);
    }
    

  •  类似资料: