gpt4 book ai didi

java - JMeter 中的网站 URL 正在重定向而不是加载测试 URL

转载 作者:行者123 更新时间:2023-11-29 04:41:47 27 4
gpt4 key购买 nike

我正在学习 JMeter。在我的任务中,我需要加载一个测试 URL,但测试 URL 实际上重定向到另一个 URL。当我尝试检查 HTML 格式的“查看结果树”时,我没有看到任何已加载的内容,但“采样器结果”为 200 OK。

我得到以下响应数据

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
</head>
<script type="text/javascript">

var externalURL = "cat04-partner-external.napgsys.com".toLowerCase();
internalUrl = "cat04-partner.napgsys.com".toLowerCase();


$(document).ready(function () {
if(window.location.href.indexOf(externalURL) > -1) {
window.location.href = window.location.href +"sso/login/#/login2";
}
else{
window.location.href = window.location.href +"sso/login/#/login";
}
});
</script>
<!--<META http-equiv="refresh" content="0;URL=/sso">-->
</html>

我尝试了“自动重定向”和“跟随重定向”,但没有任何帮助。如何确保它重定向到正确的 URL,我可以在 HTML 中验证是否加载了正确的测试 URL。

最佳答案

您尝试的选项(“自动重定向”和“跟随重定向”)适用于在服务器端重定向的应用程序,但您的应用程序使用 JavaScript 代码在客户端重定向,而 JMeter 的 HTTP 采样器在 HTTP 级别运行,并且不运行 any JavaScript code :

Does JMeter process dynamic pages (e.g. Javascript and applets)?

No. JMeter does not process Javascript or applets embedded in HTML pages.

JMeter can download the relevant resources (some embedded resources are downloaded automatically if the correct options are set), but it does not process the HTML and execute any Javascript functions.

所以你有 3 个选择:

  • 选项 1:假装发生重定向:

    • 验证返回的响应是否具有重定向代码(例如使用 RegEx 后处理器)
    • 向重定向链接发出下一个请求,就好像重定向发生了一样。

    这种方法的优点是易于实现,完全足以进行性能测试,并允许您控制有多少用户/迭代转到每个重定向链接(例如,您可以添加“随机” Controller 来获取用户随机转到 loginlogin2,或者吞吐量 Controller 将一定比例的用户重定向到 login,其余用户重定向到 login2)。

    有些人可能认为的缺点是,如果您还想测试您的 JS 代码,您不会这样做。但 JMeter 一般不用于客户端测试,所以这并不是这种方法的缺点,而是使用 JMeter 进行功能测试的缺点。

    这是此类计划的示例: enter image description here

    在第一次请求后,我们检查响应页面是否包含登录重定向(这是检查它的一种方法,当然还有许多其他方法)。如果是,则认为请求成功。

    然后 Random Controller 确保每次我们选择 loginlogin2。随机的。当然,您可以根据需要使用任何其他 Controller 来代替 Random Controller 。

  • 选项 2:使用 Selenium WebDriver 采样器

    基本上您将创建 selenium tests, and run them in JMeter :

    Web Driver Sampler automates the execution and collection of Performance metrics on the Browser (client-side). A large part of performance testing, up to this point, has been on the server side of things. However, with the advancement of technology, HTML5, JS and CSS improvements, more and more logic and behaviour have been pushed down to the client. This adds to the overall perceived performance of website/webapp, but this metric is not available in JMeter. Things that add to the overall browser execution time may include:

    • Client-side Javascript execution - eg. AJAX, JS templates
    • CSS transforms - eg. 3D matrix transforms, animations
    • 3rd party plugins - eg. Facebook like, Double click ads, site analytics, etc

    上面概述了优势。缺点是 Selenium 采样器的可扩展性不如 HTTP 采样器,并且不能像 HTTP 采样器那样对服务器施加压力。与任何基于 UI 的测试一样,它们也需要更多维护。

  • 选项 3:结合两种方法

    让大多数线程运行 HTTP 采样器,并且很少测量最终用户使用 Selenium 采样器的体验。这提供了最好的覆盖范围,但当然需要更大的投资来创建和维护它们。

关于java - JMeter 中的网站 URL 正在重定向而不是加载测试 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38928718/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com