getAllWindowNames() method of DefaultSelenium class not listing names of all tabbed windows? - selenium-rc

I am writing a sample program to automate the tabbed windows. Please have a look at my sample program:
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class TestTabWindows
{
public static void main(String[] args)
{
Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://naukri.com");
selenium.start();
selenium.open("/");
selenium.windowMaximize();
selenium.windowFocus();
String window_names[] = selenium.getAllWindowNames();
System.out.println("--------Window names before any tab window--------");
for(int i=0; i<window_names.length;i++)
{
System.out.println(window_names[i]);
}
selenium.type("//*[#id='qp']", "selenium");
selenium.click("//*[#id='search']");
selenium.waitForPageToLoad("20000");
selenium.click("//*[#id='1']/strong");
window_names = selenium.getAllWindowNames();
System.out.println("------Window names after tab window is opened--------");
for(int i=0; i<window_names.length;i++)
{
System.out.println(window_names[i]);
}
}
}
Now th problem is that the second for loop at the end of the program should print 2 window names in console - the main window & the tabbed window, but it prints only the main window.
I don't seem to find out why this is happening?
Please suggerst. Regards,

Related

Editors with many widgets have horrible performance

We switched to e4 target platform. One editor has became horrible slow with rendering (about 20 seconds to layout). When a modal dialog is opened from the editor-menu, the application flickers like having an epileptical fit.
When we turn off css, by ...
DefaultScope.INSTANCE.getNode("org.eclipse.e4.ui.workbench.renderers.swt")
.put("themeEnabled", "false");
in the plugin, the rendering is very fast (<10ms), like it used to be under the previous target platform.
this is the control that i have embedded into the editor (for evaluation reasons):
package xyz;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
public class BigControl extends Composite {
public BigControl(Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout(23, false));
for (int i=0; i<100; i++) {
for (int j=0; j<23; j++) {
new Label(this, SWT.NONE).setText("|" + Integer.toString(i) + " " + Integer.toString(j) + "|");;
}
}
}
}
has anybody experience with that problem? Yes, we know that a table would be better for such amount of data, but refactoring that would cost too much at the moment.
The second problem is, when we turn off the theme functionality, eclipse / swt brings up exceptions when switching perspectives, views and so on.
OK, we replaced the target platform by a newer one (2019-3). I was not aware about using an older platform.
The flickering stopped, it is still not fast (resizing the window takes about 2 seconds), but it is acceptable for the moment.
Thank you for your help,
Best, Martin
... to make things clear, I created a brand new application by the eclipse wizard (... having a view).
I replaced the sample views code by that - as I mentioned, when we turn off css/theming (see code above), everything is fine - otherwise it doesn't stop to shake, it is even hard to get the mouse pointer back to eclipse to stop the app:
package xyz;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.part.ViewPart;
public class View extends ViewPart {
public static final String ID = "xyz.view";
public class BigControl extends Composite {
public BigControl(Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout(23, false));
for (int i=0; i<100; i++) {
for (int j=0; j<23; j++) {
new Label(this, SWT.NONE).setText("|" + Integer.toString(i) + " " + Integer.toString(j) + "|");;
}
}
}
}
#Override
public void createPartControl(Composite parent) {
new BigControl(parent, SWT.NONE);
}
#Override
public void setFocus() {
}
}

Memory usage in IE for gwt application

For the last couple of days I've been trying to find out why my gwt application is leaking on IE 9.
I want to share one of my findings with you and maybe someone can give me a clue about what is going one here...
I wrote this small test:
public class Memory implements EntryPoint
{
FlowPanel mainPanel = new FlowPanel();
FlowPanel buttonsPanel = new FlowPanel();
FlowPanel contentPanel = new FlowPanel();
Timer timer;
Date startDate;
public void onModuleLoad()
{
mainPanel.setWidth("100%");
mainPanel.setHeight("100%");
RootPanel.get().add(mainPanel);
Button startBtn = new Button("start test");
startBtn.addClickHandler(new ClickHandler(){
#Override
public void onClick(ClickEvent event)
{
startDate = new Date();
System.out.println("Started at " + startDate);
timer = new Timer()
{
public void run()
{
Date now = new Date();
if(isWithin5Minutes(startDate, now))
{
manageContent();
}
else
{
System.out.println("Complete at " + new Date());
timer.cancel();
contentPanel.clear();
}
}
};
timer.scheduleRepeating(50);
}
});
buttonsPanel.add(startBtn);
mainPanel.add(buttonsPanel);
mainPanel.add(contentPanel);
}
private void manageContent()
{
if(contentPanel.getWidgetCount() > 0)
{
contentPanel.clear();
}
else
{
for(int i =0; i < 20; i++)
{
Image image = new Image();
image.setUrl("/images/test.png");
contentPanel.add(image);
}
}
}
private boolean isWithin5Minutes(Date start, Date now)
{
//true if 'now' is within 5 minutes of 'start' date
}
}
So, I have this Timer that runs every 50 ms (during around 5 minutes) and executes the following:
- if the panel has content, clear it;
- if the panel has no content add 20 png images (30x30 with transparency) to it.
Using the Process Explorer from sysInternals I got the following results:
IE 9:
Firefox 21.0:
I ran the same program with some changes (.jpg images instead of .png, create the images only once and use them as member variables, create the images using a ClientBundle) but the result was the same. Also, I ran the application in production mode.
Is there something wrong with my code that could cause this behavior in IE?
Shouldn't the Garbage Collector (GC) free some of the used memory at least when the timer ends?
Any of you came across this problem before?
Garbage collector in IE is quite strange thing. E.g. you can force it to run by simply minimizing browser window. I guess leaks in your case are images that weren't removed properly by browser when you clear container. Try to remove them by using JS "delete" operation, like that:
private native void utilizeElement(Element element) /*-{
delete element;
}-*/;
Then change your manageContent a little:
if(contentPanel.getWidgetCount() > 0)
{
for (Iterator<Widget> it = contentPanel.iterator(); it.hasNext();)
utilizeElement(it.next().getElement());
contentPanel.clear();
}
Hope this helps.

keyboard vs menu conflict on Java 7, Mac OS

How can I get a Java 7 application to have its menu bar at the top of the screen (on a Mac) and also have correctly working keyboard shortcuts?
I have a Java application with a Swing user interface. Many menus have keyboard equivalents, which are essential.
There is very little that is system-dependent, but on Mac OS X the menu bar should appear at the top of the screen instead of on each window, so I set apple.laf.useScreenMenuBar.
This works fine on Java 6, but on Java 7 (out last week!) compiling and running the same code causes the keyboard shortcuts to carry out their menu actions twice. For example, in the attached code, Command ⌘ + O opens two file dialogues instead of one. (The other keyboard shortcuts also act twice, but you sometimes have to move windows to see that they did.)
The keyboard problem goes away if I don't set apple.laf.useScreenMenuBar, and that's what I'll do if I have to, but my Mac users will be displeased. I'd really like to have the menu bar in the right place and the keyboard shortcuts working.
System: Mac OS 10.7.3 (Lion) on a late-2010 MacBook Pro
Java 7:
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
Java 6:
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04-415-11M3635)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01-415, mixed mode)
Where I've looked:
A discussion of why apple.laf.useScreenMenuBar should be gotten rid of
-- I'm all for it, but it doesn't seem to have happened.
A discussion about not using mrj.version to detect that you're on a Mac
-- not directly relevant, but sounded promising.
My apologies for the length of the attached code (148 lines), but my Swing coding is very old-fashioned. It should compile and run from the command line without any special flags or settings.
import javax.swing.*;
import java.awt.Toolkit;
import java.awt.*;
import java.awt.event.*;
/**
* Shows that using the single screen-top menu bar on a Mac with Java 7
* causes keyboard shortcuts to act twice.
*
* To see the problem(on a Mac -- running OS X 10.7.3 in my case):
* 1) compile on either Java 6 or Java 7
* 2) run on Java 7
* 3) give the command-O shortcut
* You will see two file dialogues.
*
* -- J. Clarke, May 2012
*/
public class MenuBug {
private static void go(String[] args) {
// Comment out the following line to fix the problem;
// leave it active to see the problem.
// It doesn't help to ...
// ... put the line into a static block.
// ... put the line right after the setLookAndFeel call.
// ... put the line before after the setLookAndFeel call.
System.setProperty("apple.laf.useScreenMenuBar", "true");
MainWindow mainWindow = new MainWindow();
}
public static void main(final String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
JOptionPane.showMessageDialog(null,
e + " while loading look and feel",
"MenuBug error", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
go(args);
}
});
}
}
class MainWindow extends JFrame {
MainWindow() {
super ("Main Window");
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
addWindowListener (new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
JMenuBar menuBar = createMenuBar();
setJMenuBar(menuBar);
pack();
setSize(350,300);
setVisible(true);
}
private JMenuBar createMenuBar() {
JMenuBar mBar = new JMenuBar();
JMenu menu = new JMenu("File");
String[] menuItemNames = new String[] {"New", "Open...", "Other"};
for (int i = 0; i < menuItemNames.length; i++) {
String miName = menuItemNames[i];
JMenuItem mi = new JMenuItem(miName);
mi.setActionCommand(miName);
linkMenuItemToAction(mi);
menu.add(mi);
}
mBar.add(menu);
return mBar;
}
/**
* Create an Action for menuItem, and make sure the action and the menu
* item know about each other; where appropriate, add keyboard equivalents.
* #param menuItem The menu item to be linked to an action.
*/
private void linkMenuItemToAction(JMenuItem menuItem) {
final int META_MASK =
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
Action a = null;
String miName = menuItem.getActionCommand();
if (miName.equals ("New")) {
a = new NewAction();
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
META_MASK));
}
else if (miName.equals ("Open...")) {
a = new OpenAction();
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
META_MASK));
}
else if (miName.equals ("Other")) {
a = new OtherAction();
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T,
META_MASK));
}
menuItem.setEnabled(a.isEnabled());
menuItem.addActionListener(a);
}
private class NewAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
new MainWindow();
}
}
private void makeDialog() {
String dialogTitle = "Please choose a file to open";
FileDialog fileDialog = new FileDialog(this, dialogTitle,
FileDialog.LOAD);
fileDialog.setVisible(true);
String fileName = fileDialog.getFile();
}
private class OpenAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
makeDialog();
}
}
private class OtherAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,
"an example message",
"not really an error", JOptionPane.ERROR_MESSAGE);
}
}
}
I'm answering my own question -- sort of. As noted in the comments to the original, the trouble goes away with Java 1.7u10.
It looks like that this problem still exist but now it can be reproduced with fn + backSpace (delete) on mac with 1.7_21.
I used the same example as above just added text field. Select part of text in textfield and press delete (fn+backspace)
Change KeyStroke to "DELETE" in linkMenuItemToAction method
else if (miName.equals ("Other"))
{
a = new OtherAction();
menuItem.setAccelerator(KeyStroke.getKeyStroke("DELETE"));
}
and add this:
JTextField textField = new JTextField(10);
textField.setText("Long long long long long long long text");
add(textField, BorderLayout.PAGE_START);
to MainWindow constructor.

How to read the contents of a screen from another application [Office Communicator]

Knowing the hwnd of the window, how do I read the contents of this? Before anyone ask me, I'm trying to get the text that was used in the Communicator window.
Below is the code I found on the Internet.
The code is not mine.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace EventFun
{
class EventHookUp
{
CommunicatorAPI.Messenger mCommunicator = null;
static void Main(string[] args)
{
EventHookUp hu = new EventHookUp();
hu.InitializeEventHocks();
Console.ReadKey();
}
public void InitializeEventHocks()
{
mCommunicator = new CommunicatorAPI.Messenger();
mCommunicator.OnIMWindowCreated += new CommunicatorAPI.DMessengerEvents_OnIMWindowCreatedEventHandler(mCommunicator_OnIMWindowCreated);
mCommunicator.OnIMWindowDestroyed += new CommunicatorAPI.DMessengerEvents_OnIMWindowDestroyedEventHandler(mCommunicator_OnIMWindowDestroyed);
}
void mCommunicator_OnIMWindowCreated(object pIMWindow)
{
CommunicatorAPI.IMessengerConversationWndAdvanced stpIMWindow = pIMWindow as CommunicatorAPI.IMessengerConversationWndAdvanced;
//stpIMWindow.History;
long Hwnd = (long)stpIMWindow.HWND;
Console.WriteLine("New IM Window Created : {0}", Hwnd);
CommunicatorAPI.IMessengerContacts contactList = (CommunicatorAPI.IMessengerContacts)stpIMWindow.Contacts;
StringBuilder sb = new StringBuilder();
foreach (CommunicatorAPI.IMessengerContact imc in contactList)
{
sb.Append(imc.FriendlyName);
sb.Append(Environment.NewLine);
}
Console.WriteLine(sb.ToString());
}
void mCommunicator_OnIMWindowDestroyed(object pIMWindow)
{
Console.WriteLine("IM Window Destroyed.");
}
}
}
It sounds like you are trying to get the conversation text history from the conversation window? If so, George Durzi has an excellent blog post on this.
As this blog post is not available, I used below method to retrieve the conversation history:
object obj = msgrAdv.StartConversation(
CONVERSATION_TYPE.CONVERSATION_TYPE_IM, // Type of conversation
sipUris, // object array of signin names for having multiple conversations or just a string
null,
"Test",
"1",
null);
imWindowHandle = long.Parse(obj.ToString());
if (imWindow == null) //If there is already an open window...
{
imWindow = (IMessengerConversationWndAdvanced)msgrAdv.InstantMessage(sipUris);
}
//else there was no open window, we have opened the window using "msgrAdv.StartConversation" so there is a imWindow associated which is implemented in communicator_OnIMWindowCreated.
//and then...
string history = imWindow.History;

Add a notification icon at the status bar in BlackBerry JDE 4.5.0

I'm writing a Java application in BlackBerry JDE 4.5 that will start listening for some event at the start up. I want to display a small icon at the status bar.
I know its support in version 4.6.0 of the BlackBerry API set with ApplicationIcon, ApplicationIndicator and ApplicationIndicatorRegistry classes but which classes are there in BlackBerry JDE 4.5.0 API set?
Update
I think some support is there for 4.5.0 as I'm using Blackberry Pearl 8100 with OS v4.5.0.81 which displays Notification Icons at status bar for any incoming messages or calls.
I made the Alternale Entry point & Main CLDC app like this article below,
How To - Setup an alternate entry point for my application
I have got an article as,
How to - Make a running UI application go to the background and resume in the foreground
in which its said that
The alternate entry is going to call the main method with the parameter that is passed in, regardless of whether the application is running.
But in my case the main() is not getting called when I click on appIcon when the app is running in background.
It only updates appIcon & appName which is previously set in Alternate Entry Point.
So I m not getting where the control goes if its not calling main() when clicked on updatedIcon?
Is anyone has any idea on this issue?
I updated the appIcon & appName.
Now what I want is "When clicked on updatedIcon a particular screen should be opened & when the user goes back to Main Menu the app should get its original Icon, app name & the flow should go through main() when clicked on original app Icon"
I was thinking when I click on updated appIcon the control will go to main() but instead of calling main() it says,
Starting AppName
AppName already running
& directly it goes to first screen. and when I come back to Main Menu the app has updated icon & name
So how to get it?
Unfortunately it's not possible. What you can do is update application icon.
Also there are alternative ways of notification:
Notification Service for Blackberry OS 4.5 application
Update Application Icon
alt text http://img211.imageshack.us/img211/4527/icoupdate1.jpgalt text http://img697.imageshack.us/img697/3981/icon.jpgalt text http://img687.imageshack.us/img687/256/iconactive.jpgalt text http://img130.imageshack.us/img130/3277/icoupdate2.jpgalt text http://img691.imageshack.us/img691/6459/icoupdate3.jpg
Background running application:
public class NotifIconSrvc extends Application {
private int mCount = 0;
private int mSize = 0;
public NotifIconSrvc() {
Timer timer = new Timer();
timer.schedule(sendEventTask, 1000, 3000);
}
TimerTask sendEventTask = new TimerTask() {
public void run() {
// Post the GlobalEvent.
// Long = ci.samples.45.notificon
ApplicationManager.getApplicationManager().postGlobalEvent(
0x5a9f7caa171ab7b8L, mCount++, mSize++);
}
};
public static void main(String[] args) {
NotifIconSrvc app = new NotifIconSrvc();
app.enterEventDispatcher();
}
}
Main application:
public class NotifIconApp extends UiApplication
implements GlobalEventListener {
private Bitmap mIcon = Bitmap.getBitmapResource("icon.png");
private Bitmap mIconActive =
Bitmap.getBitmapResource("icon_active.png");
private Scr mScreen = new Scr();
public NotifIconApp() {
addGlobalEventListener(this);
pushScreen(mScreen);
}
public static void main(String[] args) {
NotifIconApp app = new NotifIconApp();
app.enterEventDispatcher();
}
public void eventOccurred(long guid, int count, int size,
Object object0, Object object1) {
if (0x5a9f7caa171ab7b8L == guid) {
Bitmap icon = getUpdateIconBitmap(mIcon, count, size);
HomeScreen.updateIcon(icon);
Bitmap rolloverIcon =
getUpdateIconBitmap(mIconActive, count, size);
HomeScreen.setRolloverIcon(rolloverIcon);
mScreen.updateScreen(count, size);
}
}
private Bitmap getUpdateIconBitmap(Bitmap bmp, int count, int size) {
int width = bmp.getWidth();
int height = bmp.getHeight();
Bitmap iconBmp = new Bitmap(width, height);
Graphics g = new Graphics(iconBmp);
XYRect rect = new XYRect(0, 0, width, height);
g.drawBitmap(rect, bmp, 0, 0);
g.setFont(g.getFont().derive(Font.BOLD, 20, Ui.UNITS_px,
Font.ANTIALIAS_STANDARD, Font.COLORED_OUTLINE_EFFECT));
String text = Integer.toString(count);
g.setColor(Color.BLACK);
g.drawText(text, 0, 2);
text = Integer.toString(size) + " Kb";
g.setColor(Color.GREEN);
g.drawText(text, 0, height - 22);
return iconBmp;
}
}
class Scr extends MainScreen {
LabelField mMessages;
String mLabelText = "message count: ";
String mTitleText = "message counter";
public Scr() {
add(mMessages = new LabelField(mLabelText));
setTitle(mTitleText);
}
void updateScreen(int count, int size) {
StringBuffer sb = new StringBuffer(Integer.toString(count));
sb.append("/");
sb.append(Integer.toString(size));
sb.append("Kb");
String text = sb.toString();
setTitle(mTitleText + "(" + text + ")");
mMessages.setText(mLabelText + text);
}
protected void makeMenu(Menu menu, int instance) {
super.makeMenu(menu, instance);
menu.add(mMenuGoBG);
}
MenuItem mMenuGoBG = new MenuItem("go background", 0, 0) {
public void run() {
UiApplication.getUiApplication().requestBackground();
}
};
}

Resources