我希望能够在不使用 NUNIT 的情况下运行这个应用程序,特别是因为我需要每小时运行一次。我是 NUNIT 和 selenium 的初学者,想知道如何将其转换为控制台应用程序,而不必通过 NUNIT 运行它?
代码如下。非常感谢你的帮助。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Selenium;
using System.Threading;
using System.Data;
using System.IO;
namespace LogIn
{
[TestFixture]
public class LogIn
{
public static ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "https://.............aspx");
selenium.Start();
selenium.SetSpeed("900");
selenium.WindowMaximize();
selenium.WindowFocus();
verificationErrors = new StringBuilder();
}
[Test]
public void Login()
{
selenium.SetSpeed("900");
selenium.Open("/Login.aspx");
Assert.AreEqual("stuff", selenium.GetTitle());
selenium.Type("id=ctl00_cphBody_objLogin_UserName", "username");
selenium.Type("id=ctl00_cphBody_objLogin_Password", "Pass");
selenium.Click("id=ctl00_cphBody_objLogin_LoginImageButton");
selenium.WaitForPageToLoad("30000");
Assert.AreEqual("labs", selenium.GetTitle());
//i dont understand why do we need this?
/*
try
{
Assert.AreEqual("Orders - Drug Testing ", selenium.GetText("link=Orders - Drug Testing "));
}
catch (AssertionException e)
{
Console.WriteLine(e.Message + " " + DateTime.Now);
}
*/
Console.WriteLine("Congrats, you are logined successfully. " + DateTime.Now);
selenium.Click("link=Specimen Volume Report - Drugs");
selenium.WaitForPageToLoad("30000");
selenium.Click("id=ctl00_cphBody_dtpFrom");
selenium.Type("id=ctl00_cphBody_dtpFrom", DateTime.Now.ToString("MM/dd/yyyy"));
selenium.Type("id=ctl00_cphBody_dtpTo", DateTime.Now.ToString("MM/dd/yyyy"));
selenium.Click("id=ctl00_cphBody_btnExport");
selenium.SetSpeed("6000");
Console.WriteLine("Waiting for result complete");
selenium.IsTextPresent("Specimen Volume Report");
selenium.IsTextPresent("Display Specimen Detail");
}
[TearDown]
public void FullTearDown()
{
selenium.Stop();
}
}
}