القائمة الرئيسية

الصفحات

Selenium - Override javascript functions to ignore downloading process

I have got an issue with downloading process on IE 8. This browser blocks my automatic-download functionality on my app so that I could not work with my test case any more after that. In my case, I didn't care about the file is downloaded or not, I just focus on the result after downloading process finished successfully. Therefore, I found a solution to ignore this process so that I can work normally.

I use Primefaces, here is the remote command to trigger the download process

<p:remoteCommand name="cmdGenerateDocument" actionListener="#{logic.onGenerateDocument}" update="xrflDocumentCreationPanel" oncomplete="clickDownloadButton();"/>

The following is my test case:
@Test
public void shouldUpdateStep6ToWarningIfStep1IsValidAfterFinished(){
MainPage mainPage = new MainPage();
waitForLoading(mainPage.getDriver());

EmployeeDetailPage empDetailPage = new EmployeeDetailPage();
waitForLoading(empDetailPage.getDriver());
empDetailPage.fillDataForAllFields();

mainPage.clickNext();
waitForLoading(mainPage.getDriver());

mainPage.clickNext();//move to step 3
waitForLoading(mainPage.getDriver());

mainPage.clickNext();//move to step 4
waitForLoading(mainPage.getDriver());

mainPage.clickNext();//move to step 5
waitForLoading(mainPage.getDriver());

//avoid issue with download automatically on IE8
mainPage.ignoreDownloadProcess();

mainPage.clickNext();//move to step 6
waitForLoading(mainPage.getDriver());

mainPage.jumpToEmployeeDetailTab();
waitForLoading(mainPage.getDriver());

empDetailPage.setEmptySalutaion();
waitForLoading(mainPage.getDriver());

mainPage.jumpToDocumentCreationTab();
waitForLoading(mainPage.getDriver());

assertTrue(mainPage.isRequriedFinishedAllStepsMessageShown());
assertTrue(mainPage.isRequriedMessageShownOnStep1());
assertTrue(mainPage.isStep6Warning());
}

The content of function "ingnoreDowloadProcess()"
public void ignoreDownloadProcess() {
String script = "clickDownloadButton = function(){};";
((JavascriptExecutor) getDriver()).executeScript(script);
}

Comments