using OpenQA.Selenium;using System;
using System.Text;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium.Remote;
namespace FirstPackage
{
[TestFixture]
[Parallelizable]
public class Methods
{
public static IWebDriver driver;
public static string baseURL;
public static StringBuilder verificationErrors;
public void waitFor(string xpath, bool check)
{
for (int second = 0; ; second++)
{
if (second >= 60) Assert.Fail("timeout");
try
{
if (IsElementPresent(By.XPath(xpath), check)) break;
}
catch (Exception)
{ }
Thread.Sleep(1000);
}
}
private bool IsElementPresent(By by, bool check)
{
try
{
if (check == true && driver.FindElement(by).Text != string.Empty)
{
return true;
}
if (check == false)
{
driver.FindElement(by);
return true;
}
return false;
}
catch (NoSuchElementException)
{
return false;
}
}
[OneTimeSetUp]
public void SetupTest()
{
DesiredCapabilities capability = DesiredCapabilities.Chrome();
driver = new RemoteWebDriver(new Uri("http://192.168.10.173:4444/"),new DesiredCapabilities("chrome","",new Platform(PlatformType.WinNT)));
//capability.SetCapability("chrome", capability.BrowserName);
//capability.SetCapability("WIN10", capability.Platform);
// driver = new ChromeDriver();
baseURL = "http://192.168.10.173:8080/";
// driver.Manage().Window.Maximize();
verificationErrors = new StringBuilder();
}
[OneTimeTearDown]
public void TeardownTest()
{
try
{
driver.Quit();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
}
}
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
namespace FirstPackage
{
[TestFixture]
[Parallelizable(ParallelScope.Fixtures)]
class AcceptScenario:Methods
{
private string elementXpath;
private bool acceptNextAlert = true;
[Test, Order(1)]
[Parallelizable]
public void registerRequest_AcceptScenario()
{
driver.Navigate().GoToUrl(baseURL + "/eosLogin.aspx");
driver.FindElement(By.Id("txtUserName")).Clear();
driver.FindElement(By.Id("txtUserName")).SendKeys( "14");
driver.FindElement(By.Id("txtPassword")).Clear();
driver.FindElement(By.Id("txtPassword")).SendKeys( "14");
elementXpath = ".//*[@id='btnSubmit']";
waitFor(elementXpath,false);
driver.FindElement(By.Id("btnSubmit")).Click();
}
[Test, Order(2)]
[Parallelizable]
public void TheConformThirdDegreeTest()
{
driver.Navigate().GoToUrl(baseURL + "/eosLogin.aspx");
driver.FindElement(By.Id("txtUserName")).Clear();
driver.FindElement(By.Id("txtUserName")).SendKeys( "97340309");
driver.FindElement(By.Id("txtPassword")).Clear();
driver.FindElement(By.Id("txtPassword")).SendKeys( "1");
elementXpath = ".//*[@id='btnSubmit']";
waitFor(elementXpath, false);
driver.FindElement(By.Id("btnSubmit")).Click();
}
[Test, Order(3)]
[Parallelizable]
public void TheConfirmSecondDegreeTest()
{
driver.Navigate().GoToUrl(baseURL + "/eosLogin.aspx");
driver.FindElement(By.Id("txtUserName")).Clear();
driver.FindElement(By.Id("txtUserName")).SendKeys( "994047273");
driver.FindElement(By.Id("txtPassword")).Clear();
driver.FindElement(By.Id("txtPassword")).SendKeys( "1");
elementXpath = ".//*[@id='btnSubmit']";
waitFor(elementXpath, false);
driver.FindElement(By.Id("btnSubmit")).Click();
}
[Test, Order(4)]
[Parallelizable]
public void TheConfirmFirstDegreeTest()
{
driver.Navigate().GoToUrl(baseURL + "/eosLogin.aspx");
driver.FindElement(By.Id("txtUserName")).Clear();
driver.FindElement(By.Id("txtUserName")).SendKeys( "994047159");
driver.FindElement(By.Id("txtPassword")).Clear();
driver.FindElement(By.Id("txtPassword")).SendKeys( "1");
elementXpath = ".//*[@id='btnSubmit']";
waitFor(elementXpath, false);
driver.FindElement(By.Id("btnSubmit")).Click();
elementXpath = "//div[@id='ctl00_SiteMenu1_siteMenu']/ul/li[8]/div/ul/li/a/span/span";
waitFor(elementXpath,false);
driver.FindElement(By.XPath("//div[@id='ctl00_SiteMenu1_siteMenu']/ul/li[8]/a/span/span")).Click();
driver.FindElement(By.CssSelector("span.rpText > span")).Click();
//
Assert.AreEqual("14", driver.FindElement(By.XPath("//tr[@id='ctl00_ContentPlaceHolder1_grdVacationList_ctl 00__0']/td[13]")).Text);
Assert.AreEqual("name", driver.FindElement(By.XPath("//tr[@id='ctl00_ContentPlaceHolder1_grdVacationList_ctl 00__0']/td[12]")).Text);
Assert.AreEqual("money", driver.FindElement(By.XPath("//tr[@id='ctl00_ContentPlaceHolder1_grdVacationList_ctl 00__0']/td[11]")).Text);
Assert.AreEqual("tst", driver.FindElement(By.CssSelector("td.rgSorted")). Text, "test");
Assert.AreEqual("tst", driver.FindElement(By.XPath("//tr[@id='ctl00_ContentPlaceHolder1_grdVacationList_ctl 00__0']/td[8]")).Text);
Assert.AreEqual("follow", driver.FindElement(By.XPath(".//*[@id='ctl00_ContentPlaceHolder1_grdVacationList_ctl 00__0']/td[3]")).Text);
//
driver.FindElement(By.XPath("//tr[@id='ctl00_ContentPlaceHolder1_grdVacationList_ctl 00__0']/td[11]")).Click();
elementXpath = ".//*[@id='ctl00_ContentPlaceHolder1_btnApprove']";
waitFor(elementXpath,false);
driver.FindElement(By.Id("ctl00_ContentPlaceHolder 1_btnApprove")).Click();
elementXpath = ".//*[@id='ctl00_ContentPlaceHolder1_lblError']";
waitFor(elementXpath,true);
string errorLabel = driver.FindElement(By.XPath(".//*[@id='ctl00_ContentPlaceHolder1_lblError']")).Text;
Assert.AreEqual("hello", errorLabel, "test");
}
}
}
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
namespace FirstPackage
{
[TestFixture]
[Parallelizable(ParallelScope.Fixtures)]
class RejectScenario:Methods
{
private string elementXpath;
[Test, Order(1)]
[Parallelizable]
public void registerRequest_RejectCsenario()
{
//if(driver!=null)
driver.Url = baseURL + "/eosLogin.aspx";
//driver.Navigate().GoToUrl(baseURL + "/eosLogin.aspx");
driver.FindElement(By.Id("txtUserName")).Clear();
driver.FindElement(By.Id("txtUserName")).SendKeys( "14");
driver.FindElement(By.Id("txtPassword")).Clear();
driver.FindElement(By.Id("txtPassword")).SendKeys( "14");
elementXpath = ".//*[@id='btnSubmit']";
waitFor(elementXpath, false);
driver.FindElement(By.Id("btnSubmit")).Click();
elementXpath = ".//*[@id='ctl00_SiteMenu1_siteMenu']/ul/li[4]/a/span/span";
waitFor(elementXpath, false);
driver.FindElement(By.XPath(".//*[@id='ctl00_SiteMenu1_siteMenu']/ul/li[4]/a/span/span")).Click();
driver.FindElement(By.XPath(".//*[@id='ctl00_SiteMenu1_siteMenu']/ul/li[4]/div/ul/li[1]/a/span/span")).Click();
elementXpath = ".//*[@id='ctl00_ContentPlaceHolder1_ddlVacationList']";
waitFor(elementXpath, false);
//
new SelectElement(driver.FindElement(By.Id("ctl00_Cont entPlaceHolder1_ddlVacationList"))).SelectByText(" hello");
driver.FindElement(By.CssSelector("option[value=\"2\"]")).Click();
driver.FindElement(By.XPath(".//*[@id='ctl00_ContentPlaceHolder1_txtbeginDate']")).Click();
driver.FindElement(By.LinkText("۱۷")).Click();
driver.FindElement(By.XPath(".//*[@id='ctl00_ContentPlaceHolder1_txtEndDate']")).Click();
driver.FindElement(By.XPath("(//a[contains(text(),'۱۷')])[2]")).Click();
//
driver.FindElement(By.Id("ctl00_ContentPlaceHolder 1_btnSubmit")).Click();
elementXpath = ".//*[@id='ctl00_ContentPlaceHolder1_lblError']";
waitFor(elementXpath, true);
string errorLabel = driver.FindElement(By.XPath(".//*[@id='ctl00_ContentPlaceHolder1_lblError']")).Text;
Assert.AreEqual("hello", errorLabel, "test");
}
[Test,Order(2)]
[Parallelizable]
public void RejectRequest_ByManager()
{
driver.Url = baseURL + "/eosLogin.aspx";
//driver.Navigate().GoToUrl(baseURL + "/eosLogin.aspx");
driver.FindElement(By.Id("txtUserName")).Clear();
driver.FindElement(By.Id("txtUserName")).SendKeys( "97340309");
driver.FindElement(By.Id("txtPassword")).Clear();
driver.FindElement(By.Id("txtPassword")).SendKeys( "1");
elementXpath = ".//*[@id='btnSubmit']";
waitFor(elementXpath, false);
driver.FindElement(By.Id("btnSubmit")).Click();
elementXpath ="//div[@id='ctl00_SiteMenu1_siteMenu']/ul/li[8]/a/span/span";
waitFor(elementXpath,false);
driver.FindElement(By.XPath("//div[@id='ctl00_SiteMenu1_siteMenu']/ul/li[8]/a/span/span")).Click();
driver.FindElement(By.CssSelector("span.rpText > span")).Click();
driver.FindElement(By.CssSelector("#ctl00_ContentP laceHolder1_grdVacationList_ctl00__1 > td.rgSorted")).Click();
elementXpath = ".//*[@id='ctl00_ContentPlaceHolder1_txtAdminParaf']";
waitFor(elementXpath,false);
driver.FindElement(By.Id("ctl00_ContentPlaceHolder 1_txtAdminParaf")).Clear();
driver.FindElement(By.Id("ctl00_ContentPlaceHolder 1_txtAdminParaf")).SendKeys("test");
driver.FindElement(By.Id("ctl00_ContentPlaceHolder 1_btnReject")).Click();
}
}
}
کد بالا کدهای تست هستش که با grid میخام تست موازی انجام بدم اما همچین خطایی میده
Unable to cast object of type 'System.String' to type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]