How to create alert box in protractor? - javascript

During testing, I'm trying to put a alert pop up box when my environment is changing from test to prod during executing the scripts in protractor. Can anybody help with me with this?

If browser alert popup is acceptable option, you can execute javascript on browser side via protractor api: browser.executeScript().
var env_change_alert = "alert('Environment changes from test to prod')";
browser.executeScript(env_change_alert);
And you will get popup on the browser with which your test case interact as following:
The popup will block your test running until you click on the OK button on the popup.

Related

Testcafe native browser dialog not displaying, getNativeDialogHistory is undefined

I'm just getting started with testcafe. The website that I need to test has a native browser window alert that loads before anything displays on the page, and that alert prompts the user for credentials. If the cancel button is clicked, the page is blank except for one word "unauthorized".
When I have my test navigate to the website, I see no window alert at all. The page immediately displays the "unauthorized" message. Is testcafe automatically closing this alert? Neither setNativeDialogHandler nor getNativeDialogHistory are working. How can I have testcafe enter text into two fields in this dialog?
Thank you!
I suppose your site has HTTP authentication. TestCafe can work with HTTP authentication, however, it prevents showing the dialog. This means that everything will work, but you will not see the dialog.
Please read the following
article: https://devexpress.github.io/testcafe/documentation/test-api/authentication/http-authentication.html

How to storeConfirmation in popup SeleniumIDE

Can u help me about StoreConfirmation for popup SeleniumIde ? + example command.
please answer only selenium IDE.
Thanks
If you are talking about default javascript alert or confirmation there are two commands for it:
storeAlert
Returns:
The message of the most recent JavaScript alert
Retrieves the message of a JavaScript alert generated during the
previous action, or fail if there were no alerts.
Getting an alert has the same effect as manually clicking OK. If an
alert is generated but you do not consume it with getAlert, the next
Selenium action will fail.
Under Selenium, JavaScript alerts will NOT pop up a visible alert
dialog.
Selenium does NOT support JavaScript alerts that are generated in a
page's onload() event handler. In this case a visible dialog WILL be
generated and Selenium will hang until someone manually clicks OK.
storeConfirmation
Returns:
the message of the most recent JavaScript confirmation dialog
Retrieves the message of a JavaScript confirmation dialog generated
during the previous action.
By default, the confirm function will return true, having the same
effect as manually clicking OK. This can be changed by prior execution
of the chooseCancelOnNextConfirmation command.
If an confirmation is generated but you do not consume it with
getConfirmation, the next Selenium action will fail.
NOTE: under Selenium, JavaScript confirmations will NOT pop up a
visible dialog.
NOTE: Selenium does NOT support JavaScript confirmations that are
generated in a page's onload() event handler. In this case a visible
dialog WILL be generated and Selenium will hang until you manually
click OK.
You can see working example here : http://www.software-testing-tutorials-automation.com/2013/10/selenium-ide-what-is-use-of.html
Hope it will help you.

Continues adding of tests to phantomjs

I am new to PhantomJS, so this is maybe stupid.
I would like to create a testing environment, that will allow user to add tests (predefined) instantly and every test is run immediately.
Example (this tests are added dynamically):
load page, compare load speed
click on button, check if dialog opens
close dialog, check if dialog is closed,...
Now in phantomjs I see this phantom.exit, and as I understand it, it closes phantomjs process. Is it possible to get the result and add new tests dynamically, without canceling phantomjs (phantom.exit)?

Scripts not running in FF and Chrome

I am using javascript alert message to show validation messages. In Firefox and Chrome first time working fine,second time for same alert same its asking message like "Prevent this page from creating additional dialogs" with check box. After select that check box, Next time button click scripts not executing. How to block that message?
Use a JavaScript Modal popup! eg. JQuery UI Modal Popup
This is a browser matter, so you as a developer cant do anything with that behavior.
Here is a similar question
already answered here
unfortunately you can't be sure that user has his browser settings with javascript alerts popup on ( that called with 'alert('...') function').
You should use javascript dialog plygin instead.
For example:
http://fancybox.net/
its a browser property for the client,if he doesnt want to view these alerts. you cant remove that check box and message.
if this message is shown then what the problem, leave it for the user.
why you want to force him to view these alerts,
it must be user's wish to see or not see these alerts.
for better user experience and for your purpose you can use fancybox or facebox
fancy box fiddler check this http://jsfiddle.net/BJNYr/

Selenium IDE 1.8.1 Alert box : cannot see the alert box while running the tests

I am writing the tests in selenium and Junit and importing the tests as Junit4 Remote control for web application , while I am running the tests it passes the steps but I am not able to see the alert opening but the test passes.
Why I am not able to see the alet box while running the tests??? I will be thankful to the answers.
assertEquals("Please enter valid city ", selenium.getAlert());
Under Selenium, JavaScript alerts will NOT pop up a visible alert dialog. Selenium does NOT support JavaScript alerts that are generated in a page's onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until someone manually clicks OK.
to verify your alert use this: storeAlertPresent(variableName)
Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts : storeAlert ( variableName )
So now you can assert this stored alert.
And There is one more command present, If you want to click on cancel button instead of OK button: chooseCancelOnNextConfirmation()

Categories