How to fix "unexpected alert open: {Alert text : } " error - ruby

I have a project in ruby with AngularJS and I'm currently converting tests over to Headless chrome from Phantomjs, and I keep getting an error:
Selenium::WebDriver::Error::UnhandledAlertError:
unexpected alert open: {Alert text : }
This happens throughout multiple test files..
I have tried adding
"accept_alert {} " before a command :
#from
find('.sp-advanced-configuration').click
#to
accept_alert{ find('.sp-advanced-configuration').click }
but receive
Failure/Error: accept_alert{ ... }
Capybara::ModalNotFound:
Unable to find modal dialog
as well as
Selenium::WebDriver::Error::UnhandledAlertError:
unexpected alert open: {Alert text : }
Not sure what else to try
/*********** *********/
After looking into this further, It seems the issue occurs whenever there are unsaved changes left on the test before moving onto the next test.
Is there a way where you can accept this for every test without having to add
after do
execute_script('window.onbeforeunload = undefined')
end
in every test file?

The reason you're seeing this is that Poltergesit/PhantomJS used to automatically accept unexpected system modals. The selenium driver doesn't do that because your test should actively either accept or decline it. Is find('.sp-advanced-configuration').click the action that opens the alert box? From the errors you're getting I would guess not. The block accept_alert receives needs to be the block that actually triggers the opening of the system modal. This means your code probably needs to be
accept_alert { # action that triggers the alert }
find('.sp-advanced-configuration').click

Related

CAPL: On Message Not Recognizing Database

Programming for CANalyzer in the Vector CAPL Browser, I can start typing "on message CAN4..." and it will auto complete things for me. I can see the messages. But after selecting a message, it always yells at me with "Expecting message name or identifier. Database missing?" as if it has no idea what I just put in even though it helped me put it there. What is the proper format for this? Is it different since I'm using ARXML instead of DBC? Is it just not compatible?
on message CAN4::Something_PDU // Auto-completes this but gives the error
{
}
on message CAN4.Something_PDU // Never auto-completes this and also doesn't work
{
}
on message CAN4::Something_PDU::Something_Auth // Auto-completes but not sure that's what I want and also doesn't compile with same error.
{
}
What is the right way and/or why doesn't it recognize the database despite its obvious ability to auto-complete? So confused!
I just faced a comparable issue when trying to get called by incoming ethernet signals. They are also defined in an *.arxml, in my case. However, the behavior of the Vector CAPL-Browser was exactly the same as you described.
I figured out that replacing on message with on signal does the trick and the script can get compiled:
on signal Something_Signal // autocompletion works and compiles
{
}
on signal Eth1::Something_Signal // autocompletion doesn't work but compiles
{
}
there is another way to do this: goto Windows symbols on the right panel in CAPL Editor >
try to find Something_PDU > drag and drop PDU_Name on your Code after on message
the CAPL event on message should be use with name
try use
on message Something_PDU
instead of
on message CAN4.Something_PDU

How to validate Browser Error's message with cypress

For example if user dont fill this field and press "continue" button, this error message will pop up.
I wonder is there a way with Cypress that I check that error message was displayed?
Kind regards
You can make this assert : cy.get('input:invalid').should('have.length', 1)
See https://github.com/cypress-io/cypress-documentation/pull/1919/files how to assert the validation message
I know this is an older question but here is another solution.
cy.get(`[data-testid="XXXX"]`)
.invoke('prop', 'validationMessage')
.should((text: string) => {
expect(text).to.contain(YYYY);
});
Using the above code here is what happens:
You grab the input / textarea element using cy.get Note: it is recommended to use a data-testid or obtain the element by something less brittle so the test doesn't fail if the text changes etc.
Using the invoke method, you can check validationMessage against prop then then, obtain the inner text and use expect to check if it's valid. This is very handy if you use custom validation messages.

Change error system message in oracle apex

I have a form page and all field is required when press save the below message appear
How i can change this message to custom message "please fill all required fields " , and how i can clear error when enter value (when value change to not null).
I can't see images at the moment.
However, one option might be to create your own validation which returns error text. Something like
if :P1_NAME is null then
return ('Name must be entered');
end if;
Messages are automatically cleared once you submit the page and there are no errors left.
I am not sure if you can change system messages but you can add custom error messages with javascript if a change happens in any item.
Add a change event to the item that runs javascript and use the following code:
var item = apex.item('P1_ITEM').getValue();
if(item == null) {
//First clear the errors
apex.message.clearErrors();
// Now show new errors
apex.message.showErrors([
{
type: "error",
location: [ "page", "inline" ],
pageItem: "P1_ITEM",
message: "Name is required!",
unsafe: false
},
{
type: "error",
location: "page",
message: "Page error has occurred!",
unsafe: false
}
]);
}
However, this will not stop the user from submitting, it only allows you to better display the messages, so you must add the corresponding validations after submit.
If you want to remove the system error message from the required items, you can disable the option of Value Required on item and add a custom validation as they told you in the other response.
If you want to explore all the apex.message options better, I recommend this documentation:
https://docs.oracle.com/database/apex-5.1/AEAPI/apex-message-namespace.htm#AEAPI-GUID-D15040D1-6B1A-4267-8DF7-B645ED1FDA46
More documentation for apex.item:
https://docs.oracle.com/cd/E71588_01/AEAPI/apex-item.htm#AEAPI29448
There are some ways for how to do such things.
Firstly you have the custom Validations you can make, these are awesome and you should really try to use them if possible.
Then there is also the Error message on the saving procedure, but this just throws a custom message on procedure fail so I never use it.
What you appear to be seeing there is that you got an error message and didnt change the fields associated with the error.
If the save procedure is custom, you can also put in an EXCEPTION block before the END, and catch errors there and throw out a custom error with a custom error message.
Another thing I really like is to actually rename some common errors so I dont have to catch them all individually. Say clients may often times try to save identical data, thus breaking the PK. Oracle will throw an error, but the message is good for the developer, but less understandable for the client whom I always assume is a 3 year old kid who can barely read and will cry over everything. So I make an error handling function, add it to apex, and so when the error occurs, it throws a nice message informing the client that they have tried to add some data that already exists.
So, an error handling function associated with APEX, to rename some normal errors.
Good luck

Timeout error for element already clicked

I am getting below exception even when my element has already been clicked and i am navigated to next page.
Caused by: org.openqa.selenium.TimeoutException: Expected condition
failed: waiting for element to be clicked: [[ChromeDriver: chrome on
XP (56f040029c23126b0087ff1dfa82369e)] -> xpath:
//*[#id='login']/app-root/app-caf-login/div/div/div[2]/form/div[3]/div/div/button]
(tried for 10 second(s) with 500 milliseconds interval)
Verifying XPAth but since element is already clicked them not sure why error is coming.
Description: Click the Sign In Button
action: org.getopentest.selenium.Click
args:
locator: { xpath: "//*[#id='login']/app-root/app-caf-login/div/div/div[2]/form/div[3]/div/div/button" }
Description: Pause for 60 second
action: org.getopentest.selenium.ActionsPause
args:
durationMs: "60000"
Expected : no error should be there
As described in this answer make sure you don't use the sendEnter: true argument with any of the SendKeys actions. When you pass sendEnter: true , the action will "press" the enter key after sending the keys to the textbox element. So basically, in the test you showed, the first action will input the username and then press enter, thus trying to log in without a password, which will of course fail.
Also, you are using the ActionsPause keyword incorrectly (more info here). If you want to introduce a delay in your test, you can use the $delay() API, but you very rarely need to do this with OpenTest, since synchronization is built-in, meaning all test actions that perform some work on a UI element know how to wait for that element to be available before doing the work.

Turn off FireFox driver refresh POST warning

I have inherited some GEB tests that are testing logging into a site (and various error cases/validation warnings).
The test runs through some validation failures and then it attempts to re-navigate to the same page (just to refresh the page/dom) and attempts a valid login. Using GEB's to() method, it detects that you are attempting to navigate to the page you are on, it just calls refresh - the problem here is that attempts to refresh the last POST request, and the driver displays the
"To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier"
message - as the test is not expecting this popup, it hangs and the tests timeout.
Is there a way to turn off these warnings in Firefox webdriver? or to auto-ignore/accept them via Selenium or GEB?
GEB Version: 0.9.2,
Selenium Version: 2.39.0
(Also tried with minor version above: 0.9.3 & 2.40.0)
Caveats:
I know about the POST/Re-direct/GET pattern - but am not at liberty to change the application code in this case
The warning message only causes an issue intermittently (maybe 1 in 5 times) - I have put this down to speed/race conditions whereby the test completes the next actions before the message appears - I know a possible solution is to update tests to wait for message to appear and then accept, but my question is, is there a global setting that can just avoid these being triggered/displayed?
That refresh() is there to work around an issue with IE driver which ignores calls to driver.get() with the same url as the current one.
Instead of monkey patching Browser class (which might bite you somewhere down the line or might not) I would change the url of your login page class. You might for example add an insignificant query string - I think that simply a ? at the end should suffice. The driver.currentUrl == newUrl condition will evaluate to false and you will not see that popup anymore.
If I understand you issue properly this might help. In Groovy you can modify a class on the fly.
We use Spock with Geb and I placed this in a Super class which all Spock Spec inherit from. Eg: QSpec extends GebSpec.
It is the original method slightly modified with the original code commented out so you know what has been changed. I use this technique in several required places to alter Geb behaviour.
static {
Browser.metaClass.go = { Map params, String url ->
def newUrl = calculateUri(url, params)
// if (driver.currentUrl == newUrl) {
// driver.navigate().refresh()
// } else {
// driver.get(newUrl)
// }
driver.get(newUrl)
if (!page) {
page(Page)
}
}
}

Resources