PDA

View Full Version : تست موازی selenium Grid



mehliaeb
دوشنبه 28 فروردین 1396, 11:23 صبح
کسی میتونه کمک کنه چطور تست هارو به صورت موازی اجرا کنم ؟استفاده از selenium Grid در سی شارپ
ممنون

mehliaeb
سه شنبه 29 فروردین 1396, 08:39 صبح
تست هارو میخام همزمان رو چند بروزر اجرا بشه
از سلنیوم گرید استفاده کردم با سی شارپ تست هارو نوشتم با استفده از وب درایور سلنیوم.
حالا سلنیوم گرید رو میخام اجراش کنم نمیشه
عکس ضمیمه شده
لطفا کمک
144989

mehliaeb
چهارشنبه 30 فروردین 1396, 10:24 صبح
Selenium 1, where the Selenium server was necessary to run tests, Selenium WebDriver does not need a special server to execute tests. Instead, the WebDriver directly starts a browser instance and controls it.
در متن بالا منظور از سرور همون مرورگر هستش؟

mehliaeb
شنبه 02 اردیبهشت 1396, 13:04 عصر
کسی میتونه در باره اجرای چند تست همزمان کمک کنه

mehliaeb
سه شنبه 12 اردیبهشت 1396, 15:03 عصر
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_ContentPlaceHolder1_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_ContentPlaceHolder1_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_ContentPlaceHolder1_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_ContentPlaceHolder1_grdVacationList_ctl00__ 1 > td.rgSorted")).Click();
elementXpath = ".//*[@id='ctl00_ContentPlaceHolder1_txtAdminParaf']";
waitFor(elementXpath,false);
driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_txtAdminParaf")).Clear();
driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_txtAdminParaf")).SendKeys("test");
driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_btnReject")).Click();
}
}
}

کد بالا کدهای تست هستش که با grid میخام تست موازی انجام بدم اما همچین خطایی میده
Unable to cast object of type 'System.String' to type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]

mehliaeb
سه شنبه 12 اردیبهشت 1396, 15:04 عصر
این هم عکس نود و هابی هستش که ست کردم

کسی میتونه کمک کنه

145122