我写了一个非常基本的硒测试。我的测试返回页面的页面标题,但如果我现在想更进一步并根据我的期望验证页面标题,我将如何执行此操作?
因此,例如,如果我希望标题为“aaa”,但它返回了不同的东西,我希望我的测试失败。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Interactions;
using System.Threading;
namespace Exercise1
{
class test1
{
static void Main()
{
IWebDriver webDriver = new ChromeDriver();
webDriver.Navigate().GoToUrl("https://energy.gocompare.com/gas-electricity");
webDriver.Manage().Window.Maximize();
String title = webDriver.Title;
Console.WriteLine("Title of webpage is " + title);
// webDriver.Quit();
}
}
}
你可以比较一下,
String expectedTitle = "Utilities from Go Compare";
if(title.contains(expectedTitle)){
Console.writeline("Title is matching with expected value");
}
else{
Console.writeline("Title is not matching with expected value");
}
或者您可以使用NUnit
Assert 方法,例如
Assert.AreEqual(true, title.contains(expectedTitle), "Title is not matching");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句