本文整理汇总了C#中ITestContext类的典型用法代码示例。如果您正苦于以下问题:C# ITestContext类的具体用法?C# ITestContext怎么用?C# ITestContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITestContext类属于命名空间,在下文中一共展示了ITestContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FullyQualifiedApplicationPath
public string FullyQualifiedApplicationPath(ITestContext testContext)
{
//Return variable declaration
var appPath = string.Empty;
//Getting the current context of HTTP request
var context = testContext.HttpContext;
//Checking the current context content
if (context != null)
{
//Formatting the fully qualified website url/name
appPath = string.Format("{0}://{1}{2}{3}",
context.Request.Url.Scheme,
context.Request.Url.Host,
context.Request.Url.Port == 80
? string.Empty
: ":" + context.Request.Url.Port,
context.Request.ApplicationPath);
}
if (!appPath.EndsWith("/"))
appPath += "/";
return appPath;
}
示例2: Test
public void Test(ITestContext context)
{
if (this.url.IsNullOrEmpty() || this.url == "/" || this.url == "~" || this.url == "~/")
{
this.url = this.FullyQualifiedApplicationPath(context);
}
if (this.action.IsNullOrEmpty())
{
throw new ApplicationException(Errors.UrlAndActionCannotBeEmpty);
}
this.service = new WebApiService { Timeout = this.timeout };
try
{
var result = this.arguments == null
? this.service.Get<object>(this.url, this.action)
: this.service.Get<object>(this.url, this.action, this.arguments);
}
catch (WebApiException ex)
{
Assert.Fails(Errors.FailedToAccessService, ex.Message);
}
}
示例3: IterationSetup
public void IterationSetup(ITestContext testContext)
{
//Debug.WriteLine("IterationSetup is executed before each ExecuteScenario call");
if (Random.Next(100) % 50 == 0)
throw new Exception("2% error chance for testing");
}
示例4: Scan
public IEnumerable<Step> Scan(ITestContext testContext, MethodInfo method, Example example)
{
var executableAttribute = (ExecutableAttribute)method.GetCustomAttributes(typeof(ExecutableAttribute), false).FirstOrDefault();
if (executableAttribute == null)
yield break;
string stepTitle = executableAttribute.StepTitle;
if (string.IsNullOrEmpty(stepTitle))
stepTitle = Configurator.Scanners.Humanize(method.Name);
var stepAsserts = IsAssertingByAttribute(method);
var methodParameters = method.GetParameters();
var inputs = new List<object>();
var inputPlaceholders = Regex.Matches(stepTitle, " <(\\w+)> ");
for (int i = 0; i < inputPlaceholders.Count; i++)
{
var placeholder = inputPlaceholders[i].Groups[1].Value;
for (int j = 0; j < example.Headers.Length; j++)
{
if (example.Values.ElementAt(j).MatchesName(placeholder))
{
inputs.Add(example.GetValueOf(j, methodParameters[inputs.Count].ParameterType));
break;
}
}
}
var stepAction = StepActionFactory.GetStepAction(method, inputs.ToArray());
yield return new Step(stepAction, new StepTitle(stepTitle), stepAsserts, executableAttribute.ExecutionOrder, true, new List<StepArgument>());
}
示例5: SetUp
public override void SetUp(ITestContext context)
{
RunningNode.Subscriptions.ClearAll();
MessageHistory.ClearAll();
InMemoryQueueManager.ClearAll();
FubuTransport.ApplyMessageHistoryWatching = true;
}
示例6: ReadExpected
public void ReadExpected(ITestContext context, IStep step, SetRow row)
{
Cell.ReadArgument(context, step, x =>
{
row.Values[Cell.Key] = x;
});
}
示例7: execute
protected override void execute(IWebElement element, IDictionary<string, object> cellValues, IStep step, ITestContext context)
{
// TODO -- StoryTeller needs to pull this all inside the Cell
if (!cellValues.ContainsKey(_cell.Key))
{
// already caught as a syntax error
return;
}
var handler = ElementHandlers.FindHandler(element);
var expectedValue = cellValues[_cell.Key];
var matchingHandler = handler as IMatchingHandler ?? new BasicMatchingHandler(handler, context);
if (matchingHandler.MatchesData(element, expectedValue))
{
context.IncrementRights();
}
else
{
context.ResultsFor(step).MarkFailure(_cell.Key);
context.IncrementWrongs();
}
context.ResultsFor(step).SetActual(_cell.Key, handler.GetData(CurrentContext, element));
}
示例8: WriteResults
public void WriteResults(StepResults results, ITestContext context)
{
if (!_cell.IsResult)
{
WritePreview(context);
return;
}
var actual = results.HasActual(_cell.Key) ? results.GetActual(_cell.Key) : "MISSING";
if (results.IsInException(_cell.Key))
{
Text("Error!");
AddClass(HtmlClasses.EXCEPTION);
return;
}
if (results.IsFailure(_cell.Key))
{
var expected = _step.Get(_cell.Key);
string text = "{0}, but was '{1}'".ToFormat(expected, actual);
Text(text);
AddClass(HtmlClasses.FAIL);
}
else
{
Text(context.GetDisplay(actual));
AddClass(HtmlClasses.PASS);
}
}
示例9: SetUp
public override void SetUp(ITestContext context)
{
_settings = new DeploymentSettings("storyteller");
context.Store(_settings);
_writer = new DeploymentWriter("storyteller");
}
示例10: ResultsWriter
public ResultsWriter(HtmlDocument document, ITestContext context)
{
_document = document;
_context = context;
_document.AddStyle(HtmlClasses.CSS());
}
示例11: ScenarioSetup
public void ScenarioSetup(ITestContext testContext)
{
//Debug.WriteLine("ScenarioSetup Executes on thread creation");
//Debug.WriteLine("Exceptions here are not handled!");
Console.WriteLine($"Created Thread {testContext.ThreadId}");
}
示例12: SetUp
public override sealed void SetUp(ITestContext context)
{
// TODO -- later, make this thing be able to swap up the application under test
_application = context.Retrieve<IApplicationUnderTest>();
beforeRunning();
}
示例13: Scan
public virtual IEnumerable<Scenario> Scan(ITestContext testContext)
{
Type scenarioType;
string scenarioTitle;
if (testContext.Examples == null)
{
var steps = ScanScenarioForSteps(testContext);
scenarioType = testContext.TestObject.GetType();
scenarioTitle = _scenarioTitle ?? GetScenarioText(scenarioType);
var orderedSteps = steps.OrderBy(o => o.ExecutionOrder).ThenBy(o => o.ExecutionSubOrder).ToList();
yield return new Scenario(testContext.TestObject, orderedSteps, scenarioTitle, testContext.Tags);
yield break;
}
scenarioType = testContext.TestObject.GetType();
scenarioTitle = _scenarioTitle ?? GetScenarioText(scenarioType);
var scenarioId = Configurator.IdGenerator.GetScenarioId();
foreach (var example in testContext.Examples)
{
var steps = ScanScenarioForSteps(testContext, example);
var orderedSteps = steps.OrderBy(o => o.ExecutionOrder).ThenBy(o => o.ExecutionSubOrder).ToList();
yield return new Scenario(scenarioId, testContext.TestObject, orderedSteps, scenarioTitle, example, testContext.Tags);
}
}
示例14: execute
protected override void execute(IWebElement element, IDictionary<string, object> cellValues, IStep step, ITestContext context)
{
assertCondition(element.Enabled, DisabledElementMessage);
assertCondition(element.Displayed, HiddenElementMessage);
element.Click();
}
示例15: IterationTearDown
public void IterationTearDown(ITestContext testContext)
{
//Debug.WriteLine("IterationTearDown is executed each time after ExecuteScenario iteration is finished.");
//Debug.WriteLine("It is also executed even when IterationSetup or ExecuteScenario fails");
if (Random.Next(100) % 25 == 0)
throw new Exception("4% error chance for testing");
}