
Selenium WebDriver diciptakan sebagai alat lintas platform untuk mengelola browser web. Dan selama hampir 14 tahun sekarang dia telah melakukan pekerjaan ini dengan sangat baik. Namun, autotest dunia nyata menciptakan situasi di mana Selenium tidak berdaya. Misalnya, menurut skrip, Anda perlu mengunggah atau mengunduh file. Setelah mengklik tombol "Unduh" atau "Unduh", jendela pengelola file sistem operasi muncul di bagian atas jendela peramban tempat Selenium tidak lagi memiliki akses. Tes berhenti.
Saya mendengar rekomendasi untuk menggunakan utilitas seperti AutoIt atau Sikuli untuk bekerja dengan sistem windows tersebut. Saran saya adalah jangan pernah melakukan ini, ini adalah praktik jahat yang mengarah pada tes yang tidak stabil:
. 15 8 . .
, . — "". , ( input
file
) sendKeys()
"" :
By fileInput = By.cssSelector("input[type=file]");
String filePath = "/home/selenium/files/upload.txt";
driver.findElement(fileInput).sendKeys(filePath);
. Selenium . . . , , , .
, ? , , DOM . $$("input[type=file]")

, findElement()
. . , . , .

Selenium, . , Selenium , . — . (barancev) . , .
, . - , Downloads, Selenium ( Internet Explorer), "" .
, , :

, . . :

, . href
. , , http . Java :
String downloadLink = driver
.findElement(By.cssSelector("main#content a.btn"))
.getAttribute("href");
File fileToSave = new File("/path/to/file.zip");
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(downloadLink);
HttpResponse response = httpClient.execute(httpGet, new BasicHttpContext());
copyInputStreamToFile(response.getEntity().getContent(), fileToSave);
, . , JavaScript . , . , , , . , . , - . , , Selenium. BrowserUpProxy BrowserMobProxy.
, Selenide. DownloadFileWithProxyServer.
, , . https, .
, , . , . — .
Agar tes tetap stabil, faktor yang membuatnya rapuh harus dihilangkan. Dialog sistem operasi, itu adalah salah satu faktor tersebut. Dalam artikel-artikel berikut ini, saya berencana untuk mengungkapkan aspek-aspek penting lainnya yang sangat memengaruhi operasi tes Selenium yang stabil. Dengarkan podcast QA Guild dan otomatisasi yang baik.