How to set a default wait for Alert with Capyabara? - ruby

In my code I don't want to use sleep. How do I use wait_until.
########### my code ###############33
btn_logout.click
sleep 3
page.driver.browser.switch_to.alert.accept

This should work
accept_alert do
btn_logout.click
end
It'll wait for the modal as long as the max wait time that is set for Capybara.

Related

using click() in Cypress

I am testing my app using Cypress, in my app there is a one minute timer. When the timer expires, no button should work. To put it more precisely, even though the user clicks on buttons, nothing should happen (functions connected to those buttons should not be triggered). How can I test such a thing?
cy.get('#timer-btn').click().wait(60000)
cy.get('#timer').should('have.text', 'TIME IS UP, your score is: 0')
cy.get('.btn').click()
//???
I believe you could use cy.clock() and .tick() to manipulate the time the browser thinks has passed
cy.clock();
cy.get('#timer-btn').click();
cy.tick(60000);
cy.get('#timer').should('have.text', 'TIME IS UP, your score is: 0');
cy.get('.btn').click();
Instead of using wait use timeout because wait waits for a total of 60 seconds, but with a timeout, it is terminated whenever the expected condition is met.
cy.get('#timer-btn').click()
cy.get('#timer', {timeout: 60000}).should(
'have.text',
'TIME IS UP, your score is: 0'
)
cy.get('.btn').click()
Now if the button is disabled after 60 seconds you can use:
cy.get('#timer-btn').click()
cy.get('#timer', {timeout: 60000}).should(
'have.text',
'TIME IS UP, your score is: 0'
)
cy.get('.btn').should('be.disabled')
Now, if you see on comparing the HTML of the button during and after the timer, if any attribute-value pair is added to the button after the timer is completed, you can assert that using:
cy.get('#timer-btn').click()
cy.get('#timer', {timeout: 60000}).should(
'have.text',
'TIME IS UP, your score is: 0'
)
cy.get('.btn').should('have.attr', 'attr-name', 'attr-value')
If you see just an attribute is added you can just use
cy.get('.btn').should('have.attr', 'attr-name')

Applescript run script every 5 seconds

I am trying to run the following code as a coroutine. Is there any way to accomplish this?
repeat
delay 5
log theScript
end repeat
Use the on idle handler and save the script as application
on idle
log theScript
return 5
end idle
In case of an AppleScriptObjC application you can't use the idle handler, an alternative is NSTimer of the Foundation framework.
property timer : missing value
on applicationWillFinishLaunching:aNotification
set timer to current application's NSTimer's scheduledTimerWithTimeInterval:5.0 target:me selector:"timerFired:" userInfo:(missing value) repeats:true
end applicationWillFinishLaunching_
on timerFired:aTimer
log "timerFired"
end timerFired

Making an echo line stay on screen for a certain time

As I said in the title i have a batch file with echo lines. I want them to stay each on the screen for a certain period of time. Could you give me an exemple of such?
You can do this using sleep command. For example:
SLEEP 5
This will delay the execution for 5 seconds.

GUI interaction, waiting until the window is open

Is there a bash command that waits for a window to open? Right now I'm doing something along the lines of:
open-program
sleep 100 # Wait for the program to open
send-keyboard-input
Is there a way to have "send-keyboard-input" wait until open-program finishes, eliminating the sleep 100? The time always varies, sometimes it's 90 seconds, sometimes it's 50 second.
Have you tried this?
open-program && send-keyboard-input

Watir ... difference between sleep and wait

Is there any notable difference between
sleep 10
and
wait_until(10)
They both seem to do the same thing: wait 10 seconds then proceed to the next step
sleep just does nothing for the specified time. wait_until takes a block. It waits until the block evaluates to true or times out. If no block is given they act the same.

Resources