Thursday, February 17, 2011

Help getting QTP to identify a control

We're trying to use QTP (QuickTest Professional) to auto-test a legacy C++ application.

However, the main window for the app is composed of several IDENTICAL panels. Each panel has a unique title.

If I view the window in Spy++ (comes with DevStudio), I see:

+ Window <hwnd> "Window Title" taskwindowclass
  + Window <hwnd> "Panel A" childwindowclass
    + Window <hwnd> "OK" Button
  + Window <hwnd> "Panel B" childwindowclass
    + Window <hwnd> "OK" Button

In QTP's Object Spy however, the hierarchy shows as:

+ Window: Window Title
  + WinButton: OK

It doesn't even show that there is an intermediate panel.

Does anybody know a way to get the window "path" in order to identify each control? i.e. so the controls identify as:

Button A: "Window Title/Panel A/OK"
Button B: "Window Title/Panel B/OK"
From stackoverflow
  • You could use descriptive programming to bypass the object map. QTP will ignore panel objects by default. You could try to get a reference to the panel object dynamically, then search the ChildObjects collection to find the ok button. Another option might be to simply add an ordinal identifier to the ok buttons.

    • Button A: "Window Title/OK index #1"
    • Button B: "Window Title/OK index #2"

How can I run Test projects with Visual Studio 2008 Standard Edition?

I'm currently running Visual Studio 2008 Standard Edition and one of the items they cut out for that edition is the unit testing capability. As a result, when I open up example projects like the MVC commerce test, one of the projects just won't load since it doesn't know to open that type of project.

I know I can just exclude or remove the project and I am aware of TestDriven.NET, but is there a plugin for VS2008 Standard which will do the unit tests that come with VS2008 Pro? Will TestDriven.NET do this or are the tests different enough from NUnit testing that this won't work?

UPDATE: To clarify, I'm curious if there are any programs or plugins out there that can run Test projects within Visual Studio 2008. TestDriven.NET cannot load or run or allow VS2008 to open Test projects and Gallio does not run within the VS2008 IDE (although I appreciate the suggestions greatly)

From stackoverflow
  • TestDriven.NET can run NUnit, xUnit.NET and MSTest. It's not free, though, but well worth it. From http://www.testdriven.net/overview.aspx:

    Supports multiple unit testing frameworks including NUnit, MbUnit and MS Team System.

    Schnapple : Was TestDriven.NET ever free? Or did I imagine that?
  • Try Gallio as explained best in this blog post by Richard Dingwall, and for Visual Studio support, use TestDriven.Net to runs it.

    There's some information available in this Google Groups post as well.


    From Gallio's website:

    At present Gallio can run tests from MbUnit versions 2 and 3, MSTest, NBehave, NUnit, xUnit.Net, and csUnit. Gallio provides tool support and integration with CCNet, MSBuild, NAnt, NCover, Pex, Powershell, Resharper, TestDriven.Net, TypeMock, and Visual Studio Team System.

Finding Unique Table/Column Combinations Across SQL Databases

I have 4 databases with similar schema's, and I'm trying to create a query to return just the table, column pairs that exist ONLY in database 1 and do not exist in database 2, 3, or 4.

Currently I can return the symmetric difference between database 1 and 2 via the following query...

select table_name, column_name from (
     select table_name, column_name from [Database1].information_schema.columns
     union all
     select table_name, column_name from [Database2].information_schema.columns) as tmp
     group by table_name, column_name having count(*) = 1

However, in trying to isolate just those columns in database 1, and doing the same across all 4 databases, things are getting complicated. What is the cleanest solution for this query?

From stackoverflow
  • SELECT
         D1.table_name,
         D1.column_name
    FROM
         Database1.information_schema.columns D1
    LEFT OUTER JOIN Database2.information_schema.columns D2 ON
         D2.table_name = D1.table_name AND
         D2.column_name = D1.column_name
    LEFT OUTER JOIN Database3.information_schema.columns D3 ON
         D3.table_name = D1.table_name AND
         D3.column_name = D1.column_name
    LEFT OUTER JOIN Database4.information_schema.columns D4 ON
         D4.table_name = D1.table_name AND
         D4.column_name = D1.column_name
    WHERE
         D2.table_name IS NULL AND
         D3.table_name IS NULL AND
         D4.table_name IS NULL
    
    Blorgbeard : you have a trailing AND
    Tom H. : Thanks. I need to work on my copy-paste skills :)
  • I can come up with this at first shot, which can be a head start. This hasn't been tested though, just another alternative maybe:

    select table_name, column_name from [Database1].information_schema.columns d1 where table_name || '+' || column_name not in (select table_name || '+' || column_name from [Database2].information_schema.columns)

    and table_name || '+' || column_name not in (select table_name || '+' || column_name from [Database3].information_schema.columns)

    and table_name || '+' || column_name not in (select table_name || '+' || column_name from [Database4].information_schema.columns)

Is it considered bad design to do lengthy operations in a constructor?

I am implementing a class to compare directory trees (in C#). At first I implemented the actual comparison in the class's constructor. Like this:

DirectoryComparer c = new DirectoryComparer("C:\\Dir1", "C:\\Dir2");

But it doesn't feel "right" to do a possible lengthy operation in the constructor. An alternative way is to make the constructor private and add a static method like this:

DirectoryComparer c = DirectoryComparer.Compare("C:\\Dir1", "C:\\Dir2");

What do you think? Do you expect a constructor to be "quick"? Is the second example better or is it just complicating the usage of the class?

BTW:

I wont mark any answer as accepted because I don't think there is a correct answer, just preference and taste.

Edit:

Just to clarify my example a little. I'm not only insterested if the directories differs, I'm also interested in how they differ (which files). So a simple int return value wont be enough. The answer by cdragon76.myopenid.com actually is pretty close to what I want (+1 to you).

From stackoverflow
  • I prefer the second one.

    I expect the constructor to instanciate the class. The method compare does what it is designed to do.

  • You should never do anything that might fail in a constructor. You don't want to ever create invalid objects. While you could implement a "zombie" state where the object doesn't do much, it's much better to perform any complex logic in seperate methods.

    Jon Skeet : It's perfectly okay for a constructor to fail, and throw an exception. There are plenty of examples of this in the framework. It should make sure that it doesn't leak a reference to itself during the constructor, but apart from that it's fine. Not that I like complex constructors, mind you.
    James : I don't think that just because it is in the framework it is OK. The framework is great, but it isn't flawless. It's great advice to say that you should never do things that may fail in a constructor. But yes, constructors should be allowed to throw exceptions in the case of invalid data, IMHO.
  • Yes, typically a constructor is something quick, it is designed to prepare the object for use, not to actually do operations. I like your second option as it keeps it a one line operation.

    You could also make it a bit easier by allowing the constructor to pass the two paths, then have a Compare() method that actually does the processing.

  • I think an interface might be what you're after. I would create a class to represent a directory, and have that implement the DirectoryComparer interface. That interface would include the compare method. If C# already has a Comparable interface, you could also just implement that.

    In code, your call would be:

    D1 = new Directory("C:\");
    ..
    D1.compare(D2);
    
  • I like the second example because it explains what is exactly happening when you instantiate the object. Plus, I always use the constructor to initialize all of the global settings fro the class.

  • I would think a combination of the two is the "right" choice, as I would expect the Compare method to return the comparison result, not the comparer itself.

    DirectoryComparer c = new DirectoryComparer();
    
    int equality = c.Compare("C:\\Dir1", "C:\\Dir2");
    

    ...and as Dana mentions, there is an IComparer interface in .Net that reflects this pattern.

    The IComparer.Compare method returns an int since the use of IComparer classes is primarily with sorting. The general pattern though fits the problem of the question in that:

    1. Constructor initializes an instance with (optionally) "configuring" parameters
    2. Compare method takes two "data" parameters, compares them and returns a "result"

    Now, the result can be an int, a bool, a collection of diffs. Whatever fits the need.

  • I think for a general purpose comparer you may on construction only want to specify the files you are comparing and then compare later- this way you can also implement extended logic:

    • Compare again- what if the directories changed?
    • Change the files you are comparing by updating the members.

    Also, you may want to consider in your implementation receiving messages from your OS when files have been changed in the target directories- and optionally recomparing again.

    The point is- you are imposing limits by assuming that this class will only be used to compare once for a single instance of those files.

    Therefore, I prefer:

    DirectoryComparer = new DirectoryComparer(&Dir1,&Dir2);

    DirectoryComparer->Compare();

    Or

    DirectoryComparer = new DirectoryComparer();

    DirectoryComparer->Compare(&Dir1,&Dir2);

    Don Kirkby : I agree, and you can still have a single line by saying new DirectoryComparer(a, b).Compare()
    tloach : @Don: A former coworker called that "trying to do too many sexy things on one line". If the new fails for any reason you've just caused an exception that can be hard to track down.
  • If you are working with C#, you could use extension methods to create a method for comparing 2 directories that you would attach to the build in DirectoryClass, so it would look some thing like:

    Directory dir1 = new Directory("C:\.....");
    Directory dir2 = new Directory("D:\.....");
    
    DirectoryCompare c = dir1.CompareTo(dir2);
    

    This would be much clearer implementation. More on extension methods here.

  • If an operation may take an unknown amount of time, it is an operation you might want to export into a different thread (so your main thread won't block and can do other things, like showing a spinning progress indicator for example). Other apps may not want to do this, they may want everything within a single thread (e.g. those that have no UI). Moving object creation to a separate thread is a bit awkward IMHO. I'd prefer to create the object (quickly) in my current thread and then just let a method of it run within another thread and once the method finished running, the other thread can die and I can grab the result of this method in my current thread by using another method of the object before dumping the object, since I'm happy as soon as I know the result (or keeping a copy if the result involves more details I may have to consume one at a time).

  • I agree with the general sentiment of not doing lengthy operations inside constructors.

    Additionally, while on the subject of design, I'd consider changing your 2nd example so that the DirectoryComparer.Compare method returns something other than a DirectoryComparer object. (Perhaps a new class called DirectoryDifferences or DirectoryComparisonResult.) An object of type DirectoryComparer sounds like an object you would use to compare directories as opposed to an object that represents the differences between a pair of directories.

    Then if you want to define different ways of comparing directories (such as ignoring timestamps, readonly attributes, empty directories, etc.) you could make those parameters you pass to the DirectoryComparer class constructor. Or, if you always want DirectoryComparer to have the exact same rules for comparing directories, you could simply make DirectoryComparer a static class.

    For example:

    DirectoryComparer comparer = new DirectoryComparer(
        DirectoryComparerOptions.IgnoreDirectoryAttributes
    );
    DirectoryComparerResult result = comparer.Compare("C:\\Dir1", "C:\\Dir2");
    
  • If the arguments are just going to be processed once then I don't think they belong as either constructor arguments or instance state.

    If however the comparison service is going to support some kind of suspendable algorithm or you want to notify listeners when the equality state of two directories changes based on filesystem events or something like that. Then ther directories is part of the instance state.

    In neither case is the constructor doing any work other than initializing an instance. In case two above the algorithm is either driven by a client, just like an Iterator for example, or it's driven by the event listening thread.

    I generally try to do things like this: Don't hold state in the instance if it can be passed as arguments to service methods. Try to design the object with immutable state. Defining attributes, like those used in equals and hashcode should allways be immutable.

    Conceptualy a constructor is a function mapping an object representation to the object it represents.

    By the definition above Integer.valueOf(1) is actually more of a constructor than new Integer(1) because Integer.valueOf(1) == Integer.valueOf(1). , In either case this concept also means that all the cosntructor arguments, and only the constructor argument, should define the equals behavior of an object.

  • I would definitely do the second.

    Long actions in a constructor are fine if they are actually building the object so it is usable.

    Now one thing that I see people do in constructors is call virtual methods. This is BAD since once someone uses you as a base class and overrides one of those functions you will call the base class's version not the derived class once you get into your constructor.

  • I don't think that talking about abstract terms like "lengthy" have anything to do with the decision if you put something in an constructor or not.

    A constructor is something that should be used to initialize an object, a method should be used to "do something", i.e. have a function.

  • I think it's not only okay for a constructor to take as much time as needed to construct a valid object, but the constructor is required to do so. Deferring object creation is very bad as you end up with potentially invalid objects. So, you will have to check an object everytime before you touch it (this is how it is done in the MFC, you have bool IsValid() methods everywhere).

    I only see a slight difference in the two ways of creating the object. One can see the new operator as a static function of the class anyway. So, this all boils down to syntactic sugar.

    What does the DirectoryComparer class do? What is it's responsibility? From my point of view (which is a C++ programmer's view) it looks like you'd be better off with just using a free function, but I don't think that you can have free functions in C#, can you? I guess you will collect the files which are different in the DirectoryComparer object. If so, you could better create something like an array of files or an equivalent class that's named accordingly.

Sql Server Management - Option to avoid scripting the collation?

I have databases with different collations. I want to be able to script out tables from one database and create them in another. However, when I script out the tables, it includes the collation in the column definitions.

Is there a way to exclude the collations from the generated table creation scripts?

From stackoverflow
  • Tools -> Options

    Under Scripting (in the Table/View section)

    Set Include Collation to False!

    Jim : Hmm. I don't see those options in Tools -> Options.
    Mitchel Sellers : You have to have the most current version of SSMS from what I can tell, older builds of the tool don't seem to have the options.
  • Pretty lame - but do a search and replace on the script after it has been generated??

  • Which version of SSMS are you using? The full edition, or Express edition?

    You'll need to apply at least SP2 for 2005 to get the scripting settongs under Tools->Options.

    This doesn't need to be applied to the database servers, it can be applied to just the client tools on your admin workstation if required.

How can I switch on Intellisense and code hints in C++ Builder 2009?

I've just installed CodeGear Studio 2009 and I didn`t find where I can put the Intellisense and code hints on.

And, by the way, in Visual Studio we can indent selected blocks of code in the same way. How can I use similar functions in CodeGear?

Any ideas about that?

From stackoverflow
  • It's called Code Insight. I don't have 2009 yet but it's probably in the same place as 2007. Have a look in Tools > Options > Editor Options > Code Insight.

    By the way, it's no where near as good as Intellisense in VS.

  • The generic name is called "code completing", intellisense and insight are just catching marketing spun names companies use.

  • even after I`ve relaunched it with all points of CodeInsight turned on I found out that there was no result((

Deleting from a database map

I have these 3 tables + data:

items: itemId, itemName
data: 1, my item one

categories: catId, catName
data: 1, my cat one. 2, my cat two

map: mapId, itemId, catId

When you include item "my item one" in category "my cat one", you insert [1, 1, 1] into the map. When you add "my item one" to "my cat two", you insert [2, 1, 2] into the map. Now let's say we change our mind and only want the item in "my cat two". This means we need to know what categories the item is no longer in and delete the associations from the map. What's the most efficient sequence of steps to take to do so? (I'm looking for a solution that will scale beyond this trivial example.)

From stackoverflow
  • Assuming you've already got the category ID for "my cat two" and the item ID for "my item 1":

    DELETE FROM MAP WHERE ItemID = @MyItem1Id
                    AND CatID <> @MyCat2Id
    

    If you have a set of categories you want to keep the item in, you could either:

    1. Delete everything from the map for that item and then re-add the set
    2. Use a query like the above but with "AND CatID NOT IN [ ... ]"
  • If you decide that an item should only be in the new category, the following should work:

    DELETE
         M
    FROM
         Map M
    WHERE
         M.itemid = @item_id AND
         M.catid <> @new_cat_id
    
  • It's not very clear what you mean by "scale beyond this trivial example".

    Sorry for the confusion. I mean with the same tables but with far more data.

    Tom H. : As long as you don't have hundreds of millions of rows and have normal indexes the amount of data shouldn't be an issue.