0

I want to achieve the following process. The scripts are written in Katalon, but it does not matter. Selenium approach is enough.

I test an appearance of two elements in a dialog window. If a text message appears, the second element will not come and the dialog window is closed. If the first element (message) is not displayed, a button that displays after a certain amount of time is clicked.

I would like to continue and avoid using wait until element is visible/invisible. I do not know how to do it, but any action is triggered first it will go through it.

The problem is that the test waits for the message for the certain time and if it not displayed in (let say 30 sec), it clicks on the button. I want to avoid to wait until it is visible, and instead of waiting just to click immediately on the button. So the aim is to track two parallel actions (not selenium actions) and which one is fired first. Is there any approach? Maybe using tasks?

Here is the code:

TestObject dialogWinEl = findTestObject("Object Repository/FinacDocAndPayments/dialogWindow/div_dialogWin")
WebUI.waitForElementVisible(dialogWinEl, GlobalVariable.TIMEOUT_ELEMENT, FailureHandling.OPTIONAL)

TestObject statusMsgFilesDownloadEl = findTestObject("Object Repository/InvoiceDetailPage/div_dialogWin/span_noDocFoundStatus")
boolean noDownloadFiles = WebUI.waitForElementVisible(statusMsgFilesDownloadEl, GlobalVariable.DOWNLOAD_BTN, FailureHandling.OPTIONAL)

        if(noDownloadFiles){
            KeywordUtil.markPassed("No files found to download. Closing dialog")
        }
        else{
            KeywordUtil.markPassed("Files found. Click on Download files")
            TestObject btnEl = findTestObject('Object Repository/InvoicesAndPayments_Global/btn_generic', [('btn_text'):btnName])
            WebUI.waitForElementClickable(btnEl, GlobalVariable.TIMEOUT_ELEMENT)
            WebUI.click(btnEl)
            KeywordUtil.markPassed("File downloaded. Closing dialog window")
        }

TestObject xBtn = findTestObject('Object Repository/InvoicesAndPayments_Global/confDialog/div_closeBtn')
WebUI.waitForElementClickable(xBtn, GlobalVariable.TIMEOUT_ELEMENT)
WebUI.click(xBtn)
KeywordUtil.markPassed("Dialog window has been closed")

Basically the variable noDownloadFiles is equal to the status of the particular element (visible or not) and it waits for the time that is in the var GlobalVariable.DOWNLOAD_BTN = 20sec. The problem here is if this variable is false it means that it waited for the specific amount of time and then it continues in the else branch. The point is if the button appears earlier it does not have to wait to see if statusMsgFilesDownloadEl is visible or not. I simply want to use this:

WebUI.waitForElementVisible(statusMsgFilesDownloadEl, GlobalVariable.DOWNLOAD_BTN, FailureHandling.OPTIONAL) 

and

WebUI.waitForElementClickable(btnEl, GlobalVariable.TIMEOUT_ELEMENT) 

and once the first or second is evaluated it continues. There is no reason to wait for one and then for the other.

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
Michal
  • 610
  • 10
  • 24
  • We don't even know your current approach... post your code and describe what you are attempting to do with the current approach. Then explain what problems you are running into with error messages, etc. – JeffC Nov 14 '18 at 19:20
  • @JeffC Ok added – Michal Nov 14 '18 at 19:46
  • It is not clear what are you trying to achieve. Is it even possible to click the `btnEl` before the `statusMsgFilesDownloadEl` appears? – Mate Mrše Dec 14 '18 at 09:19

0 Answers0