# Introduction to Coded Tests

Test Studio allows you to combine the recorded actions in a test with coded solutions for any specific and complex scenarios, which require customization beyond the built-in verifications and actions capabilities.

In this article you can find the important topics about coding in Test Studio project:

* [What language can I use to write code in Test Studio tests?](https://www.telerik.com/teststudio/documentation/automated-tests/coded-tests/coded-step#what-coding-language-can-be-used-in-test-studio-project)
* [Can I use the recorded steps in code?](https://www.telerik.com/teststudio/documentation/automated-tests/coded-tests/coded-step#convert-a-recorded-step-to-coded-function)
* [How to create an empty coded function in the test?](https://www.telerik.com/teststudio/documentation/automated-tests/coded-tests/coded-step#insert-empty-coded-step)
* [How to create a code item accessible for all tests in the project?](https://www.telerik.com/teststudio/documentation/automated-tests/coded-tests/coded-step#which-is-the-standalone-code-file)
* [Can I search in the code file?](https://www.telerik.com/teststudio/documentation/automated-tests/coded-tests/coded-step#code-editor-options)

## What Coding Language Can Be Used in Test Studio Project?

Test Studio supports two types of coding languages - **C#** and **VisualBasic**. The language is set on project level when adding the first coded item.

![Choose coding language](https://www.telerik.com/teststudio/documentation/assets/72a132f8904de869f1d2ac89bcd0dbc9/fig1.png)

> **Tip**
> <br>
> <br>
> Once the scripting language is set on project level, it **cannot be changed** to the other option. If you need to transform the coded solution to the other language, you need to **manually convert the code**\_ to the other scripting language.

## How to Implement a Coded Function in the Test?

In Test Studio tests you can take advantage of reusing the recorded steps as coded functions as well as adding your own custom coded logic.

### Convert a Recorded Step to Coded Function

Most of the recorded steps can be converted to their corresponding coded function and allows to further customize the tests and actions. Select a recorded step, right click on it to trigger the <a href="/features/test-maintenance/test-step-context-menu" target="_blank">step context menu</a> and choose the option **Edit in Code**.

![Convert to code](https://www.telerik.com/teststudio/documentation/assets/4834ded73f224cb2dad4c8116e4017c6/fig4.png)

This automatically converts the step into a coded one and creates a new test method in the coded file associated with the test. The method represents the code required for this step depending on its type and different settings and properties set.

![Recorded step in code](https://www.telerik.com/teststudio/documentation/assets/871e5637b724860ba9db9cdec392ed53/fig5.png)

> **Tip**
> <br>
> <br>
> Check out <a href="https://www.telerik.com/blogs/writing-coded-steps-test-studio" target="_blank">this neat tutorial</a> on converting steps to coded functions in Test Studio.

### Insert Empty Coded Step

To insert an empty coded step in the test choose the 'Coded Step' option from the <a href="/features/custom-steps/overview" target="_blank">Step Builder</a> - it is listed under the **Common** section.

![Add a coded step](https://www.telerik.com/teststudio/documentation/assets/b09a3cb88e9b30cd41ea785556f81adb/fig2.png)

Adding the first coded step in a test automatically creates a coded file associated with the test. Test Studio switches from the test to the code file and allows writing the custom coded function in the empty test method.

![First coded step](https://www.telerik.com/teststudio/documentation/assets/1d1113b97f3e9ddea4783642bb2fca1b/add-coded-step.gif)

The automatically generated coded file contains some predefined values like the necessary `using` (or `Import`) statements, the project `namespace` and the base test class `BaseWebAiiTest` inherited from the current test class. All these options are customizable and can be maintained on project level in the <a href="/features/project-settings/script-options" target="_blank">Project Settings -> Script tab</a>.

![Usings, namespace, base test](https://www.telerik.com/teststudio/documentation/assets/15d99009926d8990dfcf6f0b7ab191cb/fig10.png)

> **Note**
> <br>
> <br>
> The `namespace` in all coded items should be the same. Otherwise the project cannot be compiled and the tests cannot be executed.
> <br>
> <br>
> Any <a href="/automated-tests/coded-tests/add-assembly-reference" target="_blank">external dll referenced</a> in the Test Studio project should be included as `using` (or `Import`) statement in the code file where it will be used.

For this example I will add a simple statement to refresh the page DOM tree - the test method in which the code is added is *public void WebTest_CodedStep()*.

![Custom code added](https://www.telerik.com/teststudio/documentation/assets/fef9b0480a73d0c004cc61eeebe38b45/fig11.png)

Switching back to the test steps, shows that the test method is selected for the coded step and thus can be executed as part of this test.

![Coded step added in test](https://www.telerik.com/teststudio/documentation/assets/bbf06f111ed58d6160af0cc2ab8e0d48/fig12.png)

### Add Next Coded Step in the Test

*What if you need to insert another coded step in the same test?*

Test Studio gives the option to reuse the already existing test method, or to create a new one and insert different coded function.

![Second Coded step added in test](https://www.telerik.com/teststudio/documentation/assets/86017b7ad9c5053f2890c28d8142299c/add-second-coded-step.gif)

Each coded step in the test needs to be mapped to a method from the coded file. You can choose from the coded step dropdown to map it to any of the already existing test methods, or select the option to define a new one.

![Map coded step](https://www.telerik.com/teststudio/documentation/assets/656004052e2d2aa27c743b4af6fc521a/fig3.png)

> **Tip**
> <br>
> <br>
> Multiple coded steps in the same test can be mapped to a single method in the test coded file.

## Which is the Code-Behind File?

The code-behind file is the one created with the first coded step in a test. It is associated with that test and can be used in another project if moved with the test.

> **Tip**
> <br>
> <br>
> When moving a test to another project, it is recommended to use the option to <a href="/knowledge-base/best-practices-kb/add-existing-test" target="_blank">add an existing test</a>).

## Which is the Standalone Code FIle?

Test Studio allows adding a code file on project level and it is usually called *standalone code file*. It can be used to create a utility class that defines a set of methods to perform common, often re-used functions. The code item can be used also as a helper class to assist in providing some extended functionality for your test project.

To insert a standalone code file use the option 'Add New Code File' from the <a href="/features/project-explorer/overview#project-items-context-menu" target="_blank">context menu</a> in the Project Explorer. You can add the coded file on project root level, or in any sub-folder.

![Standalone Code file](https://www.telerik.com/teststudio/documentation/assets/f1b89b8797d7d8d1aa9a3101f42e5d48/fig1.png)

> **Tip**
> <br>
> <br>
> <a href="/advanced-topics/coded-samples/general/utility-class-in-standalone" target="_blank">Here</a> you can find an example of a utility class file and how to use it from the tests in the project.

## Code Editor Options

All coded files in Test Studio project are opened in the code editor. It provides **Quick Find** and **Quick Replace** features to ease navigation and maintenance of the custom code. You can open it from the *Find* icon in the top bar, or standard *Ctrl+F* shortcut.

The search and replace functionality works in the file which is currently active.

![Code Editor](https://www.telerik.com/teststudio/documentation/assets/2b58f2cfa1278829055e74735d5fbc55/fig5.png)

There is a context menu in the coded editor, which allows you to comment or uncomment multiple lines of code when selected. You can also use the keyboard shortcuts *Ctrl+K* (comment) and *Ctrl+U* (uncomment).

![Context Menu](https://www.telerik.com/teststudio/documentation/assets/c52f04adc80fd3aa1de603f5b976a3b4/fig6.png)
