SWT eclipse browser does not work on Linux - java

I have tried eclipse GIT sample to open SWT browser
Ref : http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet260.java
This code works on Windows without any problem .But I get below exception in Linux.
I am developing an eclipse plugin which has repository setting page which is created by extending "AbstractRepositorySettingsPage" in the overrided method #Override "public void run(IProgressMonitor a_monitor) throws CoreException" I am creating Display in this method
Update :
This code works if I run it through main() method in Linux.
org.eclipse.swt.SWTError: Not implemented [multiple displays]
Root exception:
org.eclipse.swt.SWTError: Not implemented [multiple displays]
at org.eclipse.swt.SWT.error(SWT.java:4423)
at org.eclipse.swt.widgets.Display.checkDisplay(Display.java:767)
at org.eclipse.swt.widgets.Display.create(Display.java:908)
at org.eclipse.swt.graphics.Device.<init>(Device.java:156)
at org.eclipse.swt.widgets.Display.<init>(Display.java:507)
at org.eclipse.swt.widgets.Display.<init>(Display.java:498)
at com.test$OpenPage.run(test.java:267)
at org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage$29.run(AbstractRepositorySettingsPage.java:1964)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
AFAIK above exception is caused because it tries to create a new Display object So I tried to create the Display with existing NON UI thread and open the browser
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable()
{
public void run()
{
Shell aShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
Shell myShell = new Shell (aShell , SWT.SHELL_TRIM);
// Very important, generally parents must have a layout set to display children
myShell.setLayout (new FillLayout());
Browser browser = new Browser (myShell, SWT.NONE);
browser.setUrl ("http://www.google.de");
myShell.layout();
myShell.open();
}
});
The above snippet opens the browser but it does not allow to enter anything in the opened search engine. I want to enter in the available text box and also It does not close the opened browser on click of close button. I terminate the eclipse.

Related

JavaFX update Webview WebEngine loaded website UI after delay Thread

I have a Webview component inside a JavaFX Program (using FXML) and I want to open it to an external html which is supposed to be a loading screen. (it is necessary due to other background tasks getting perfomed like checking for the existence of a file every 5 seconds)
Then after 5 seconds It is supposed to open the real html file (in this example : "google.com") and should open it.
The problem I've run into is that when i put a delay right after the first engine.load(""); and then after the delay another engine.load(""); with the proper website it will wait that time and then just open the second website without ever opening the first.
So Using a delay without an additional Thread made the Program only open after that time has passed and only opened the second WebEngine.
Using a Thread worked when i put in Thread.sleep(5000); and after that only System.out.println("Hello World!"); but if I put anything related to JavaFX it gives the error that it cannot update the UI outside of Main Thread
I haven't found an option to update the WebEngine Method to load a different website since i am unable to access it outside of my loading Method and Updating it from a different Thread is not allowed.
Using Platform.runLater() has given me nothing but errors because the WebEngine is either not recognized as the same Engine and gives the error that it cannot find the object or it gives the error that JavaFX cant update UI Elements outside of its own Thread.
#FXML
private void initialize() throws InterruptedException {
WebEngine engine = webView.getEngine();
String url = "";
try {
url = getClass().getResource("/index.html").toExternalForm();
} catch (Exception e) {
}
loadSub(url, engine);
}
boolean test = false;
private void loadSub(String website, WebEngine engine) {
engine.load(website); // load loading Screen
//wait 5 seconds
engine.load("Google.com"); //load appropiate website
}

TestStack White error JAVA app

I try TestStack.White to run an automation for JAVA app, here in my example is Calculator coded in JAVA, under VS2015 in C#. I installed TestStack.White using NuGet and tring with Winform app and it works, but here with java app, I can open the application, But not all component I can click on it.
So I try to know the component name with UIA Verify interface, but it selects the whole window, after that I look for something similar to UI Verify, and I found Ranorex STudio with Track Features and it works I can see Java Component name, but after I know the name, and I searsh for it in the app, the code not working. This is my code:
class Program
{
static void Main(string[] args)
{
Application aa = Application.Launch("..\\..\\CalculatorOrange.jar");
Window calcWindos = aa.GetWindow("Calculator Lite - 1.5.3", InitializeOption.NoCache);
Button twoBtn = calcWindos.Get<Button>(SearchCriteria.ByText("8"));
twoBtn.Click();
//var twoBtn = calcWindos.Get<MenuBar>("mnuFile");
//twoBtn.Click();
}
}
and it shows this error:
An unhandled exception of type 'TestStack.White.AutomationException'
occurred in TestStack.White.dll
Additional information: Failed to get (ControlType=button or
ControlType=check box),Name=8
This image shows the component type and name
Update 1 : On the left, I use Ranorex Spy, and it shows all the Component, and on the right the Inspect for Microsoft

Access windows native message dialog box windowtester

I am a new to this. I am working on WindowTester.I could not open a new discussion page or I would tag it as Windowtester
I am having difficulty of closing down windows native dialog box after pull down menu. The code is,
ui.click(new PullDownMenuItemLocator("Save Control ", new ViewLocator("com.SOAGateway.control.views.SOAGView")));
After choosing one of the option from the menu, a dialog box appear which is native window dialog.
I would like to cancel it but it is not working.
I tried different things such as,
a)
ui.click(new PullDownMenuItemLocator("Save Control ", new ViewLocator("com.SOAGateway.control.views.SOAGView")));
Display display = new Display();
if (shell != null) shell.dispose();
b)
Display display = new Display();
ui.click(new PullDownMenuItemLocator("Save Control ", new ViewLocator("com.SOAGateway.control.views.SOAGView")));
display.dispose();
But nothing is working.
Is there any idea how could I sort out this problem.
Thanks.
Interaction with native Dialogs is very limited in Windowtester.
However, you should be able to cancel a native dialog in Windows with the following line of code:
ui.keyClick(WT.ESC);
SWTBOT can't handle native dialogs - see http://wiki.eclipse.org/SWTBot/FAQ#How_do_I_use_SWTBot_to_test_native_dialogs_.28File_Dialogs.2C_Color_Dialogs.2C_etc.29.3F

Wait for Netbeans Platform application to deserialize all previously opened windows

I am developing a Netbeans Platform application and face the following problem:
When closing my app persists the opened windows A and B.
Upon reopening my app the windows get deserialized one by one. First A then B.
It is very possible that I receive new information for window B during the reopening of window A.
At this point the program logic decides whether to open a new window B or use the existing one. But since window B doesn't exist yet it opens a new window. Afterwards the "old" window B is opened via deserialization.
Is there a way to wait until all windows are opened? I could delay the opening of additional windows until all windows are opened.
I found nothing in the Windows-System API or in the class WindowManager.
Any other idea?
13 Views and 0 answers, we need more netbeans platform developers!
WindowManager.getDefault().addWindowSystemListener(new WindowSystemListener() {
#Override
public void beforeLoad(WindowSystemEvent wse) {
}
#Override
public void afterLoad(WindowSystemEvent wse) {
// at this point all windows are opened
}
#Override
public void beforeSave(WindowSystemEvent wse) {
}
#Override
public void afterSave(WindowSystemEvent wse) {
}
});

Webdriver showModalDialog

We are using webdriver for our functional tests. But our application uses the showModalDialog JS function a lot to open a popup. When we try to test this functionality with webdriver it hangs from the moment the popup is opened.
We tried several things to test this:
Using the workaround explained here. But this seems to be a fix for selenium and not for webdriver. We tried it but it didn't work.
Searching for a good alternative, HtmlUnit opened the modal dialog and could interact with it, but it has it's drawbacks like no visual help to fix certain tests and it stopped execution when it detected a JS error in a JS library we have to use but have no control over.
How can we test this or work around this problem?
From my experiences with various automation tools interaction with "webpage dialog" windows opened from IE using window.showModalDialog() or window.showModelessDialog() is not available.
Since the window is not a "true" window (look at the taskbar, it doesn't even show up) most tools can't "inspect" it and/or interact with it.
However if you do find a tool that will, please advise - there are many people looking for such a beast.
That all said, if you can possibly avoid using either of these 2 proprietary methods you'll have much more luck.
(and yes, for the picky ones, Firefox and Chrome have adopted these kind of dialogs but they don't work quite the same)
None of the answers answer the question. If the driver hangs, then you can't call any methods on it. The question is NOT about finding the pop up, it is about how to stop the driver hanging. The only way I have found is to not use showModalDialog. This can be done by adding the folowing to your test code :
((JavascriptExecutor) driver).executeScript("window.showModalDialog = window.open;");
which calls window.open each time your JavaScript calls window.showModalDialog.
I am using webdriver.SwitchTo().Window() method but my concern is my popup window does not have "Name"
When I use webdriver.WindowHandles it return only one handle, I am using this statement after popup window open.
As I don't have name / handle I cannot switch from parent window to child window.
Any other solution to do the same functionality
First we have to switch to the active element:
driver.switchTo().activeElement();
To check whether we have actually switched to the correct active element:
driver.switchTo().activeElement().getText();
Even if the window doesn't have name u can use
driver.switchTo.defaultcontent();
and perform the operation you want to execute
or else you can get the window handle name using the below command
for (String handle : driver.getWindowHandles()) {
driver.switchTo().window(handle); }
hope this should work for you.
Issue 284 is for WebDriver. It seems that it will be implemented only after Issue 27 will be implemented, so the fix should be in Beta 1 or 2 of WebDriver.
Set<String> beforePopup = driver.getWindowHandles();
Set<String> afterPopup = driver.getWindowHandles();
afterPopup.removeAll(beforePopup);
if(afterPopup.size()==1){
System.out.println(afterPopup.toArray()[0]);
}
driver.switchTo().window((String) afterPopup.toArray()[0]);
What I have been using and it works great for us on with IE and Firefox is to go through popups
and look for a a unique text on the popup you are trying to interact with. Here is the method, let me know if it works for you. Please note the line driver = driver.switchTo().window(windowHandle);
public void switchWindow(String containingText, WebDriver driver) throws Exception {
if ( StringUtils.isEmpty(containingText))
return;
int counter = 1;
int numOfpopups = driver.getWindowHandles().size();
System.out.println("Waiting for popup to load..... # handles:" + numOfpopups);
while ( numOfpopups < 2 && ((counter%10) != 0) ) {
counter++;
try{Thread.sleep(1000);}catch (Exception e) {}
}
System.out.println("Done waiting for..... " + counter + " seconds");
if (driver.getWindowHandles().size() < 2)
throw new BrowserException("Timeout after " + counter + " secs. No popup present. ");
System.out.println("Going through window handles...");
for (String windowHandle : driver.getWindowHandles()) {
driver = driver.switchTo().window(windowHandle);
if ( driver.getPageSource().contains(containingText)
return;
else
continue;
}
throw new Exception("Window containing text '" + containingText + "' not found");
}
To my knowledge, webdriver has no built-in functionality to handle modal windows as of now. Webdriver will hang once you click button which opens modal window. This happens due to JS on parent window halts until child window is closed.
To handle modal windows such as this one, see below for possible workaround written in Java. The main idea is to perform action that opens modal window (click on the button) in new thread.
/**
* Click button to open modal window and switch to it
* #param we webElement handle of a button
*/
public void clickToOpenModal(final WebElement we) {
//Get handles of all opened windows before opening modal window
Set<String> initWindowHandles = getDriverInstance().getWindowHandles();
//Create new thread and click button to open window
Thread thread1 = new Thread() {
#Override
public void run() {
//Click button
click(we);
}
};
thread1.start();
//Wait for window to appear
waitForWindow(initWindowHandles, pauseL);
thread1.interrupt();
thread1 = null;
//Get handles of all opened windows after opening modal window
Iterator<String> it = getDriverInstance().getWindowHandles().iterator();
//Select handle of modal window
String windowHandle = "";
while(it.hasNext()){
windowHandle = it.next();
}
//Switch focus and work on the modal window
getDriverInstance().switchTo().window(windowHandle);
}
The solution by Hugh Foster works, i tried this and succeeded
((JavascriptExecutor) driver).executeScript("window.showModalDialog = window.open;");
You can find the url of modal dialog then open it on another tab, it will work as normal.
In case you want to deal with open modal dialog, you can try to send "tab" key for move around objects and "send keys... enter" for setText or click.
Note: Below is some information why you cannot use selenium webdriver for work with that modal.
Modal pop-up - This is very specific to IE, Microsoft defined it as
When Windows Internet Explorer opens a window from a modal or modeless HTML dialog box by using the showModalDialog method or by using the showModelessDialog method, Internet Explorer uses Component Object Model (COM) to create a new instance of the window. Typically, the window is opened by using the first instance of an existing Internet Explorer process. When Internet Explorer opens the window in a new process, all the memory cookies are no longer available, including the session ID. This process is different from the process that Internet Explorer uses to open a new window by using the open method.
http://msdn.microsoft.com/en-us/library/ms536759(VS.85).aspx
MSDN blog on Modal dialog
When user select Model popup, parent window is blocked waiting for the return value from the popup window. You will be not able to see the view source of the page, need to close the popup then only the parent window is activated.

Categories

Resources