硒测试运行错误和不完整

时间:2017-05-08 04:25:36

标签: c# selenium selenium-webdriver selenium-chromedriver

enter image description here

我想用Selenium网格运行并行测试,但是当我点击"运行所有"它打开了两个浏览器,但只有一个节点超过2节点继续测试,其中一个节点上的测试不完整,有什么问题?

  [OneTimeSetUp]

  public void SetupTest()
  {
        var capabilities = DesiredCapabilities.Chrome();
         options = new ChromeOptions();
        options.AddArguments("test-type");
        options.BinaryLocation = driverPath;
        capabilities.SetCapability("chrome.binary", driverPath);
        capabilities.SetCapability(ChromeOptions.Capability, options);
        System.Environment.SetEnvironmentVariable("webdriver.chrome.‌​driver",driverPath);
        capabilities.SetCapability(ChromeOptions.Capability, options.ToString());
        capabilities.SetCapability(capabilities.Platform.ProtocolPlatformType, "WebDriver");
        capabilities.SetCapability(CapabilityType.BrowserName, "chrome");
        capabilities.SetCapability(capabilities.Version, "57");
        capabilities.SetCapability(CapabilityType.Platform, "WinNT");
        capabilities.SetCapability(ChromeOptions.Capability, options);
        if (driver != null)
        {
            Uri uri=new Uri("http://127.0.0.1:4444/wd/hub");
            RemoteWebDriver rd=new RemoteWebDriver(uri,capabilities);
            driver = rd;

        }
        baseURL = "http://192.168.10.173:8080";
        // driver.Manage().Window.Maximize();
        verificationErrors = new StringBuilder();
    }

我的测试:

 class AcceptScenario:Methods
{
    private string elementXpath;
    private bool acceptNextAlert = true;


    [Test, Order(1)]
    [Parallelizable]
    public void registerRequest_AcceptScenario()
    {

        driver = new ChromeDriver(driverPath);
        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("بدون حقوق");
        driver.FindElement(By.XPath(".//*[@id='ctl00_ContentPlaceHolder1_txtbeginDate']")).Click();
        driver.FindElement(By.CssSelector("a[title=\"۲۸ اردیبهشت ۱۳۹۶\"]")).Click();
        driver.FindElement(By.XPath(".//*[@id='ctl00_ContentPlaceHolder1_txtEndDate']")).Click();
        driver.FindElement(By.XPath("(//a[contains(text(),'۲۸')])[4]")).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("درخواست مورد نظر با موفقیت ثبت شد", errorLabel, "درخواست با درخواست های دیگر تداخل دارد");
    }

我的另一个测试是:

class RejectScenario:Methods
{

    private string elementXpath;


    [Test, Order(1)]
    [Parallelizable]

    public void registerRequest_RejectCsenario()
    {
        //if(driver!=null)
        driver=new ChromeDriver(driverPath);
        driver.Navigate().GoToUrl("Http://192.168.10.173:8080/eosLogin.aspx");
        driver.FindElement(By.Id("txtUserName")).Clear();
        driver.FindElement(By.Id("txtUserName")).SendKeys("");
        driver.FindElement(By.Id("txtPassword")).Clear();
        driver.FindElement(By.Id("txtPassword")).SendKeys("");
        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("روزانه استحقاقي");
        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("درخواست مورد نظر با موفقیت ثبت شد", errorLabel, "درخواست با درخواست های دیگر تداخل دارد");
  }

0 个答案:

没有答案