Thursday, February 26, 2015

Automating windows popup/dialog boxes using C # and Java

In some scenarios we faced problem to automate windows dialog boxes Selenium with C# or Selenium with Java. There are different ways to automate windows popup. One thing is clear that we can not automate using selenium because selenium is only use for browser based applications.
So we have only option is to use our scripting languages only.




Using C#:
To identify control id use UISpy. To automate we need to use "System.Windows.Automation" namespace in our project.




using System;
using System.Threading;
using System.Windows.Automation;
using Microsoft.VisualStudio.TestTools.UnitTesting;

public class WindowPopUpHandler
{
   private bool _isCancelClicked = false;
  
   public bool Authenticate(string windowTitle, string userName, string password)
    {
      string checkProperty = "AutomationId";

      string userNameId = "1003";

      string passwordId = "1005";

      string okButoonId = "1";
      try
        {


            AutomationElement desktopRoot = AutomationElement.RootElement;
            AutomationElement app = desktopRoot.FindFirst(TreeScope.Children,
            new PropertyCondition(AutomationElement.NameProperty, windowTitle));


           if (app == null)


            throw new AutomationException("Window '" + windowTitle + "' is not found.");

            this.WaitForCondition(app, checkProperty, userNameId, 5000);


            AutomationElement userNameTextBoxElement = GetRequiredElement(app,      checkProperty, userNameId);
           var userNameTextBox = (ValuePattern)userNameTextBoxElement.GetCurrentPattern  (ValuePattern.Pattern);


           userNameTextBox.SetValue(userName);
 


           AutomationElement passwordTextBoxElement = GetRequiredElement(app, checkProperty, passwordId);
            var passwordTextBox = (ValuePattern)passwordTextBoxElement.GetCurrentPattern   (ValuePattern.Pattern);


AutomationElement okButton = GetRequiredElement(app, checkProperty, okButoonId);
var okButtonelement = (InvokePattern)okButton.GetCurrentPattern(InvokePattern.Pattern);


                   okButtonelement.Invoke();
                    return true;


}
catch (Exception e)
{
throw new AutomationException("Authenticate Method Failed due to exception '" + e.Message);

}
}
}


Using Java: Need to import Robot jar into our application.



import java.awt.AWTException;


import java.awt.Robot;


import java.awt.event.KeyEvent;


import java.util.concurrent.TimeUnit;


import org.apache.log4j.xml.DOMConfigurator;


import org.testng.annotations.BeforeSuite;


import org.testng.annotations.BeforeTest;


import org.testng.annotations.AfterTest;


public class BaseTest extends CommonFunction {






@Test


public void AdminPageLogin() throws InterruptedException, AWTException, java.io.IOException





{

try{

LaunchBrowser(readConfig("urlAdmin"));





}

catch(Exception e){ //Setting UserName and Password by Sending Keys using Robot class


Robot robot = new Robot();

Utilities.CopyPaste(readConfig("adminUserId"), robot);

Utilities.SendKeys(KeyEvent.VK_TAB, robot);

Utilities.CopyPaste(readConfig("adminPwd"), robot);

Utilities.SendKeys(KeyEvent.VK_TAB, robot);

Utilities.SendKeys(KeyEvent.VK_ENTER, robot);
}



Friday, February 20, 2015

Six Things You Should Never Say to a Software Tester

Whether you’re a co-worker, colleague, friend, foe or relative, here are 6 things you should probably never say to a software tester. You’ve been warned!
1. “Can you hurry up and finish testing soon? We’re under a very tight deadline.”
Good testing cannot be rushed. Ideally, testing should begin with the design phase of a project and continue all the way through. Software testing is ultimately about validating the design requirements, but to be effective at that, the testing process must begin with the design stage itself. When testing is started later, it can be less effective. Designers must sync with testers, developers must sync with testers, and valuable time is wasted getting teams and technology expectations to mesh. This is a recipe for delays, confusion, and budget overruns.
Starting the testing process with design lets testers be involved  from the beginning. They can contribute early, get to know the product early, and be involved early. That makes for better testing and that makes for a better product.
2. “Promise me there’s no bugs in this, okay?”
It’s been argued (correctly, in my opinion) that the role of testing is not “quality assurance” but rather “quality assistance.” I believe that phrase originated with Jon Bach, but don’t quote me on that. Basically, quality cannot be tested into a product, thus a tester’s job is not to verify that a product is error-free, but that it has passed (or failed) to meet a certain set of standards, which vary from company to company. Leave the outlandish promises to the marketing and sales departments. Keep testing in the realm of reality.
3. “You must be bored out of your mind.”
This is a huge myth of software testing, but one that’s easy to dispel. Go to a testing conference, read a few blogs and articles and you’ll quickly see how passionate testers can be with their craft. Here’s a nice quote from Michael Bolton that pretty much sums it up:
“Testing is something that we do with the motivation of finding new information.  Testing is a process of exploration, discovery, investigation, and learning.  When we configure, operate, and observe a product with the intention of evaluating it, or with the intention of recognizing a problem that we hadn’t anticipated, we’re testing.  We’re testing when we’re trying to find out about the extents and limitations of the product and its design, and when we’re largely driven by questions that haven’t been answered or even asked before.”
4. “I didn’t have time to read your bug report. Give me the 5-second version.”
Testers (the good ones, anyway) spent a great deal of time crafting their bug reports with precision, accuracy and steps to re-produce. When a developer (or other department) doesn’t care to understand the full severity of a bug, it not only wastes the tester’s time, but it can lead to huge problems down the road. The reasons for this should be rather obvious. Instead of the five second version, how about the five word version? Read the freaking bug report.
5. “You’re actually a very nice person. I don’t care what the developers say.”
I had to throw a little humor into the post :). On a more serious note, the relationship between testers and developers is not always – how shall I say this – pleasant. As testing guru James Bach once wrote: “Anyone who creates a piece of work and submits it for judgment is going to feel judged. That’s not a pleasant feeling. And the problem is compounded by testers who glibly declare that this or that little nit or nat is a “defect,” as if anything they personally don’t like is a quality problem for everybody.” In other words, don’t stir the pot.
6. “Couldn’t a machine do this much easier?”

Depends on what they’re doing, but even if the answer to that question were “yes” who would manage the automation? Who would analyze the results? Who would choose the tool to use and decide where and when it’s going to be implemented? This doesn’t even touch on the need for manual testing. Machines can do a lot of things, but replacing testers is not – and never will be – one of them.

Lessons in how not to develop software

Once in a while a great case study comes along that is a great teaching vehicle.   This is one of them.

Two current magazine articles cover the dismal debut last fall (2013) of www.healthcare.gov , America’s federal website where citizens can sign up for new and improved healthcare insurance under the Affordable Care Act (aka “Obamacare”).  “Code Red” is the title of the article in the March 10th, 2014 issue of TIME magazine.  The other, “Failure to Launch”,  is in the March/April, 2014 issue of Foreign Affairs.  I found a lot of useful information in them, and believe you’ll find their story extremely useful as an object lesson in quality control, governance, design, and rock-solid delivery.

Early in 2013, the Congressional Budget Office projected the enrollment of 7 million people between www.healthcarel.gov’s going live and the end of the year.  The website went live on October 1st.  Over the next 6 weeks, only a few thousand people were able to register.  Thousands could not navigate beyond the log-in dialog.  Thousands more were blocked by unhelpful error messages.  The entire system crashed several times in October and November.   A team of mostly Silicon Valley engineers (from Google, Oracle, and Red Hat), hastily and urgently selected on the strength of peer recommendation, spent October and November fixing hundreds of bugs and re-factoring lots of code.   I heard this afternoon on National Public Radio that over 6 million people have enrolled to date – certainly better than a few thousand, but roughly 3 months behind schedule.    What did the team of engineers and testers learn had gone wrong in this massive project that, in October, came within a day or two of being junked?

Here’s a short list of contributing problems.   Some look very familiar.
·         Insufficient testing.  In late March, 2013, McKinsey prepared a report for the Department of Health and Human Services (parent organization for the Center for Medicaid and Medicare Services (CMS), who had been assigned ownership for producing the website – the actual development was done by CGI Group and other contractors) that pointed to “insufficient time and scope of end-to-end testing”. 
·         Insufficient performance testing.    Also in March-April, CMS warned its management that they would not be able to test load adequately by October because they could not simulate so many people logging on simultaneously. 
·         Failure to report correct tested capacity.   In October, the team of Silicon Valley coders and testers reported that the website was crashing because its capacity was not 200,000 concurrent users, as had been reported, nor 100,000, but at most a mere 2,000 users.   The system crashed in October when 250,000 people tried to enroll.     
·         Reluctance to communicate failure up the management ladder.  The head of the Department of Health and Human Services did not know how bad the system was until after it had launched.   Neither did President Obama, since he looked to her for current status. 
·         Senior managers “drank the Kool-Aid”, repeating to themselves and to the press that everything was fine, without consulting the engineers who were aware of many problems (for example, page-load time was 8 seconds).   In September, David Simas, the White House senior adviser for communications, assured a reporter for Time magazine that “everything has been tested and is working perfectly.”  
·         No technical leadership.   Contractors bickered amongst themselves.  
·         No dashboard.   It was impossible to get a global view of progress or quality.
·         No sense of urgency among contractor employees even after the website had become the butt of jokes in world-wide media. 
·         Scope for go-live was global, not incremental.  It failed early, and colossally.
·         Caching was not used, so all queries were going directly to the database.
·         Tight coupling.   If something slowed down in one part of the backend, everything slowed down.


Apart from root-cause analysis and fixing over 500 bugs, what single practice was credited with saving the website?  Stand-ups.  Stand-ups, that is, as organized by Mikey Dickerson, a Google engineer with the title “Site Reliability Engineer”.   They aren’t the stand-ups we’re used to:
·         Twice-daily standups were held,  at 10 a.m. and 6:30 pm, 7 days a week, with average duration around 45 minutes.
·         To connect people at remote locations, open lines were left open 24 hours a day so that people could immediately exchange information.
·         Rules were posted outside the control center:

Rule # 1:  “The war room and the meetings are for solving problems.  There are plenty of other venues where people devote their creative energies to shifting blame.”

Rule #2:   “The ones who should be doing the talking are the people who know the most about an issue, not the ones with the highest rank.  If anyone finds themselves sitting passively while managers and executives talk over them with less accurate information, we have gone off the rails, and I would like to know about it.” 


Rule #3:   “We need to stay focused on the most urgent issues, like things that will hurt us in the next 24-48 hours.”  

When to use automation, and when it doesn't make sense



     

If you’ve got 750 test cases in your regression suite and it takes 4 testers 2 weeks (= 280 hours) to complete them, you’ll want to take a hard look at automating those test cases.   If one person can maintain and execute all of those tests, depending on the complexity of the scripts you could reduce tester time to  between 10 and 15 hours.  That saves a lot of money for the company, and provides a lot of flexibility to release management.  

Other factors complicate cost-benefit analysis.  For example, if the UI changes a lot and your automation is UI-dependent, maintenance will be costly.   That doesn’t mean you shouldn’t automate; just keep it in mind when deciding how much and what to automate.   There’s rule of thumb that says ROI on automation justifies its cost only if the automation is used three times.   But there are situations where automation pays for itself even if it is only run once, like when you’ve told the customer to expect the next drop tomorrow and you’ve got to take a last-minute check-in tonight.  There are many articles available on line that walk you through determining ROI on automation.

Even if the ROI for automation is next to 0, the skills that are required to create automation can be applied in many other ways to make your testing more efficient, understand the software you’re testing, and provide verification that may not be available through unassisted observation.  “Tools” doesn’t mean you’ve bought a ready-to-go commercial off-the-shelf tool, or that you’ve downloaded  someone else’s tool from Tucow.com.  It can be as homegrown as a script in Python or VBA or Powershell, etc.  Some examples:
·         Usability testing can be enhanced by tracking key and mouse activation. 
·         You can use automation to generate test data (from a few bytes to terabytes).   
·         You may want to track a system or application log file and find the value of three critical variables when a certain event is logged.  
·         We see a lot of enterprise software that is dependent on configuration that a function that works in one configuration fails on another;  you can reduce testing time by the relatively inexpensive automation of deployment and configuration even if you can’t afford automation of test cases.
·         If you identify an error-producing pattern in the code you’re testing, you can automate the search for similar patterns in code checked in by the same developer.

How you test, and whether you will benefit from tools or not, depends on the software under test.  A major flaw in the way we test (I’m speaking of the software industry in general) is that we feel good (we won’t test any deeper) if we have a test case for every requirement, and back it up with a traceability matrix where we can retrofit bug fixes or refactoring to the relevant requirement.  While seeing a traceability matrix is an occasion for celebration, it’s just a tool – we don’t know if it’s been set up intelligently.    Is one test case per requirement sufficient?  Should the requirements (or user stories) be segmented to ensure full coverage?  How important is all of this to the user?   

Testing requirements for testability is often left to BAs without testing experience, or it’s left to testers who don’t have time for it.  Negative testing, if it is included in sprint planning, is tokenized, i.e. if we execute one or two negative tests we’re done.   The whole purpose of exploratory testing is to ask yourself whether planned test coverage is sufficient, and determine if additional testing should be added to the regression suite or if a one-time check is sufficient.

The more testers can use tools, the more their hands-on, brain-in-gear manual testing will improve.  The more that testers understand how software works and check it out through exploratory testing, the better they’ll be at creating and using automation and other testing tools. 

Happy testing!