java - 宁静剧本模式-上传文件
问题描述
我们正在尝试 Cucumber Serenity 框架进行端到端测试。我是相当新的技术,我厌倦了下面这个简单的代码。
actor.attemptsTo(Enter.theValue(path).into(Upload));
其中路径是我尝试使用浏览器的上传小部件上传的文件的位置。有没有人设法使用宁静屏幕播放模式执行这样的操作。
它真的让我们想到放弃宁静而只使用黄瓜硒框架,因为我可以使用 Upload.sendkeys(path); 轻松执行此操作;任何帮助深表感谢。提前致谢。
按要求:上市步骤:
public class ListingSteps
{
@Before
public void set_the_stage() {
OnStage.setTheStage(new OnlineCast());
}
@Given("^(.*) is able to click import products$") public void userIsAbleToClick(String actorName) throws Throwable
{
theActorCalled(actorName).wasAbleTo(Start.theApplication());
}
@When("^s?he imports a single item successfully$") public void heImportsASingleItemSuccessfully() throws Throwable
{
theActorInTheSpotlight().attemptsTo(Import.spreadsheet());
}
@Then("^(.*) are listed on ebay and amazon with all the right information$") public void itemsAreListedOnEbayAndAmazonWithAllTheRightInformation(String actorName, String SKU)
throws Throwable
{ //待办的
}
暂时忽略它,因为它正在进行中。
导入类:
public class Import implements Task
{
protected String path =
"C:\\somePathToFile\\populated_excel.xlsx";
public static Import spreadsheet()
{
return instrumented(Import.class);
}
@Override public <T extends Actor> void performAs(T actorName)
{
actorName.attemptsTo(Click.on(Products.ProductsScreen));
actorName.attemptsTo(Click.on(Products.Upload));
actorName.attemptsTo(Enter.theValue(path).into(Browse).thenHit(Keys.RETURN));//this is the line which is giving errors
actorName.attemptsTo(Click.on(Products.UploadButton));
}
}
目标浏览
public class Products
{
public static Target Browse = Target.the("browse file").locatedBy("//input[@type='file']");
}
解决方案
我设法让这个工作的方式是使用 FileToUpload 类:
import net.thucydides.core.pages.components.FileToUpload;
FileToUpload fileToUpload = new FileToUpload(driver, fileName);
fileToUpload.fromLocalMachine().to(webElement);
推荐阅读
- python - 如何循环 python 列表输入验证?
- python - 为什么我的 Python venv 目录是只读的?
- pytorch - 在训练期间更改 Dropout 值
- swift - 如何在 Swift / Xcode 12.3 中重用代码块进行闭包
- vb.net - Dsum函数查询访问
- vue.js - 绑定 Vue/Antd 单选按钮组无法应用样式
- celery - 芹菜花 - 它是黑暗主题的选择吗
- windows - windows ping中的颜色变化
- pytorch - 如何初始化混合稀疏张量中的列
- microsoft-graph-api - 创建团队,400 错误请求,不支持所需功能