Nội dung bài học

Thực hành viết code auto với các thao tác cơ bản để thực hiện chức năng Add Client

using NUnit.Framework;
using OpenQA.Selenium;
using SeleniumCSharp.Initialize;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace SeleniumCSharp.Bai10_ThucHanh
{
    class ThucHanh : Init_Program
    {
        [Test]
        public void addClient()
        {
            driver.Navigate().GoToUrl("https://crm.anhtester.com");

            driver.FindElement(By.XPath("//input[@id='email']")).SendKeys("admin02@mailinator.com");
            driver.FindElement(By.XPath("//input[@id='password']")).SendKeys("123456");
            driver.FindElement(By.XPath("//button[@type='submit']")).Click();

            driver.FindElement(By.XPath("//span[text()='Clients']")).Click();

            driver.FindElement(By.XPath("//a[@title='Add client']")).Click();

            Thread.Sleep(1000);

            IWebElement headerDialog = driver.FindElement(By.XPath("//h4[@id='ajaxModalTitle']"));

            Assert.AreEqual("Add client", headerDialog.Text, "Header page of the dialog Add Client is fail.");

            string companyName = "Selenium C# A2";

            driver.FindElement(By.Id("company_name")).SendKeys(companyName);

            // Click vào dropdown Owner
            driver.FindElement(By.Id("s2id_created_by")).Click();
            // Điền giá trị Owner
            Thread.Sleep(1000);
            driver.FindElement(By.XPath("//div[@id='select2-drop']//div[@class='select2-search']//input")).SendKeys("Admin 01");
            // Enter để chọn item đầu tiếnau khi search
            Thread.Sleep(1000);
            driver.FindElement(By.XPath("//div[@id='select2-drop']//div[@class='select2-search']//input")).SendKeys(Keys.Enter);

            driver.FindElement(By.Id("address")).SendKeys("Phuong 6");
            driver.FindElement(By.Id("city")).SendKeys("Cao Lanh");
            driver.FindElement(By.Id("state")).SendKeys("Dong Thap");
            driver.FindElement(By.Id("zip")).SendKeys("81000");
            driver.FindElement(By.Id("country")).SendKeys("Viet Nam");
            driver.FindElement(By.Id("phone")).SendKeys("0939206009");
            driver.FindElement(By.Id("website")).SendKeys("https://anhtester.com");
            driver.FindElement(By.Id("vat_number")).SendKeys("10000");
            driver.FindElement(By.XPath("//li[@class='select2-search-field']//input")).SendKeys("Automation");
            driver.FindElement(By.XPath("//li[@class='select2-search-field']//input")).SendKeys(Keys.Enter);

            //Nhấn button Save
            driver.FindElement(By.XPath("//button[normalize-space()='Save']")).Click();
            Thread.Sleep(2000);
            //Search lại để kiểm tra giá trị sau khi Add client
            driver.FindElement(By.XPath("//a[contains(text(),'Clients')]")).Click();
            driver.FindElement(By.XPath("//input[@type='search']")).SendKeys(companyName);
            Thread.Sleep(1000);
            IWebElement itemClient = driver.FindElement(By.XPath("//table[@id='client-table']//tbody//tr[1]//td[2]/a"));

            Assert.AreEqual(companyName, itemClient.Text);
            
        }

    }
}

Cộng đồng Automation Testing Việt Nam

🌱 Facebook Fanpage: Anh Tester
🌱 Telegram
Automation Testing:   Cộng đồng Automation Testing
🌱 
Facebook Group Automation: Cộng đồng Automation Testing Việt Nam
🌱 Telegram
Manual Testing:   Cộng đồng Manual Testing
🌱 
Facebook Group Manual: Cộng đồng Manual Testing Việt Nam

  • Anh Tester

    Đường dẫu khó chân vẫn cần bước đi
    Đời dẫu khổ tâm vẫn cần nghĩ thấu


Cộng đồng Automation Testing Việt Nam:

🌱 Telegram Automation Testing:   Cộng đồng Automation Testing
🌱 
Facebook Group Automation: Cộng đồng Automation Testing Việt Nam
🌱 
Facebook Fanpage: Cộng đồng Automation Testing Việt Nam - Selenium
🌱 Telegram
Manual Testing:   Cộng đồng Manual Testing
🌱 
Facebook Group Manual: Cộng đồng Manual Testing Việt Nam

Chia sẻ kiến thức lên trang

Bạn có thể đăng bài để chia sẻ kiến thức, bài viết của chính bạn lên trang Anh Tester Blog

Danh sách bài học