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

  • 相关阅读:
    World file文件格式
    HTML5 基础
    Spring Framework---概况
    Tomcat(1)
    警言妙句
    嵌入式系统总是要用户对变量或寄存器进行位操作。给定一个整型变量a,写两段代码,第一个设置a的bit 3,第二个清除a 的bit 3。在以上两个操作中,要保持其它位不变。
    关键字volatile有什么含意?并给出三个不同的例子。
    关键字const有什么含意?
    关于指针数组、数组指针、指针函数、函数指针等的问题
    实现两个int变量的值的交换,要求不使用临时变量。
  • 原文地址:https://www.cnblogs.com/sanmao_net/p/1718410.html
Copyright © 2020-2023  润新知