The PageObjects and StepObjects pattern
Based on the principles of object-oriented programming, you can easily organize the autotest structure using the PageObjects and StepObjects patterns.
The principle of class interaction:
Demo autotest:
file ExamplePage.cs |
using System; using HatFramework; namespace Hat { public static class ExamplePage { public static string URL = @"https://somovstudio.github.io/test_eng.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"; } } |
file 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); } } } |
file 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 = "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: Generate EPub eBooks with ease