Simple project

Parent Previous Next

Simple project


Autotests are described in a programming language C#.


The structure of the autotest:


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Windows.Forms;

using System.Threading;

using System.Threading.Tasks;

using System.IO;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Text.RegularExpressions;

using System.Net;

using System.Net.Http;

using System.Net.Http.Headers;

using System.Reflection;

using Newtonsoft.Json;

using HatFramework;

At the beginning there is a list of plug-in libraries.


HatFramework - this is an embedded framework in the browser.

namespace Hat

{

    public class ExampleTest1

    {

        

    }

}

Namespace and class.

The class name must be the same as the file name.

Tester tester;


public async void Main(Form browserWindow)

{

        tester = new Tester(browserWindow);


        await setUp();

        await test();

        await tearDown();

}

A global variable is declared whose type is Tester


The main function with which the autotest starts is described.

This function initializes a global variable whose type is Tester.


Next comes the call of asynchronous functions.

public async Task setUp()

{

            

}


public async Task test()

{

        await tester.TestBeginAsync();

            

        await tester.TestEndAsync();

}


public async Task tearDown()

{


}

Asynchronous functions are described that perform:


  • setUp - function before the test
  • task - test function
  • tearDown - function after the test


(the names of the functions can be any, the meaning itself and their sequence are important)


Note: the test should always start with the TestBeginAsync() method and end with the TestEndAsync() method



The demo autotest is complete:


Файл: ExampleTest1.cs

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Windows.Forms;

using System.Threading;

using System.Threading.Tasks;

using System.IO;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Text.RegularExpressions;

using System.Net;

using System.Net.Http;

using System.Net.Http.Headers;

using System.Reflection;

using Newtonsoft.Json;

using HatFramework;


namespace Hat

{

    public class ExampleTest1

    {

        Tester tester;


        public async void Main(Form browserWindow)

        {

            tester = new Tester(browserWindow);


            await setUp();

            await test();

            await tearDown();

        }


        public async Task setUp()

        {

            await tester.BrowserFullScreenAsync();

        }


        public async Task test()

        {

            await tester.TestBeginAsync();

            await tester.GoToUrlAsync("https://somovstudio.github.io/test_eng.html", 5);

            await tester.WaitVisibleElementByIdAsync("login", 15);

            await tester.SetValueInElementByIdAsync("login", "admin");

            await tester.WaitAsync(2);

            await tester.SetValueInElementByIdAsync("pass", "0000");

            await tester.WaitAsync(2);

            await tester.ClickElementByIdAsync("buttonLogin");

            await tester.WaitVisibleElementByIdAsync("result", 5);

            string actual = await tester.GetValueFromElementByIdAsync("textarea");

            string expected = "Authorization was successful";

            await tester.AssertEqualsAsync(expected, actual);

            await tester.TestEndAsync();

        }


        public async Task tearDown()

        {

            await tester.BrowserCloseAsync();

        }

    }

}




Created with the Personal Edition of HelpNDoc: Free Kindle producer