This is a migrated thread and some comments may be shown as answers.

NUnit conversion of test-as-step

4 Answers 121 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Raul Ribeiro
Top achievements
Rank 1
Raul Ribeiro asked on 25 Sep 2009, 10:46 AM
Greetings!

We have developed a number of tests using Telerik Web UI Test studio which use the test-as-step feature quite frequently.
This means that a large number of our "main tests" use other smaller tests as steps in order to make the "main tests" more modular.

This has been working fine for us, but now we have been trying to convert our webaii "main tests" into nunit tests,
by using the conversion interface displayed in this video and the appropriate user setting displayed here.

However, we are running into a problem. It seems the conversion process does not translate the several test-as-steps correctly
into their appropriate code. Instead, the code in the main nunit test is similar to this:

// Execute test 'Create Origin List.aii' - This is the smaller test-as-step
this.ExecuteTest("Auxiliary Steps\\Create Origin List.aii");

which makes sense, but the compiler says the class doesn't have a ExecuteTest method.
The "main test" class was converted to code as follows: public class Move_Test_1UnitTest : BaseNUnitTest

 - Are we missing a reference in the solution ?
 - Are we missing some other setting which makes the conversion process create the code for the test-as-steps ?
 - Or does this have to be accomplished by hand?  By previewing and copy-pasting the code for the test-as-steps
into the main nunit test?
 
 Thank you very much for your attention,
 AndrĂ© Silva.

4 Answers, 1 is accepted

Sort by
0
Missing User
answered on 25 Sep 2009, 05:11 PM
Hi Andre,

In the NUnit, you would have to write test code to call the Test as Step NUnit generated test. If you would like to use the same browser, you can do the following in the Test as Step MyTestInitialize() :

// Pass in 'true' to recycle the browser between test methods     
//Initialize(false, new TestContextWriteLine(Core.TestContext.Out.WriteLine));     
    
// If you need to override any other settings coming from the      
// config section or you don't have a config section, you can     
// comment the 'Initialize' line above and instead use the      
// following:     
    
// This will get a new Settings object. If a configuration     
// section exists, then settings from that section will be     
// loaded     
    
Settings settings = GetSettings();      
    
// Override the settings you want. For example:     
settings.RecycleBrowser = true;     
    
// Now call Initialize again with your updated settings object     
Initialize(settings, new TestContextWriteLine(Core.TestContext.Out.WriteLine));   

Please note the first generated Initialize() method  is commented out. Also, remember to comment out the Manager.LaunchNewBrowser() in the Test as Step WebAii NUnit test method also, or another browser will be launched. Then in the Main WebAii NUnit Test you can do the following:

TestProject.WebAiiTest1UnitTest w = new WebAiiTest1UnitTest();  
w.MyTestInitialize();  
w.WebAiiTest1(); 

Please let us know if you have any other questions.

Greetings,
Nelson Sin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Raul Ribeiro
Top achievements
Rank 1
answered on 29 Sep 2009, 10:45 AM
Greetings!

We have been using your suggestion and it has been working fine. However, we ran into another problem using the file upload dialog.
In our test we are trying to upload two different files into a Sharepoint 2007 document library: Documento1.docx and Documento2.docx.
For this, we created two small test-as-steps which are responsible for pressing the upload button, handling the upload dialogue
and pressing the "OK" button. The first test-as-step is configured to upload Documento1.docx and the second test-as-step is configured
to upload Documento2.docx. Both of these test-as-steps are then used in a "main test". According to your suggestion, we transformed
the two smaller test-as-steps into Nunit tests and then invoked them in the "main test".
Thus, the code in the main test is as follows:

            // Execute test 'uploadfile.aii' 
            Log.WriteLine("Uploading document 1"); 
            uploadfileUnitTest uploadFile = new uploadfileUnitTest(); 
            uploadFile.MyTestInitialize(); 
            uploadFile.uploadfile(); 
             
            // Execute test 'UploadFile2.aii' 
            //this.ExecuteTest("Auxiliary Steps\\UploadFile2.aii"); 
            Log.WriteLine("Uploading document 2"); 
            UploadFile2UnitTest uploadFile2 = new UploadFile2UnitTest(); 
            uploadFile2.MyTestInitialize(); 
            uploadFile2.UploadFile2(); 

And the code for the two test-as-steps is as follows

        public void uploadfile() 
        { 
            // Launch an instance of the browser. Commented out as requested by telerik 
            //Manager.LaunchNewBrowser(); 
            //Manager.Elements.ReturnElementProxyWhenNotFound = true; 
 
            // Handle 'FileUpload' dialog. 
            FileUploadDialog fileDialog;  
             
            fileDialog = new FileUploadDialog(ActiveBrowser,  
            "C:\\DocTeste\\Documento1.docx",  
            DialogButton.OPEN); 
             
            Manager.DialogMonitor.AddDialog(fileDialog); 
 
 
            // Start Dialog Monitoring 
            Manager.DialogMonitor.Start(); 
 
 
            // Click 'a_Zz19_UploadMenu' 
            HtmlAnchor a_Zz19_UploadMenu = Pages.OriginList.a_Zz19_UploadMenu; 
            a_Zz19_UploadMenu.Wait.ForExists(10000); 
            a_Zz19_UploadMenu.Click(false); 
 
 
            // Click 'input_File_Plac__InputFile' 
            HtmlInputFile input_File_Plac__InputFile = Pages.Upload_Document.input_File_Plac__InputFile; 
            input_File_Plac__InputFile.Wait.ForExists(10000); 
            if ((ActiveBrowser.BrowserType == BrowserType.FireFox)) 
            { 
                ActiveBrowser.Window.SetFocus(); 
                input_File_Plac__InputFile.ScrollToVisible(ScrollToVisibleType.ElementTopAtWindowTop); 
                input_File_Plac__InputFile.MouseClick(); 
            } 
            else 
            { 
                input_File_Plac__InputFile.Click(false); 
            } 
 
            // Wait Until Dialog is Handled. 
            fileDialog.WaitUntilHandled(5000); 
 
            // Click 'input_Button_Pl__BtnOK' 
            HtmlInputButton input_Button_Pl__BtnOK = Pages.Upload_Document.input_Button_Pl__BtnOK; 
            input_Button_Pl__BtnOK.Wait.ForExists(10000); 
            input_Button_Pl__BtnOK.Click(false); 
 
        } 

and

        public void UploadFile2() 
        { 
            // Launch an instance of the browser.  Commented out as requested by telerik 
            //Manager.LaunchNewBrowser(); 
            //Manager.Elements.ReturnElementProxyWhenNotFound = true; 
 
            // Handle 'FileUpload' dialog. 
            FileUploadDialog fileDialog;  
             
            fileDialog = new FileUploadDialog(ActiveBrowser,  
            "C:\\DocTeste\\Documento2.docx",  
            DialogButton.OPEN); 
             
            Manager.DialogMonitor.AddDialog(fileDialog); 
 
            // Start Dialog Monitoring 
            Manager.DialogMonitor.Start(); 
 
            // Click 'a_Zz19_UploadMenu' 
            HtmlAnchor a_Zz19_UploadMenu = Pages.OriginList.a_Zz19_UploadMenu; 
            a_Zz19_UploadMenu.Wait.ForExists(10000); 
            a_Zz19_UploadMenu.Click(false); 
 
            // Click 'input_File_Plac__InputFile' 
            HtmlInputFile input_File_Plac__InputFile = Pages.Upload_Document.input_File_Plac__InputFile; 
            input_File_Plac__InputFile.Wait.ForExists(10000); 
            if ((ActiveBrowser.BrowserType == BrowserType.FireFox)) 
            { 
                ActiveBrowser.Window.SetFocus(); 
                input_File_Plac__InputFile.ScrollToVisible(ScrollToVisibleType.ElementTopAtWindowTop); 
                input_File_Plac__InputFile.MouseClick(); 
            } 
            else 
            { 
                input_File_Plac__InputFile.Click(false); 
            } 
 
            // Wait Until Dialog is Handled. 
            fileDialog.WaitUntilHandled(5000); 
 
            // Click 'input_Button_Pl__BtnOK' 
            HtmlInputButton input_Button_Pl__BtnOK = Pages.Upload_Document.input_Button_Pl__BtnOK; 
            input_Button_Pl__BtnOK.Wait.ForExists(10000); 
            input_Button_Pl__BtnOK.Click(false); 
 
        } 




This all seems to make sense, but when we run the test we see that the same Documento1.docx is uploaded twice,
which means that it is uploaded once by the uploadFile.uploadfile() instruction and again by the uploadFile2.UploadFile2() instruction.
This is very strange, since we can see that the configured file path for the uploadFile2.UploadFile2() instruction is for Documento2.docx
and not for Documento1.docx.

 - Why is this happening?
 - Is there some need for a forced "cleanup" stage for the first test-as-step?
 
 If you require any further information or code samples for this problem, please don't hesitate to tell us.
 
 Thank you very much for your attention,
 AndrĂ© Silva.







0
Cody
Telerik team
answered on 29 Sep 2009, 02:26 PM
Hi JoĂ£o Martins,

We're very pleased to hear that Nelson's suggestion has been working well for you.

For your file upload problem, yes there is a little bit of cleanup that is missing. The DialogMonitor is maintained in the framework and keeps running in between all steps. So what has happened is you added two dialogs to DialogMonitor at the same time. The first one is always taking over not allowing the second one a chance to run.

You simply need to add
Manager.DialogMonitor.RemoveDialog(fileDialog); 

To the end of each of your uploadFileX() methods (anytime after the WaitUntilHandled call). This will remove the dialog from DialogMonitor so that it will no longer try to handle the FileUpload dialog for you.


All the best,
Cody
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Raul Ribeiro
Top achievements
Rank 1
answered on 02 Oct 2009, 01:29 PM
Greetings!

Thank you for your reply. We have followed your suggestion and it seems to be working fine now.
We'll let you know if we run into more problems with our Sharepoint tests.

Thank you very much for your attention,
André Silva.
Tags
General Discussions
Asked by
Raul Ribeiro
Top achievements
Rank 1
Answers by
Missing User
Raul Ribeiro
Top achievements
Rank 1
Cody
Telerik team
Share this question
or