C#编程总是提示:应输入类型、命名空间定义或文件尾 (CS1022) ,我仔细核对过{没发现问题,求大神
代码如下:usingSystem;usingSystem.Text;usingSystem.Text.RegularExpressions;usingSystem.Thr...
代码如下:
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
namespace login
{
[TestFixture]
public class Login
{
public static void Main(string[] args)
{
private IWebDriver driver;
private StringBuilder verificationErrors;
private string baseURL;
private bool acceptNextAlert = true;
[SetUp]
public void SetupTest()
{
driver = new FirefoxDriver();
baseURL = "http://localhost:8083/Home/Login";
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
driver.Quit();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Test]
public void TheLoginTest()
{
driver.Navigate().GoToUrl(baseURL + "/Home/Login");
driver.FindElement(By.Id("txtLoginName")).Click();
driver.FindElement(By.Id("txtLoginName")).Clear();
driver.FindElement(By.Id("txtLoginName")).SendKeys("2-540");
driver.FindElement(By.Id("txtLoginPwd")).Clear();
driver.FindElement(By.Id("txtLoginPwd")).SendKeys("0");
driver.FindElement(By.Id("btnLogin")).Click();
driver.FindElement(By.CssSelector("a.a4")).Click();
}
private bool IsElementPresent(By by)
{
try
{
driver.FindElement(by);
return true;
}
catch (NoSuchElementException)
{
return false;
}
}
private bool IsAlertPresent()
{
try
{
driver.SwitchTo().Alert();
return true;
}
catch (NoAlertPresentException)
{
return false;
}
}
private string CloseAlertAndGetItsText()
{
try {
IAlert alert = driver.SwitchTo().Alert();
string alertText = alert.Text;
if (acceptNextAlert) {
alert.Accept();
} else {
alert.Dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
}
} 展开
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
namespace login
{
[TestFixture]
public class Login
{
public static void Main(string[] args)
{
private IWebDriver driver;
private StringBuilder verificationErrors;
private string baseURL;
private bool acceptNextAlert = true;
[SetUp]
public void SetupTest()
{
driver = new FirefoxDriver();
baseURL = "http://localhost:8083/Home/Login";
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
driver.Quit();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Test]
public void TheLoginTest()
{
driver.Navigate().GoToUrl(baseURL + "/Home/Login");
driver.FindElement(By.Id("txtLoginName")).Click();
driver.FindElement(By.Id("txtLoginName")).Clear();
driver.FindElement(By.Id("txtLoginName")).SendKeys("2-540");
driver.FindElement(By.Id("txtLoginPwd")).Clear();
driver.FindElement(By.Id("txtLoginPwd")).SendKeys("0");
driver.FindElement(By.Id("btnLogin")).Click();
driver.FindElement(By.CssSelector("a.a4")).Click();
}
private bool IsElementPresent(By by)
{
try
{
driver.FindElement(by);
return true;
}
catch (NoSuchElementException)
{
return false;
}
}
private bool IsAlertPresent()
{
try
{
driver.SwitchTo().Alert();
return true;
}
catch (NoAlertPresentException)
{
return false;
}
}
private string CloseAlertAndGetItsText()
{
try {
IAlert alert = driver.SwitchTo().Alert();
string alertText = alert.Text;
if (acceptNextAlert) {
alert.Accept();
} else {
alert.Dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询