Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98788

when using chromedriver, with specflow, a new browser instance open per step

$
0
0

I'm having an issue with Specflow. For some reason, a new instance of chrome is started per step. can you help with this?

For follow test, 3 steps, 3 chrome instance are started.

Feature: Home

Background: 
Given The  QA Department site

Scenario: QA Department title 
    When QA site open
    Then QA site tile must be "UI Testing Site"

The first instance has the content i want but the other two, that i don´t know why are started, are empty.

namespace QAtests.SpecFlow_Steps.Home
{


     using NUnit.Framework;
     using System;
     using System.Collections.Generic;
     using System.Linq;
     using System.Text;
     using TechTalk.SpecFlow;

    [Binding]
     class HomeTestSteps
    {
        private readonly MainPage mainPage = new MainPage();
        private readonly PageHelper pageHelper = new PageHelper();

        public HomeTestSteps()
        {

        }

        [When(@"QA Department site open")]
        public void GivenQADepartmentSiteOpen()
        {
            var url = this.mainPage.ValiteSiteAddress();
            Assert.AreEqual(url, this.mainPage.siteURL);
        }


        [Then(@"QA Department site tile must be ""(.*)""")]
        public void ThenQADepartmentSiteTileMustBe(string pageTile)
        {
            var title = this.pageHelper.GetElementTitle();
            Assert.AreEqual(pageTile, title);
        }

    }
}

The main page class just sets the url and checks elements


namespace QAtests.Pages.Main
{
    public class MainPage
    {

        private ChromeDriver driver = new ChromeDriver();
        private readonly string elementTitle = "//title";
        public readonly string siteURL = "http://uitest.duodecadits.com/";

        public MainPage()
        {

        }


        public void StartSite()
        {
            try
            {
                this.driver.Navigate().GoToUrl(siteURL);
            }
            catch (Exception e)
            {
                throw new Exception("Can´t set address.", e);
            }

        }

        public void Close()
        {
            this.driver.Close();
        }

        public string ValiteSiteAddress()
        {
            return this.driver.Url;
        }

        public IWebElement ElementTitleisVisible()
        {
            try
            {
                return this.driver.FindElement(By.XPath(elementTitle));
            }
            catch(Exception e){
                throw new Exception("Element tile not found.", e);
            }

        }
    }
}

I think that is related with the declaration of

private ChromeDriver driver = new ChromeDriver();


Viewing all articles
Browse latest Browse all 98788

Trending Articles