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

Coded step help

5 Answers 123 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.
Alex
Top achievements
Rank 1
Alex asked on 20 Sep 2010, 06:35 PM
Hello,

My company picked up a few licenses of the tool so I'm new to the tool. I'm trying to run the following coded step to reset the database to a baseline state. I will have a sql script to do that but I would like to incorporate a coded step to call the SQL script. Below is some code I found on the web to do that. I'm not a developer so I'm probably doing something wrong. Every time I run the test I get the following error message: "Execution Stage:Execution , unexpected error during test execution. Error: System.ArgumentException: The coded step method 'SQLReset' does not exist.
   at ArtOfTest.WebAii.Design.Execution.ExecutionContext.SetNewBrowserTracking(Test test, Object codeBehind)
   at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.InternalExecuteTest(Object codeBehindInstance)
   at ArtOfTest.WebAii.Design.Execution.TestExecuteProxy.ExecuteTest(Test test, Settings settings, String deploymentFolder, ExecutionType exeType)"

Coded Step:

using

 

 

System;

 

 

 

using System.Collections.Generic;  

 

 

 

using System.Text; 

 

 

using ArtOfTest.Common.UnitTesting;

 

 

 

using ArtOfTest.WebAii.Core;

 

 

 

using ArtOfTest.WebAii.Controls.HtmlControls;

 

 

 

using ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;

 

 

 

using ArtOfTest.WebAii.Design;

 

 

 

using ArtOfTest.WebAii.Design.Execution;

 

 

 

using ArtOfTest.WebAii.ObjectModel;

 

 

 

using ArtOfTest.WebAii.Silverlight;

 

 

 

using ArtOfTest.WebAii.Silverlight.UI;

 

 

 

using Telerik.WebAii.Controls.Html;

 

 

 

using Telerik.WebAii.Controls.Xaml;

 

 

 

using System.Data.SqlClient;

 

 

 

using System.IO;

 

 

 

 

namespace DBI_Automation.BPO.Automation

 

 

{

 

 

 

public class SQLReset : BaseWebAiiTest 

 

{

 

[

 

CodedStep(@"Run SQL Script to reset database")]

 

 

 

 

protected void SQLResetCall(object sender, EventArgs e)

 

 {

 

 

 

//SqlConnection con = new SqlConnection(@"Server=.\SQLEXPRESS;Database=" + txtSqlName.Value + ";User ID=" + txtSqlLogin.Value + ";Password=" + txtSqlPassword.Text + ";Trusted_Connection=False");

 

 

 

 

SqlConnection con = new SqlConnection(@"Server=DET-3176\MSSQL2008;Database=Test;Trusted_Connection=True");

 

 

con.Open();

 

 

string FilePath;

 

FilePath = 

 

@"\\urbanscience.net\users\DET\atbeard\Documents\SQL Server Management Studio\Projects\TestSQLQuery.sql";

 

 

 

 

//FilePath = @"C:\Inetpub\vhosts\" + dsAdministration.Tables[0].Rows[0]["Domain"].ToString() + @"\httpdocs\users\" + Session["UserId"].ToString() + @"\" + Session["Domain"].ToString() + @"\css\" + lnkName.Text;

 

 

 

if (File.Exists(FilePath))

 

{

 

 

 

StringBuilder strStatement = new StringBuilder(File.ReadAllText(FilePath).ToString());

 

 

SqlCommand command = new SqlCommand(strStatement.ToString(), con);

 

command.ExecuteNonQuery();

con.Close();

}

}

}

}

*Editted because it was difficult to read

5 Answers, 1 is accepted

Sort by
0
Nikolai
Telerik team
answered on 21 Sep 2010, 10:40 AM
Hello Alex,

Few things are wrong here:
1. The access modifier of you test step should be public not protected
2. Code step method should be parameterless - you don't need sender(object) or (e)EvenArgs  

so the method signature should be like this:
 

CodedStep(@"Run SQL Script to reset database")]
public void SQLResetCall()

Hope this helps.

All the best,
Nikolai
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alex
Top achievements
Rank 1
answered on 21 Sep 2010, 12:50 PM
Thank you for your help, I'm able to run the coded step.
0
Alex
Top achievements
Rank 1
answered on 07 Oct 2010, 08:51 PM
I had a follow question I'm having some trouble with. I would like to call just one SQL script that executes 11 unique delete statements against 11 tables. I'm able to connect a single table to a test and execute a SQL Script against that table with no issue. I'm hoping I don't have to create 11 tests to clear out the tables.

Thanks!
0
Accepted
Nikolai
Telerik team
answered on 08 Oct 2010, 05:33 AM
Hi Alex,

I am not sure about your scenario. Do you need to call all the 11 SQL queries at once or you need to call each of them on demand based on the test you are running for example?

If it is the first case just alter the coded step to be called for each of your SQL queries. As far as I see from your code you are reading the query from a text file so you will just need to either extend this file to hold the 11 statements and the reader to read only parts of them (I suggest using XML file for this), or create 11 files and read each if them in a loop.

If it is the second case things get complicated. You can create a test that will hold the coded step then based on some flag (could be the current page url or some static value that you set in a coded step from parent test) you alter the SQL query. This test will be called from any test that will require DB changes.

Greetings,
Nikolai
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alex
Top achievements
Rank 1
answered on 08 Oct 2010, 02:19 PM
Thanks Nikolai,

I misunderstood how the system called the test, I was under the impression that the tables involved all had to be bound to the test. I didn't realize it was independant. Oh and btw it was the first senario and it works great now.
Tags
General Discussions
Asked by
Alex
Top achievements
Rank 1
Answers by
Nikolai
Telerik team
Alex
Top achievements
Rank 1
Share this question
or