how to force fully fail a coded UI script


i cam to a problem  few weeks back i was using exception handling in my script the problem was when my script got failed because catch block was there even due to failure on console script was shown passed. To solve this problem i used following command now when catch portion of script is executed it auto fails the test case  ” Assert.Fail();”

Code of test case  :

 try
            {

                DateTime thisDay = DateTime.Today;
                String curDay = thisDay.ToString();
                //ICDataProvider ICDP = new ICDataProvider();
                //List a;
                //a = ICDP.createFileTD();

           ////     BrowserWindow.CurrentBrowser = “chrome”
                this.UIMap.backToHome();
                takeImage(“login”);
                this.UIMap.createDocument();
                this.UIMap.createDocument();
                this.UIMap.testCreateFileParams.UIForm1txtSubjectEditText = “test File Subject coadedUI23423 called from dunction askfal”+RandomString(7);
                this.UIMap.testCreateFileParams.UIForm1oldFileRefNoEditText = “test File Reference number coadedUI23423” + RandomString(7);
                this.UIMap.testCreateFileParams.UIForm1DescriptionEditText = “test File Description coadedUI23423” + RandomString(7);
                this.UIMap.testCreateFile();
                takeImage(“Create Document”);
                this.UIMap.gotTOFileINfo();
                takeImage(“CreateFile”);
                this.UIMap.prepareCase();
                this.UIMap.approveCase();
                takeImage(“Prepare case on File”);
                this.UIMap.closeCase();
                takeImage(“approve Case on File”);
                SendMail(“pass”, “test”);
            }
            catch (Exception ex)
            {

                ex.ToString();

                SendMail(“fail”, ex.ToString());
 Assert.Fail();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s