Selenyumda C #

Buni bilib olishni istardim, albatta, biz Coded UI testida bo'lgani kabi Selenyum C# da Assert sinf mavjud. yoki selenyumda tasdiqlash uchun Microsoft.VisualStudio.TestTools.UnitTesting.Assert sinfidan foydalanasiz. Rahmat

0

6 javoblar

Yes you would use the Assert class in your unit test framework, in your case MSTest

selenyum kutubxonasi, sinov kodi funktsiyasi uchun javobgarlikni o'z zimmasiga olmaydi, shu jumladan tasdiqlaydi . Frameworklarni biron-bir sababga ko'ra almashtirishingiz kerak bo'lsa, zarur bo'lgan o'zgarishlarni minimallashtirishga imkon beradigan turli xil ramkalarni qo'llab-quvvatlaydigan FluentAssertions dan foydalanishingiz mumkin MSTest .

3
qo'shib qo'ydi
@rana muammosi yo'q! Agar siz bu savolga o'zingizning muammoingizga etarlicha yordam bergan deb hisoblasangiz, uni javob sifatida belgilashni unutmang. Baxtli kodlash :)
qo'shib qo'ydi muallif mrfreester, manba
Rahmat @ mrfreester..it menga juda yordam beradi
qo'shib qo'ydi muallif rana, manba

Shu tarzda assert popupning ekraniga o'tish uchun foydalanish mumkin:

IAlert alert = driver.SwitchTo().Alert();
String alertcontent = alert.Text;
Assert.AreEqual(alertcontent, "Do you want to save this article as draft?");
obj.waitfn(5000);
alert.Accept();
1
qo'shib qo'ydi

According to https://msdn.microsoft.com/en-us/library/ms182532.aspx

[TestClass]
public class UnitTest1
{
    private IWebDriver driver;
    [TestInitialize]
    public void Setup()
    {
        driver = new ChromeDriver();
        driver.Url = "Your URL";
    }

    [TestMethod]
    public void TestMethod1()
    {
        //Your first test method
        var element = driver.FindElement(By.Id("ID"));
        Assert.IsTrue(element.Displayed);
        Assert.AreEqual(element.Text.ToLower(), "Expected text".ToLower());
    }

    [TestMethod]
    public void TestMethod2()
    {
        //Your second test method
    }

    [TestCleanup]
    public void TearDown()
    {
        driver.Quit();
    }
}
0
qo'shib qo'ydi

Tasdiqlashni ishlatish uchun avval Visual Studio'da birlik sinov loyihasini yaratishingiz kerak. yoki loyihaga murojaat qilingandan keyin import qilish.

`using Microsoft.VisualStudio.TestTools.UnitTesting;
 //Using this You can use Assert class.
 Assert.IsTrue(bool);
 Assert.IsFalse(bool);
 Assert.AreEqual(string,string);
`
0
qo'shib qo'ydi

Siz MSTest dan foydalanishingiz mumkin yoki men oddiy tasdiq usulini yozishni afzal ko'rmoqchiman. Seleniumda ishlatish holatlarining ko'pi mantiqiy nazoratdan iborat bo'ladi, IsTrue | IsFalse (siz hatto yanada murakkab iddaolar yozish uchun ham cho'zishingiz mumkin), shuning uchun siz o'zingizning fikringizni aniqlaganingizda, skriptingiz ustidan ko'proq nazoratni qo'lga kiritasiz,

  • Tasdiqlash muvaffaqiyatsizlikka uchrasa, ekran tasvirini olish
  • Siz muvaffaqiyatsiz yashashingiz va testni davom ettirishingiz mumkin
  • Siz skriptni qisman o'tishingiz mumkin
  • UI'dan ko'proq ma'lumot olish, JavaScript xatolar yoki server xatolaridir.
0
qo'shib qo'ydi

Assert class is available with either MSTest or NUnit framework. I used NUnit, and there is Assert class as in below line of code.

Sample code:

Assert.AreEqual(AmericaEmail, "[email protected]", "Strings are not matching");
0
qo'shib qo'ydi