JMeter jp@gc-WebDriver Sampler — 运行 来自 CSV 文件的网页

JMeter jp@gc-WebDriver Sampler — Run the Webpage from CSV File

我尝试使用 CSV 数据集配置从 CSV 文件创建登录。但不确定为什么它不选择变量并且在登录页面上输入了带有“用户名”和“密码”的文字。能请教一下吗?

import org.openqa.selenium.*; import org.openqa.selenium.support.ui.*; import org.openqa.selenium.support.ui.Select; WDS.sampleResult.sampleStart(); WDS.browser.get("https://uat-testing.com/" ); sleep(5000); var Username = WDS.vars.get("username" ); var Password = WDS.vars.get("password" ); WDS.log.info('Username' + Username ); WDS.log.info('Password' + Password ); WDS.browser.findElement(org.openqa.selenium.By.xpath("//input[@type='text']" )).sendKeys("Username" ); WDS.browser.findElement(org.openqa.selenium.By.xpath("//input[@type='password']" )).clear(); WDS.browser.findElement(org.openqa.selenium.By.xpath("//input[@type='password']" )).sendKeys("Password" ); WDS.browser.findElement(org.openqa.selenium.By.xpath("//button/span" )).click(); sleep(10000); WDS.sampleResult.sampleEnd();

您需要从这些行中删除引号:

sendKeys("Username" )

sendKeys("Password" ); 

所以它们看起来像:

sendKeys(Username)

sendKeys("Password" ); 

也使用 sleep function is a performance anti-pattern, I would rather recommend using Explicit Wait so your test would proceed as soon as the condition will be met rather than forcing the flow to sleep for 10 seconds, see 5 Ways to Test AJAX Calls in Selenium WebDriver 获取更多信息。