Angie Jones and Applitools has recently launched a new initiative – Automation Cookbook. It has free bite-size recipes related to JS (#Cypress) & Java (#Selenium).
Here is a tip from cookbook: Uploading files with Selenium Java:
Code:
package file_upload;
import base.BaseTests;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
public class FileUploadTests extends BaseTests {
@BeforeEach
public void launchApp(){
driver.get("https://kitchen.applitools.com/ingredients/file-picker");
}
@Test
public void testFileUpload() {
String filePath = "/Users/angie/workspace/recipes/resources/images/mac-n-cheese.jpg";
driver.findElement(By.id("photo-upload")).sendKeys(filePath);
}
}
You can practice above code in this file picker: https://kitchen.applitools.com/ingredients/file-picker
Find more Selenium and Cypress recipes over at the Automation Cookbook: https://applitools.com/cookbook/
Thanks to Angie and Applitools for making our life easy.