I am currently modernising some plugin modules from version 2.x to the OSGi-based 4.x. This project uses the Eclipse application and takes advantage of its view & perspective architecture to serve as a tabbed browser.
Studying the old code and running the Eclipse application, this is what I understand to be the expected behaviour of one particular functionality:
Clicking a link opens a panel in a new tab, which displays a HTML file containing Javascript in it.
The HTML page contains a form culminating in a Submit & Cancel button.
Clicking either button should close the tab. The submit button will, of course, first submit the form data.
Most of the above works as intended, however instead of closing just that one tab, clicking either button causes the entire Eclipse application to attempt to terminate (I received a confirmation prompt asking if I want to exit Eclipse). The submit button did successfully update submitted info into the database before attempting to terminate the Eclipse application.
This is what the offending part of the code looks like:
function onSubmit() {
//processForm();
if (opener) {
opener.newAddressValue(newToAddress);
window.close();
} else if (parent.parent) {
parent.parent.newAddressValue(newToAddress);
parent.parent.closeUsrFrame();
} else {
parent.newAddressValue(newToAddress);
parent.closeUsrFrame();
}
}
function onCancel() {
if (opener) {
window.close();
} else {
parent.closeUsrFrame();
}
}
I suspect the expected behaviour is for program flow to reach window.close() at which point the tab containing the opened panel should close, but instead it is causing the entire Eclipse application to terminate. What is the correct way to exit the current tab in Eclipse 4.x using JavaScript?
If the program display a HTML file using SWT Browser widget, you can use Browser.addCloseWindowListener(CloseWindowListener listener) to hook the event that triggered by javascript window.close.
If your program do prompt about exiting Eclipse, you shall search class that implement CloseWindowListener interface. Modify its behavior as you wished.
Related
I am trying to build a homepage of a website in Kali Linux. So, I installed VS Code and added an extension " Live Server " written by Ritwick Dey. I made HTML file, then CSS and now JavaScript. When I was writing HTML and CSS files, everything was normal with Live Server. But when i started writing JavaScript file, there happened a glitch. Every time, when I take rest after writing some text in alert(" ");, the browser automatically opens.
I had used only alert("some text");in JavaScript file. After, I made some changes in file by adding some other statements such as document.getElementById("appname").innerHTML="howdy"; Other statements do not made any disturbance but when I write alert("some_text");, the browser automatically opens.
I had enabled Auto Save as "afterDelay" and, while writing this question, I gave "off" value to Auto Save, it stopped automatically opening the browser but when I save the file, it opens the browser.
I do not want to let the browser open automatically, when I save the file. I want to open the browser manually.
you can put your alert in a function with javascript, make a timer on onclick button so it works when you want it not when server loads
I'm using selenium IDE (currently available only on firefox) to do some automated testing of a site I'm coding. When selenium navigates to, a form filling page, and fills in the info - a 'window.alert()' is called by a button.
When using selenium my set of commands look like this:
open /
clickAndWait document.form1.Action[1]
select stuff
type stuff
etc, etc
click name=myPreview
When I click through recording this the first time, it works no problem. When I rerun the script window.alert and alert don't work from the console or anything. I've debugged it, and its not working.
When a window.alert() is called as part of a selenium script (I'm talking at least in the IDE), it is called even though a user watching does not see an alert pop up. According to the documentation:
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.
Both assertAlert and verifyAlert are both based off getAlert(), all of which do the alert 'stuff' in the background. So try adding these functions to ensure that the alert is working, run the script, and then check to see if it works.
A note: this only works if you ensure the test fails before you put in the alert (basic idea of testing, fail first - make test pass).
In my django app I use Ghost.py to render a web page with some Javascript. The problem is that sometimes the JS takes a while to run and Ghost.py thinks that my JS script is not working well and raises the typical confirmation box asking me whether I want to terminate the script.
In my machine I see that the confirm box comes up and press the 'No' button when it asks me to terminate the script. But when it's running in an AWS EC2 instance, that confirm box causes a dead lock because it will keep waiting for someone to press the 'Yes' or 'No' button.
Is there a way to automatically press the 'No' button every time a confirm box shows up?
I tried using:
ghost = Ghost(wait_timeout=20)
ghost.confirm(False)
ghost.open(html_path)
ghost.capture_to(img_path)
as well as this:
ghost = Ghost(wait_timeout=20)
ghost.open(html_path, default_popup_response=False)
ghost.capture_to(img_path)
The documentation on the topic is scarce. Any help is appreciated.
I am trying to automate a process in which the user downloads a file extract from a website. My issue is that once the 'export' button in clicked, a javascript popup window comes up with various date parameters for the extract along with the final 'DOWNLOAD' button that needs to be clicked. The problem arises during this javascript popup window. Once the export button is clicked and the popup window opens, powershell seems to freeze up during the script and will not allow any further commands to be executed.
I have tried using the WASP module along with SELECT-WINDOW in order to grab the correct IE process window, however the 'Select-Window -Title "NAME OF POPUP WINDOW - Windows Internet Explorer" | Select -First 1 | Set-WindowActive' command will not execute as Powershell gets stuck 'Running script' immediately after the initial 'export' button is clicked (right when the popup window opens). Is there a way I can either 'refresh' Powershell after the popup box is opened in order to execute further commands, or any ideas on a way to break out of the continuous 'Running script' loop that I get stuck in with this Javascrip popup window?
# Set access URL and Credentials
$WebU='username'
$WebP='password'
$URLlogin='http://websiteurl.com'
$IEwait="1000"
# Execute IE and navigate to URL
$ie = New-Object -com "InternetExplorer.application";
$ie.visible = $True;
$ie.navigate($URLlogin);
Try{
# Login steps
while ($ie.Busy ) { Start-Sleep -Milliseconds $IEwait; }
if ($ie.Document.getElementByID("txtLogin"))
{ $ie.Document.getElementByID("txtLogin").value = $WebU }
while ($ie.Busy ) { Start-Sleep -Milliseconds $IEwait; }
if ($ie.Document.getElementByID("txtPassword"))
{ $ie.Document.getElementByID("txtPassword").value = $WebP }
while ($ie.Busy ) { Start-Sleep -Milliseconds $IEwait; }
if ($ie.Document.getElementByID("btnLogin"))
{ $ie.Document.getElementByID("btnLogin").Click() }
# Navigate through website to find the 'Export' button
while ($ie.Busy ) { Start-Sleep -Milliseconds $IEwait; }
if ($ie.Document.getElementByID("managementMenu_btnLearningResults"))
{ $ie.Document.getElementByID("managementMenu_btnLearningResults").Click() }
while ($ie.Busy ) { Start-Sleep -Milliseconds $IEwait; }
# This is the part that freezes the script. Once the 'btnExport' button is clicked, a JS popup keeps Powershell from executing any additional commands
if ($ie.Document.getElementByID("btnExport"))
{ $ie.Document.getElementByID("btnExport").Click() }
# Once the popoup box opens, sending the 'ENTER' key should automatically download the export file
Select-Window -Title "NAME OF POPUP WINDOW - Windows Internet Explorer" | Select -First 1 | Set-WindowActive
Select-Window -Title "NAME OF POPUP WINDOW - Windows Internet Explorer" | Select-childwindow | Send-Keys "{ENTER}"
}
# These won't execute because the JS popup window confuses Powershell and keeps it in a continuous 'Running Script' process
Catch {
"Error" }
Finally {
"Now able to execute further commands" }
This problem comes up a lot when automating GUI browsers - modal dialogs like the JS popup you describe will block your script from finishing until someone dismisses it. This is because the call you made into browser itself (which caused the modal dialog to appear) is also blocking, waiting for interaction from the user.
In my experience the easiest way to deal with this scenario is to launch a separate process just to handle the modal dialog. It takes two steps:
Write a small standalone script/program that will wait for the modal dialog to appear, then dismiss it. This is easy to test by launching the popup-handling script manually, then manually performing the steps that make the dialog appear.
Once you have that working, in your main program that automates the browser, launch your separate dialog-handling script just before you execute the line of code that creates the modal dialog.
And that's it. It feels clunky but it will work in pretty much any case I've seen (unless the modal dialog requires elevated security privileges, which brings up other issues).
Also, if you're using a programming language that has native thread support, you can launch a separate thread (instead of a process) to handle modal dialogs.
Some test automators feel it's actually cheaper (in terms of script development and maintenance time) to simply bypass modal dialogs like this if possible, assuming you can get around it and still feel confident in your testing. Sometimes this might require modifying the application to give your test code a special interface into the system.
The IE object model is actually kind of treacherous. It often says things are ready when they aren't, because an underlying resource hasn't yet loaded. I got annoyed rewriting this code each time I had to interact with a page, so I wrote a module called AutoBrowse to deal with it:
http://autobrowse.start-automating.com/
Use this instead, and you will sidestep the issue.
Hope this helps
While ( $ie.busy -eq $true){
[System.Threading.Thread]::Sleep(2000);
$wshell = New-Object -ComObject wscript.shell;
if($wshell.AppActivate('Message from webpage'))
{
[System.Threading.Thread]::Sleep(1000);
[System.Windows.Forms.SendKeys]::SendWait('{Enter}')
}
}
Is there a way by which we can capture the click of HOME and BACK button in the html file in android application using phonegap/jqtouch/javascript?
I have an application for Android using phonegap. I want to capture the click of native HOME and BACK button of the Android phone in the html page to exit / go back gracefully.
You can catch the BACK button event in PhoneGap, however not the HOME button (this is a bad Android practice as there is a clear user expectation regardless of the app you're using about what the HOME key does: sends you back to your home screen! You don't want to override this functionality).
I will direct you to pieces of code in PhoneGap (LATEST source! pull from github for latest version of the phonegap framework) for guidance.
First, there is a 'BrowserKey' java object bound to the 'BackButton' JavaScript global:
http://github.com/phonegap/phonegap-android/blob/master/framework/src/com/phonegap/DroidGap.java#L291
The definition of this class is here: http://github.com/phonegap/phonegap-android/blob/master/framework/src/com/phonegap/BrowserKey.java
First thing you need to do in your application (I suggest you run this during application initialization) is to let the native side of the framework know you are overriding BACK button functionality. You would do this in JavaScript with a simple call:
BackButton.override();
From there on out, you can attach an event handler to the document's 'backKeyDown' event to execute logic every time the BACK button is hit. Something like this should work:
document.addEventListener('backKeyDown', function(e) {
alert('you hit the back key!');
}, false);
As an addendum, here is the JavaScript code that wraps the back button event dispatching: http://github.com/phonegap/phonegap-android/blob/master/framework/assets/js/keyevent.js
Basically, after calling BackButton.override(), the native side of the framework will call window.keyEvent.backTrigger() every time the BACK button is hit.
This code sample works for PhoneGap 0.9.5 and later (tested on 0.9.6) :
document.addEventListener("menubutton", function () {
alert('Menu button');
}, false);
document.addEventListener("searchbutton", function () {
alert('Search button');
}, false);
document.addEventListener("backbutton", function () {
alert('Back button');
}, false);
Home button can't be handled. That's reserved by the system.
I have an application for Android using phonegap. I want to capture the click of native HOME and BACK button of the Android phone in the html page to exit/go back gracefully.