简体   繁体   English

如何使用 Selenium webdriver 在移动模式下打开 Chrome 浏览器以在 JMeter 中进行负载测试?

[英]How can I open the Chrome browser in mobile mode using the Selenium webdriver for load testing in JMeter?

I want to open a URL in the Chrome browser, but in mobile mode during my load test in JMeter.我想在 Chrome 浏览器中打开 URL,但在 JMeter 负载测试期间以移动模式打开。 I am using Selenium scripts.我正在使用 Selenium 脚本。 Below is my Selenium script下面是我的 Selenium 脚本

var pkg = JavaImporter(org.openqa.selenium,org.openqa.selenium.support.ui) // Import Java Selenium packages
var Thr = JavaImporter(java.lang.Thread) // Import Thread sleep packages
var wait = new pkg.WebDriverWait(WDS.browser,30) // Import WebDriverWait Package

WDS.sampleResult.sampleStart()

WDS.browser.get('https://xyz=${__urlencode(${token})}');

WDS.sampleResult.sampleEnd()

Below is the Java class I have created in BeanShell Preprocessor in Jmeter to use Chromeoptions to open Chrome in mobile mode, but I don't know how I can call it in webdriver above and I am doing it correctly or not:以下是我在webdriverBeanShell预处理器中创建的Jmeter以使用 Chromeoptions 以在移动模式下打开 Chrome 或无法正确调用它:

public class page {

    public static void main (String args[]) {
        String device = "Samsung Galaxy S4";
        //options.ChromeOptions options = new ChromeOptions();
        ChromeOptions options = new ChromeOptions();
        options.EnableMobileEmulation(device);
        IWebDriver driver = new ChromeDriver(options);
    }
}
  1. Since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language 从 JMeter 3.1 开始,您应该使用 JSR223 测试元素Groovy 语言
  2. There is no EnableMobileEmulation function in ChromeOptions , you should be using setExperimentalOption instead ChromeOptions 中没有EnableMobileEmulation function ,您应该改用setExperimentalOption

Example code for the JSR223 Sampler : JSR223 采样器的示例代码:

import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver.exe");

Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", "Galaxy S5");

ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("mobileEmulation", mobileEmulation);
ChromeDriver driver = new ChromeDriver(options)
driver.get("http://example.com");
log.info(driver.getTitle());
driver.quit();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM