Selenium with C# 62 - Selenium Data Driven Testing in MS Test using DataRow & DynamicData attributes

Ankpro Training
Ankpro Training
7.3 هزار بار بازدید - 4 سال پیش - Data Driven Testing in MS
Data Driven Testing in MS Test using DataRow and DynamicData attributes for selenium https://www.seevid.ir/fa/w/ssp0tH-W1vw Agenda https://www.seevid.ir/fa/w/ssp0tH-W1vw What is data driven testing https://www.seevid.ir/fa/w/ssp0tH-W1vw Why data driven testing is required https://www.seevid.ir/fa/w/ssp0tH-W1vw DataRow and DynamicData Attribute https://www.seevid.ir/fa/w/ssp0tH-W1vw Code demo for DataRow attribute https://www.seevid.ir/fa/w/ssp0tH-W1vw Code demo for DynamicData attribute https://www.seevid.ir/fa/w/ssp0tH-W1vw Possible interview questions on data driven testing What is data driven testing Data sources DataRow Attribute DynamicData Attribute What is data driven testing? Data is used to drive test cases and suites from an external data feed. Data can be feed from xls, xlsx, csv, xml and databases Why data driven testing is required? Allows testing of the application with multiple sets of data values Separates the test case data from the executable test script Allows reusing of Actions and Functions in different tests Data driven test cases are flexible and easy to maintain The same test cases are executed several times which helps to reduce efforts and code Any changes in the test script do not effect the test data DataRow and DynamicData Attribute DataRow Attribute to define in-line data for a test method. Example : [DataRow("NARENDRA","MODI","01/01/2019")] DynamicData Attribute to define dynamic data for a test method. Example : [DynamicData(nameof(GetData), DynamicDataSourceType.Method)] Possible Interview Questions on data driven testing with selenium What is data driven testing? Advantages of data driven testing? What are the attributes used in data driven testing using MSTest? What is DataRow attribute? What is DynamicData attribute? Code : [TestClass] public class UnitTest1 { [TestMethod] [DataRow("Narendra","Modi","01/01/2019")] [DataRow("donald", "trump", "07/01/2020")] [DataRow("BORIS", "JOHNSON", "12/31/2021")] public void DataDrivenTestingUsingDataRow(string fName, string lName, string eDate) { IWebDriver driver = new ChromeDriver(); driver.Manage().Window.Maximize(); driver.Url = "http://uitestpractice.com/Students/Create"; driver.FindElement(By.Id("FirstName")).SendKeys(fName); driver.FindElement(By.Id("LastName")).SendKeys(lName); driver.FindElement(By.Id("EnrollmentDate")).SendKeys(eDate); driver.FindElement(By.XPath("//input[@type='submit']")).Click(); driver.Quit(); } [DynamicData(nameof(GetData), DynamicDataSourceType.Method)] [TestMethod] public void DataDrivenTestingUsingDynamicData(string fName, string lName, string eDate) { IWebDriver driver = new ChromeDriver(); driver.Manage().Window.Maximize(); driver.Url = "http://uitestpractice.com/Students/Create"; driver.FindElement(By.Id("FirstName")).SendKeys(fName); driver.FindElement(By.Id("LastName")).SendKeys(lName); driver.FindElement(By.Id("EnrollmentDate")).SendKeys(eDate); driver.FindElement(By.XPath("//input[@type='submit']")).Click(); driver.Quit(); } public static IEnumerable<object[]> GetData() { yield return new object[] { "Narendra", "Modi", "01/01/2019" }; yield return new object[] { "donald", "trump", "07/01/2020" }; yield return new object[] { "BORIS", "JOHNSON", "12/31/2021" }; } }
4 سال پیش در تاریخ 1399/04/04 منتشر شده است.
7,362 بـار بازدید شده
... بیشتر