Can I do tooled refactoring for UFT script code, especially when changing function signatures? - refactoring

As an enthusiasting refactorer, there's an IntelliJ feature that I love: "Refactor --> Change signature".
Basically, you have a function and you can decide to remove a parameter or add a new one, setting a default value. This is so convenient, so beautiful, and I dearly love it.
So when I got involved in an oldschool UFT project with maintenance tasks, I felt jaded.
It there a way to achieve this without changing each and every instance of the function? Please tell me yes. Please!

Well, no. I don´t know of any tool capable of this.
There seem to be people who created a C# adapter for the UFT test object API, enabling them to write their tests in C#, and to use VisualStudio for development of test scripts. In VS, you have the refactoring support you look for. But you don´t create UFT scripts anymore, you´d create C# apps. (Note I am not talking about the API testing aspect of UFT, which uses C# anyways -- I am talking about the VBScript test scripts for GUI tests and BPT components.)
UFT itself is not capable of doing real static code analysis. (Let this statement drown a minute, and you´ll agree: it´s true.)
Adding this to the fact that the UFT´s IDE is, let´s say: sub-optimal, this led to the development of Test Design Studio (TDS), a VisualStudio "feel-alike" subset of VS for UFT (VBScript) scripts. You can check it out here: http://www.patterson-consulting.net/products/test_design_studio/Default.aspx
Among other things, TDS does static code analysis for UFT scripts in a pretty complete way (as far as an interpreted variant-typed language like VBScript allows that at all), and the author of the tool seems to be thinking about adding refactoring features like the one you asked for, but -- this has not happened yet. It will probably come only if demand is high.
Until then, TDS could help you:
You could simply change the signature
If TDS knows all calls (which is usually does), it will list you all locations where you need to edit -- and this happens at design-time, not at runtime
TDS allows you to specify the type of identifiers, for example: formal parameters, variables, and so on. This means you might even get warnings if you change nothing about the pure VBScript signature (which does not include type information), but do change the TDS directive of that signature parameter of which you changed the type.
This is no advertisement. I am not part of the company that developed TDS.
This is just an honest answer to the (slightly offtopic) question that I wish would have gotten years ago, asking questions like yours, and it proved to be a real lifesaver.
In summary, TDS quadrupled (or more) my productivity when creating and maintaining test scripts, especially if a large base framework is used. So I´d recommend checking out the option of using TDS to better handle changes like the ones you outlined.

Related

How to configure PythonAnalyzer to look for standard library typings?

I am creating a PythonAnalyzer using the following code:
var interpreterFactory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(
PythonLanguageVersion.V36.ToVersion());
var analyzer = PythonAnalyzer.Create(interpreterFactory);
Later on I also create and analyze a simple python module, that looks like this:
name = input('What is your name?\n')
print('Hi, %s.' % name)
Then I do module.Analysis.GetValuesByIndex("name", 4).
At this moment I expected the "value" to be 'str', because that's what Visual Studio shows when I open the same file in it. However, I get 'object' instead. So it seems that the PythonAnalyzer when constructed as mentioned above lacks some important information about where to look for standard library and/or its types.
Unfortunately, the documentation on PythonAnalyzer is lacking, so I was hoping the community could help understand how to configure it properly.
Congratulations on getting so far :)
What you're hitting here is the fact that CreateAnalysisInterpreterFactory is really intended for "pure" cases, where you have access to all the code that you're trying to analyze and nothing needs to be looked up. It is mostly used for the unit tests, or as a fallback when no copies of Python are installed. Depending on precisely which version of PTVS you are using, the bare information you're getting is either coming from DefaultDB\v3\python.pyi or CompletionDB\__builtin__.idb, both of which are somewhat lacking (by design).
Assuming you have a copy of Python installed, I would suggest creating an instance of InterpreterConfiguration with all of its details, and passing that to CreateInterpreterFactory (without "Analysis").
If you're on the latest sources (strongly recommended), this may run the interpreter in the background to collect information from it (you can control caching of this info with the DatabasePath and UseExistingCache members of InterpreterFactoryCreationOptions). If you are using the older version still, you'll need to trigger a completion DB regeneration or have one that you've created through VS.
And a final caveat: this part of PTVS is currently under some pretty heavy development at time of writing, so you'll either want to keep updating the version you're working against or stick with a slightly older one. Also feel free to post questions like this on the GitHub site, as while this is technically public API, it's barely documented at all and so the best help will come from the dev team.

Watin and Telerik Controls

I would like to ask if anybody knows an easy way to test Telerik controls with Watin.
We are about to start using it but before we do I wanted to see if there is anything I would need to know.
The problem that I can see we will be having is that if even smallest thing changes then all our tests will also break.
Any suggestion is greatly appreciated.
The problem that I can see we will be having is that if even smallest thing changes then all our tests will also break.
This could/will be true of all portions of your pages, including Telerik controls, depending on your test structure. Ideally, your elements will have IDs assigned and you'll use Page classes and custom control objects to remove all HTML references from your actual test code. Then if something changes on the webpage (or in a control), you verify the change is expected, then you change the WatiN page code (or control code) and re-run your tests.
The WatiN page class primer is here: http://watinandmore.blogspot.com/2009/06/introducing-page-class.html
Basically, you want to have your test code look like myPage.PickDate("3/29/2012") and not like ie.Tables[3].TableRows[2].TableCells[4].Textbox(Find.ByClass("datePicker")).TypeText("3/29/2012")
Changes can, do and should result in failing tests, however, I can attest that with a good page (or control) class setup that abstract away the HTML DOM and other specifics leaving non-HTML-filled test code, means that when changes do happen they are most often easy to get working again.
Note: Selenium also has a Page class concept, but I have not used it very much as of right now. Bottom line: If you write a lot of tests that reference the HTML DOM directly in test code, you're setting yourself up for a maintenance headache regardless of if you go with WatiN or Selenium or whatever.
Added: As to your original question: Can you work with Telerik controls in WatiN? Yes you can most likely, but depending on the control you may need to get a bit creative, possibly even calling javascript methods from within your test (page object ;) ). I've been stumped by a couple controls (non-Telerik) but most I've eventually figured out.
I realize you asked about WatiN, and I know I'll probably get downvoted into oblivion, but I might recommend Selenium instead. It seems to be more widely used and when we were evaluating the two we found Selenium easier to work with because of the Firefox plugin to record/generate the tests. This meant that our non-technical folks could set up the tests.
Since then we've successfully used Selenium to test ASP.NET sites that utilize Telerik controls. I only ran into one issue, with the RadNumericTextBoxes, which I've documented a fix for here: http://www.msigman.com/2012/02/entering-radnumerictextbox-selenium-webdriver-1-6-0/.
I'm currently in the process of writing a how-to guide for doing it: http://www.msigman.com/2012/03/automated-testing-asp-net-web-application/ (shameless plug).
You should also consider evaluating Telerik's Test Studio, our functional automation test tool. (Disclosure: I'm their evangelist for Test Studio.)
Test Studio really shines when you're working with Telerik controls. You'll get some great additional functionality around being able to dive deeper in to verifications and actions around the controls.
Even more importantly, Test Studio handles centralizing locators and pages by default, so you don't need any additional effort to best manage your UI changes.

Extending Visual Studio's "Code Snippet" functionality

When I write a test method, I type "testm", hit tab and magically see:
[TestMethod]
public void MethodName()
{
}
When I type the methodName it is highlighted (can't show that here) as a "field" that I'm filling in. I'm sure you're all familiar with this behavior.
Personally, I like names for my test methods like
Can_My_Method_Do_That_Thing instead of CanMyMethodDoThatThing. I find them much easier to read, and most times they're really a sentence anyway.
For reasons I'd rather not get into, I have a difficult time typing all those _ characters and I'd like to be able to use the space bar, and have the spaces in the name automatically replaced when I hit "Enter".
I hear that Visual Studio is extendable and customizable and so on. Is it extensible enough to do this?
You can implement and use your own code snippets and Microsoft provides a very nice guide on how this could be done: Walkthrough: Implementing Code Snippets
To have a quick look at how the "testm" Expansion (that's the Snippet Type) is "partially" implemented you may go to c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Test\ directory and edit the testmethod.snippet file.
I have never implemented this kind of "Expansion" myself, but Microsoft's Extending the Editor website is a really good source of info of how this can be achieved. This is where you should start lookin'.
If you install CodeRush Xpress then not only do you get some great free productivity and refactoring tools but there is also an open source community of plugins for CodeRush Xpress.
I found this plugin that does (almost) exactly what you want.
The caveat is that it is developed for NUnit and not MSTest so you will get a [Test] attribute instead of a [TestMethod] attribute. Since this is open source, it should be fairly easy to modify the code to your requirements.
The best method i would suggest is look into the Editor extensibility and work it out. Following steps is what you might need to do.
Map a key to your "underscorize" action.
Using the editor extensibility points, you can get access to the Selected text, process it.
And finally replace it.
One suggestion. Though the learning curve might be a bit high with having to go through MEF and stuff like that. But its worth it.
Another approach worth considering would be to use an external tool to remap the keyboard. For example, it should be straightforward to get AutoHotKey to react to the testm[Tab] sequence of keystrokes and switch into a mode where it maps spaces to underscores (or deletes each space as soon as it's typed and adds an underscore). Similarly, the Enter key could switch it out of that mode again.

Visual studio 2010 colourizers, intellisense and the rest. Where to start!

Ok, before I begin I realize that there is a lot of documentation on this subject but I have thus far failed to get even basic colourization working for VS2010.
My goal is to simply get to a point where I can open a document and everything is coloured red, from here I can implement the relevant parsing logic.
Here's what I have tried/found:
1) Downloaded all the relevent SDK's and such- Found the ook sample (http://code.msdn.microsoft.com/ookLanguage) - didn't build, didn't work.
2) Knowing almost nothing about MEF read through "Implementing a Language Service By Using the Managed Package Framework" - http://msdn.microsoft.com/en-us/library/bb166533(v=VS.100).aspx
This was pretty much a copy and paste of all the basic stuff here, and also updating some references which were out of date with the sample see: http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/a310fe67-afd2-4592-b295-3fc86fec7996
Now, I have got to a point where when running the package MEF appears to have hooked up correctly (I know this because with the debugger open I can see that the packages initialize and FDoIdle methods are being hit).
When I open a file of the extension I have registered with the ProvideLanguageExtensionAttribute everything dies as if in an endless loop, yet no debug symbols hit (though they are loaded).
Looking at the ook sample and the MEF examples they seem to be totally different approaches to the same problem. In the ook sample there are notions of Clasifications and Completion controllers which aren't mentioned in the MEF example. Also, they don't seem to create a Package or Language service, so I have no idea how it should work?
With the MEF example, my assumption is that I need to hook into the "IScanner.ScanTokenAndProvideInfoAboutIt" to provide syntax highlighting? Which would be fine if I could ever hit this method.
So my first question I guess is which approach should I be taking here? Or do they both somehow tie together?
My second questions is, where can I find a basic fully working project that implements bog standard basic syntax highlighting and intellisense or VS2010?
Thirdly, in the MEF example when I created a Package there were a bunch of test projects created for me. I appears that the integration tests launch the VS2010 test rig somehow, but the test fails. It would be good to write my service with tests but I have no idea what/how I can test each interaction so any references to testing Language services would be helpful.
Finally, please throw any resource/book links my way that I may find useful.
Cheers, Chris.
N.B. Sorry I realize this is part question part rant, but I have never been so confused.
First, the package example is not using MEF. Essentially everyplace that you mention MEF in your question is not actually MEF, but the managed package framework (MPF), also colloquially called the managed language service (MLS). You'd know if your extension was using MEF by two things: the vsixmanifest lists your assembly as containing a MEF component, and you see [Export] and [Import] attributes in the code.
The easiest way to do this is to use MEF. Since you have the SDK installed, you also have a template for an editor classifier project (under C# (or VB)->Extensibility->Editor classifier in the New Project dialog). You can certainly do this with a language service/colorizer/package, but there will be significantly more code than the equivalent classifier.
The Ook solution is the sample for this and should work; if it doesn't build/work, then can you send me email (noahric at microsoft) with what errors you are seeing so I can email the owner of that sample?
In general, you should also read my answer for the question on "How can I write a plugin for VS2010 using MEF?". That has links to other resources that should help.

Is it really worth purchasing R# for VS2010?

I heard that R#5.0 (still in beta) will support VS 2010. My question is
VS2010 == VS2008 + ReSharper ?
I know there are many improvements to VS2010, so I 'm not sure weather is it really worth purchasing the R#5.0 for VS2010?
Well, I haven't explored VS 2010 new refactoring features that much, but its my understanding that VS has some but definitely not all of resharpers features implemented (From MSDN):
Navigate To
You can use the Navigate
To feature to search for a symbol or
file in the source code.
Navigate To lets you find a specific
location in the solution or explore
elements in the solution. It helps you
pick a good set of matching results
from a query.
You can search for keywords that are
contained in a symbol by using Camel
casing and underscore characters to
divide the symbol into keywords.
For more information, see How to:
Search for Objects, Definitions, and
References (Symbols).
Generate From Usage
The Generate From
Usage feature lets you use classes and
members before you define them. You
can generate a stub for any undefined
class, constructor, method, property,
field, or enum that you want to use
but have not yet defined. You can
generate new types and members without
leaving your current location in code,
This minimizes interruption to your
workflow.
Generate From Usage supports
programming styles such as test-first
development.
IntelliSense Suggestion Mode
IntelliSense now provides two
alternatives for IntelliSense
statement completion, completion mode
and suggestion mode. Use suggestion
mode for situations where classes and
members are used before they are
defined.
In suggestion mode, when you type in
the editor and then commit the entry,
the text you typed is inserted into
the code. When you commit an entry in
completion mode, the editor shows the
entry that is highlighted on the
members list.
When an IntelliSense window is open,
you can press CTRL+ALT+SPACEBAR to
toggle between completion mode and
suggestion mode.
So I guess it would depend on which of Resharpers features you want to use. If you are satisfied with the above which is certainly great improvements, then you don't need Resharper.
On the performance question, well it might perform better because of tighter integration.
Personally the above leaves me still needing a lot of features like (just the ones i can think of right now - might be more):
There are as far as I can tell only about 6 refactorings, where resharper currently has more than 30
No import type completion, which i use ALL the time. One shortcut adds to references and adds import statement
No smart completion
Change namespace to follow navigation structure and update all references with one shortcut
Goto is more advanced in R# you can go to inheritors and bases,
file member, recent files and edits and theres the fast goto feature
Resharpers static analysis is far more comprehensive than what you get from VS
So what do you need? (I am definitely not giving up Resharper)
Peter,
Best person that can answer this question is yourself. What I suggest is you download it, learn it (and note I said learn it, not just play with it). Then decide. However, I'll warn you that it's quite addictive.
My question is VS2010 == VS2008 + ReSharper ?
Oh hell no. VS2010 has more features than VS2008, and some of those feature ideas were stolen from ReSharper, but vanilla VS2010 is still a long way behind VS2010 + ReSharper 5 or even VS2008 + ReSharper 5.
From a quick glance at my 31 Days of ReSharper blog posts (written back in the R# 2.5 days), here are just a few ReSharper features that are still not present in VS2010: (Please correct me if VS2010 does have any of these -- I haven't actually used it that much without ReSharper!)
Unused code highlighted in gray and with quick-fixes to delete the unused code for you (this is just one of many hints and warnings R# does that VS does not)
Visual indication of where you have hints, warnings, and errors in a source file (colored stripe next to the vertical scroll bar)
Integrated unit-test runner that's not locked down to only MS's test framework
Shared settings for code formatting, code templates, etc. -- check these settings into version control, and they'll be picked up automatically by other computers (no manual export/import)
Go To Type -- a pop-up window where you can enter a type name (or part of the name) and jump straight to the right source file
Navigate to derived types / overriding methods
Code Structure View -- view a list of members in your type, and drag/drop to reorder them in your source code
R# will suggest variable names for you
You can invoke an Intellisense dropdown that shows types from all namespaces (and then it adds the using for you)
It's eerily good at guessing what you meant when you tell it to fix an error for you
Remove unused braces and Invert If
Generate Code (I particularly like Generate Equals and GetHashCode, even though I use them very rarely)
Viral Rename (if you rename a type, it'll also suggest that you rename any variables that were named after the type)
And best of all, Safe Delete.
Safe Delete rocks.
And that's just the features that R# had in 2.5 when I wrote the 31 Days of ReSharper. They've added plenty of new features since (I just don't have a comprehensive list handy). A couple of my favorites are the background solution-wide analysis, which will tell you in nearly real-time if you have compiler errors anywhere in your solution, and Inspect > Value Origin, which is just wicked cool.
If your having to ask the question, my guess is that you're not using ReSharper to its full potential. Personally I find that R# writes most of my code for me and I feel like a noob using visual studio without it.
YES. unequivocably YES.
After migrating to Visual Studio 2010 we asked our development team if buying Resharper upgrades is worth the investment. The votes were unanimous: yes!
Btw: we use VS2010 Premium and the devteam has its own budget.
Why don't you try out the R# 5 betas and then you can decide if you're using enough of its features to justify purchasing it.
http://confluence.jetbrains.net/display/ReSharper/ReSharper+5.0+Nightly+Builds
ReSharper has been around long enough that developers might purchase the upgrade just out of habit! :)
I recall that when VS2008 was released, R# wasn't quite ready, and there was griping among the .NET community about it. "Must...have...ReSharper!". Heh. Jetbrains appear to be on top of it this time though.

Resources