[Selenium C#] Bài 10: Thực hành Auto Test hệ thống CRM

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);
            
        }

    }
}
  • 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

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: new

Filename: post/post_detail.php

Line Number: 382

Backtrace:

File: /home/anhtest2/public_html/application/views/frontend/post/post_detail.php
Line: 382
Function: _error_handler

File: /home/anhtest2/public_html/application/views/frontend/layout/layout_view.php
Line: 361
Function: view

File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 34
Function: view

File: /home/anhtest2/public_html/application/controllers/frontend/Post.php
Line: 59
Function: render

File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Notice

Message: Trying to get property 'slug' of non-object

Filename: post/post_detail.php

Line Number: 382

Backtrace:

File: /home/anhtest2/public_html/application/views/frontend/post/post_detail.php
Line: 382
Function: _error_handler

File: /home/anhtest2/public_html/application/views/frontend/layout/layout_view.php
Line: 361
Function: view

File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 34
Function: view

File: /home/anhtest2/public_html/application/controllers/frontend/Post.php
Line: 59
Function: render

File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once

https://anhtester.com//blog/selenium-c/" data-width="100%" data-numposts="4">