DEV: Add support for image fields in FormKit PageObject (#29589)

This commit adds an API `upload_image` to `FormKitField` page object for setting an image file on an `Image` field in FormKit. Usage is like this:

```ruby
form.field("image_field").upload_image(image_path)
```

The `value` API also now supports `Image` fields; it returns an `Upload` record if the field has an uploaded image.
This commit is contained in:
Osama Sayegh 2024-11-05 15:35:53 +03:00 committed by GitHub
parent a553c9ea0c
commit c3bc7a6a05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -44,6 +44,10 @@ module PageObjects
component.find("select").value
when "composer"
component.find("textarea").value
when "image"
url = component.find(".uploaded-image-preview a.lightbox", wait: 10)[:href]
sha1 = url.match(/(\h{40})/).captures.first
Upload.find_by(sha1:)
end
end
@ -152,7 +156,17 @@ module PageObjects
if control_type == "question"
component.find(".form-kit__control-radio[value='false']").click
else
raise "'accept' is not supported for control type: #{control_type}"
raise "'refuse' is not supported for control type: #{control_type}"
end
end
def upload_image(image_path)
if control_type == "image"
attach_file(image_path) do
component.find(".image-upload-controls .btn.btn-default").click
end
else
raise "'upload_image' is not supported for control type: #{control_type}"
end
end