如何测试机器人(一个应用程序来自动化另一个程序)?

时间:2019-07-26 17:40:02

标签: c# .net visual-studio tdd

我正在尝试使某些软件自动化(此刻我正在使Web服务自动化)。我已经知道有关TDD的原理,但是我不知道如何进行测试。我该如何测试?

我还没有尝试过有关测试自动化方法的任何事情,我什至不知道如何开始。我将Teststack White用于UI测试,并将.net中的本机单元测试模块用于我知道如何测试的事情。 就像我说的那样,我正在开发一个Web服务自动化程序,因此我正在使用WebBrowser导航到该站点,然后执行操作(它不适用于简单的post / get请求,有很多请求有人导航到幕后时不断在幕后制作)。我还没有API(希望它正在开发中),所以这是唯一的方法。

<Window x:Class="Bot.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Bot"
        mc:Ignorable="d"
        Title="MainWindow" Height="487" Width="800">

        <WebBrowser Name="MyBrowser" Height="250" LoadCompleted="AppLoaded"/>
</Window>
´´´

```c# .net
//
private void AppLoaded(object sender, NavigationEventArgs e)
{

    Console.WriteLine("Creating solicitation.");
    mshtml.HTMLDocument htmlDoc = (mshtml.HTMLDocument) MyBrowser.Document;
    mshtml.HTMLAnchorElement btnClickme = (mshtml.HTMLAnchorElement) htmlDoc.getElementById("login");
    //I'm moving the focus away from the browser, for some reason it fails to click while on focus.
    MyBrowser.MoveFocus(new System.Windows.Input.TraversalRequest(System.Windows.Input.FocusNavigationDirection.First));
    //If the button is found, click on it to start the process. It won't redirect the browser, it should change some elements in the screen.
    if (botaoSolicitar != null) botaoSolicitar.click();
}
´´´

How can I test this type of code? All methods only cause changes in the web page, my only feedback is the existance or inexistance of certain elements on the page.

0 个答案:

没有答案