Skip to content

Instantly share code, notes, and snippets.

@jasonporritt
Created November 15, 2010 02:56
Show Gist options
  • Save jasonporritt/676364 to your computer and use it in GitHub Desktop.
Save jasonporritt/676364 to your computer and use it in GitHub Desktop.
File upload testing
[When("I choose a photo to upload")]
public void UploadImageFor()
{
// Where Browser is your current Browser object
var fileUpload = Browser.FileUpload(x => x.Name == "Photo");
var assembly = Assembly.GetExecutingAssembly();
var fileStream = assembly.GetManifestResourceStream(assembly.GetName().Name + ".TestData.image.jpg");
var fileData = new byte[fileStream.Length];
fileStream.Read(fileData, 0, fileData.Length);
var filePath = Path.GetTempFileName();
var tempFile = File.Create(filePath);
tempFile.Write(fileData, 0, fileData.Length);
tempFile.Close();
fileUpload.Set(filePath);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment