I currently am using Marathon (Java Automation tool for testing) that runs a Ruby script on a Java application and need to detect if a specific alert appears. For example, I want it to press "Accept" on a row in a while loop and handle potential pop-up alerts during the process.
Only 2 pop-ups can appear during this process of accepting.
If a popup with the window title "Are you sure?" appears, I want it to press enter or click "OK" as usual.
But, if a popup with the window title "Message" (which indicates error), I want it to press "OK" and exit the while loop. Exiting the while loop should be trivial to code after I figure out a way to differentiate the two pop-ups.
Try using get_window
and check the title with what you are expecting. Alternatively you can execute arbitrary Java code using driver.execute_script
that can look for alert windows and do the needful.
#{{{ Marathon
require_fixture 'default'
#}}} Marathon
def test
with_window("SwingSet3") {
select("JOptionPane", "true")
option = Random.rand(2)
if(option == 0)
click("Show Warning Dialog")
else
click("Show Confirmation Dialog")
end
if(get_window == "Warning Dialog Example")
with_window("Warning Dialog Example") {
click("OK")
}
end
if(get_window == "Select an Option")
with_window("Select an Option") {
click("Yes")
}
with_window("Message") {
click("OK")
}
end
}
end