File upload
The server shows the name and size of what it received and throws the files away. Up to 1 MB per upload.
What to practise
- Upload one file and check its name and size; upload two files at once.
- Submit without a file and check the message; check that the third field is disabled.
- In Selenium (and VAF) a file is "chosen" by sending its full path to the field; several paths are separated by a new line.
In VAF: AsUploadFileField().LetsUpload(path).
Tested in VAF-Demo
A test of this page from VAF-Demo: the whole VAF chain, from the page to the element, is in the test.
[Test]
public void OneFileIsReceived()
{
string file = Path.Combine(TestContext.CurrentContext.WorkDirectory, "vaf-demo-upload.txt");
File.WriteAllText(file, "Hello VAF");
SharedContext.App.Should().HaveSection<UploadPage.Form>()
.That.Should().HaveElement<UploadPage.Form.Single>()
.That.AsUploadFileField().LetsUpload(file)
.AndAlso().Should().HaveElement<UploadPage.Form.Upload>()
.That.AsButton().LetsClick();
SharedContext.App.Should().HaveSection<UploadPage.Result>()
.That.Should().HaveElement<UploadPage.Result.First>()
.That.AsLabelText().Should().HaveValue("vaf-demo-upload.txt — 9 bytes");
}
On GitHub (opens in a new tab)
-
Page object
—
UploadPage.cs: the locators of this page -
Native tests
—
UploadTests.cs: the whole VAF chain in each test - The whole project and its README Latest test run (GitHub Actions)