Паттерн PageObjects и StepObjects
Основываясь на принципах объектно-ориентированного программирования можно легко организовать структуру автотеста с применением паттернов PageObjects и StepObjects.
Принцип взаимодействие классов:
Демонстрационный автотест:
файл ExamplePage.cs |
using System; using HatFramework; namespace Hat { public static class ExamplePage { public static string URL = @"https://somovstudio.github.io/test.html"; public static string InputLogin = "login"; public static string InputPass = "pass"; public static string ButtonLogin = "buttonLogin"; public static string Result = "result"; public static string Textarea = "textarea"; } } |
файл ExampleSteps.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 ExampleSteps : Tester { public ExampleSteps(Form browserWindow): base(browserWindow) {} public async Task FillForm() { await this.WaitVisibleElementByIdAsync(ExamplePage.InputLogin, 15); await this.SetValueInElementByIdAsync(ExamplePage.InputLogin, "admin"); await this.WaitAsync(2); await this.SetValueInElementByIdAsync(ExamplePage.InputPass, "0000"); await this.WaitAsync(2); } } } |
файл ExampleTest2.cs |
using System; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using HatFramework; namespace Hat { public class ExampleTest2 { ExampleSteps tester; public async void Main(Form browserWindow) { tester = new ExampleSteps(browserWindow); await setUp(); await test(); await tearDown(); } public async Task setUp() { await tester.BrowserFullScreenAsync(); } public async Task test() { await tester.TestBeginAsync(); await tester.GoToUrlAsync(ExamplePage.URL, 5); await tester.FillForm(); await tester.ClickElementByIdAsync(ExamplePage.ButtonLogin); await tester.WaitVisibleElementByIdAsync(ExamplePage.Result, 5); string actual = await tester.GetValueFromElementByIdAsync(ExamplePage.Textarea); string expected = "Вы успешно авторизованы"; await tester.AssertEqualsAsync(expected, actual); await tester.TestEndAsync(); } public async Task tearDown() { await tester.BrowserCloseAsync(); } } } |
Created with the Personal Edition of HelpNDoc: Easily create Qt Help files