zoukankan      html  css  js  c++  java
  • Web application automation test in VS by selenium

    Let me give a brief introduction to selenium at first:
    Selenium is a set of tools that supports rapid development of test automation for web-based applications.    Two major tools will be used here:    Selenium-IDE (Integrated Development Environment):  A Firefox add-on, which has a recording feature and will keep account of user actions and store them as a reusable script to play back.    Selenium-RC (Remote Control): This allows using high-level programming language (HTML, Java, C#, Perl, PHP, Python, and Ruby) to develop test cases and allows automated testing to be integrated with a project’s automated build environment.


    Now I will introduce how to do web application automation test in VS by selenium:

      1. Some tools to install:
        a) As selenium-IDE is an only Firefox add-on, Firefox is required to install at first.
        b) Download and install Selenium-IDE, download Selenium-RC and unzip it to local disk from http://seleniumhq.org/download.
        c) Java is required to install as it is used to start Selenium-RC server.

      2. Open Firefox, start Selenium-IDE (Tools -> Selenium IDE) to record test case.

        

      3. Export test case generated by Selenium-IDE to C# code(baidu.cs):

           

    [TestFixture]
    public class baidu
    {
        
    private ISelenium selenium;
        
    private StringBuilder verificationErrors;

        [SetUp]
        
    public void SetupTest()
        {
            selenium 
    = new DefaultSelenium("localhost"4444"*chrome""http://www.baidu.com/");
            selenium.Start();
            verificationErrors 
    = new StringBuilder();
        }

        [TearDown]
        
    public void TeardownTest()
        {
            
    try
            {
                selenium.Stop();
            }
            
    catch (Exception)
            {
                
    // Ignore errors if unable to close the browser
            }
            Assert.AreEqual(
    "", verificationErrors.ToString());
        }

        [Test]
        
    public void TheBaiduTest()
        {
            selenium.Open(
    "/");
            selenium.Type(
    "kw""google");
            selenium.Click(
    "su");
            selenium.WaitForPageToLoad(
    "30000");
            selenium.Click(
    "//table[@id='1']/tbody/tr/td/a/font");
        }
    }

      4. Create a test project in VSTT.

          5. Copy .dll files from unzipped Selenium-RC folder “~\selenium-remote-control-1.0.1\selenium-dotnet-client-driver-1.0.1” to your test project’s \Bin\Debug folder and add reference.

          

      6. Add a new unit test file, copy the c# code generated by Selenium-IDE to the unit test file, and change the attribute of methods to that supported by VSTT:

        

      7. Before you run your test, you should start selenium-server at first,
          start java  -jar  selenium-server.jar  -forcedbrowsermode *firefox(*googlechrome, *iexplore, *opera, *safari, ...)
      8. Run automation test cases:
               mstest /runconfig:%TestProjPath%\TestRunConfig.testrunconfig /testmetadata:%TestProjPath%\[testname].vsmdi /testlist:%TestToRun% /resultsfile:%TestProjPath%\TestResults\[resultname].trx, %TestToRun% is the test list you select to run in [testname].vsmdi.

  • 相关阅读:
    数据结构--线性表顺序存储(顺序表)
    图论--双连通分量--点双连通模板
    C++ 模板(template) 的定义
    图论--网络流--最大流 HDU 2883 kebab(离散化)
    图论--网络流--最小割 HDU 2485 Destroying the bus stations(最短路+限流建图)
    图论--网络流--最大流 HDU 3572 Task Schedule(限流建图,超级源汇)
    图论--网络流--最大流--POJ 1698 Alice's Chance
    CodeForces 709C Letters Cyclic Shift
    CodeForces 709B Checkpoints
    CodeForces 709A Juicer
  • 原文地址:https://www.cnblogs.com/sanmao_net/p/1718410.html
Copyright © 2011-2022 走看看