小编典典

如何使用C#设置Selenium与Visual Studio .NET一起使用?

selenium

我尝试过使用google,但是有很多不同的方法可以使用Selenium。我正在使用:-Windows 2003 Server-Visual Studio
2008-通过Firefox安装的Selenium IDE-将NUnit 2.5复制到C:\-将seleniumRC复制到C:\

  1. 首先,我使用C#创建了一个图书馆项目。
  2. 这是我的课:

    使用系统;
    使用System.Text;
    使用System.Text.RegularExpressions;
    使用System.Threading;
    使用NUnit.Framework;
    使用selenium

    命名空间SeleniumTest
    {
    [TestFixture]
    公共类NewTest
    {
    私人seleniumselenium;
    私有StringBuilder验证错误;

        [建立]
        公共无效SetupTest()
        {
            selenium = new DefaultSelenium(“ localhost”,4444,“ * iexplore”,“ http:// localhost:4444”);
            selenium.Start();
            VerificationErrors = new StringBuilder();
        }
    
        [拆除]
        公共无效TeardownTest()
        {
            尝试
            {
                selenium.Stop();
            }
            catch(异常)
            {
                //如果无法关闭浏览器,请忽略错误
            }
            Assert.AreEqual(“”,“”);
        }
    
        [测试]
        公共无效TheNewTest()
        {
            selenium.Open(“ /google.com”);
        }
    }
    

    }

  3. 接下来,添加来自C:\ Selenium RC \ selenium-dotnet-client-driver-1.0.1的所有引用

  4. 编译图书馆计划,成功。没有错误。
  5. 运行NUnit.exe,现在出现错误:(

SeleniumTest.NewTest.TheNewTest:Selenium.SeleniumException:XHR错误:URL =
http:// localhost:4444 / google.com
Response_Code = 403 Error_Message = Forbidden + for + Proxy


阅读 426

收藏
2020-06-26

共1个答案

小编典典

由于将baseURL设置为Selenium
RC的baseURL,因此收到了Forbidden错误。您需要将其设置为http://www.google.com,然后在测试中

    [Test]
    public void TheNewTest()
    {
        selenium.Open( "/" );
    }

或者您需要将测试更改为

    [Test]
    public void TheNewTest()
    {
        selenium.Open( "http://www.google.com" );
    }
2020-06-26