【发布时间】:2015-01-11 02:36:51
【问题描述】:
我想禁用 firefox javascript 并运行我的自动化测试。
我正在使用 Specflow + c# 和 selenium。
我也在使用 PageObject 模式和页面工厂。
我的功能文件是这样的:
Scenario: Search for item after disabling the javascript
Given I am a ACUST
When I disable the javascript
And I have entered a text 'dress' string to search for that matches a product
Then The relevant search results for the 'dress' will be returned
我的代码如下:
using System;
using System.Collections.Generic;
using System.Collections;
using TechTalk.SpecFlow;
using NUnit.Framework;
using OpenQA.Selenium;
using Hof.Web.Tests.UIAutomation.Pages;
using Hof.Web.Tests.UIAutomation.Helper;
using Hof.Components.Common;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Support.UI;
public class SearchSteps : Steps
{
private static readonly string Url = ConfigHelper.GetValue<string>("tset.Web.BaseUrl.QA3") + "/product";
public IWebDriver driver;
public SearchSteps()
{
WebBrowser.driverType = "MF";
driver = WebBrowser.Current;
}
[Given(@"I am a ACUST")]
public void GivenIamAAnonymousCustumer()
{
var hp = new HeaderPage(driver);
GenericFunctions.NavigateToURL(Url);//In Future it will be changed to Homepage URL
Console.WriteLine("Account Name:= " + hp.Lnk_SignInOrRegister.Text);
Assert.IsTrue(hp.Lnk_SignInOrRegister.Text.Trim().Equals("Sign in or Register"),"Err! User is not anonymous. Please Log out");
}
[When(@"I disable the javascript")]
public void WhenIDisableTheJavascript()
{
driver.Close(); //closes previous browser session which has javascript enabled
FirefoxProfile p = new FirefoxProfile();
p.SetPreference("javascript.enabled", false);
driver = new FirefoxDriver(p);
var hp = new HeaderPage(driver);
GenericFunctions.NavigateToURL(Url);
}
[When(@"I have entered a text '(.*)' string to search for that matches a product")]
public void WhenIHaveEnteredATextStringToSearchForThatMatchesAProduct(string strPrdToSearch)
{
var hp = new HeaderPage(driver);
hp.searchForProduct(strPrdToSearch);
}
[Then(@"The relevant search results for the '(.*)' will be returned")]
public void ThenTheRelevantSearchResultsForTheWillBeReturned(string prdSearchToVerify)
{
var hofProductpage = new ProductPage(WebBrowser.Current);
hofProductpage.verifyProductSearch(prdSearchToVerify);
}
NavigateToURL 代码:
public static void NavigateToURL(string url , IWebDriver driver)
{
driver.Navigate().GoToUrl(url);
}
浏览器打开,并且 URL 以禁用 javascript 的形式导航,但接下来的步骤失败了:
And I have entered a text 'dress' string to search for that matches a product
Then The relevant search results for the 'dress' will be returned
要拆解的代码:
[Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute()]
public virtual void ScenarioTearDown()
{
testRunner.OnScenarioEnd();
}
还有更多
OnScenarioEnd() invokes void OnScenarioEnd();
我得到的错误是:
System.InvalidOperationException:未指定会话 ID
TestCleanup 方法 Hof.Web.Tests.UIAutomation.FeatureFiles.Feature.ScenarioTearDown 引发异常。 System.InvalidOperationException:System.InvalidOperationException:未指定会话 ID。
【问题讨论】:
-
所以问题出在
GenericFunctions.NavigateToURL(Url);。里面的代码是什么? -
如果您想回答您的问题,您应该在
GenericFunctions.NavigateToURL(Url);中提供代码,以便对其中发生的事情进行一些推理 -
@SamHolder :我已将代码添加到 NavigateToURL
-
@Arran:我已将代码添加到 NavigateToURL
-
@ArpanBuch 请发布
Hof.Web.Tests.UIAutomation.FeatureFiles.Feature.ScenarioTearDown的内容,因为这似乎是问题所在
标签: c# selenium selenium-webdriver specflow pageobjects