C# 如何更改在BaseTest-setup方法下调用的类的属性值
资源:c#,努努努特,硒,VS 2017,restSharp 1) 这是我的测试类,继承的BaseTest类C# 如何更改在BaseTest-setup方法下调用的类的属性值,c#,selenium-webdriver,nunit,C#,Selenium Webdriver,Nunit,资源:c#,努努努特,硒,VS 2017,restSharp 1) 这是我的测试类,继承的BaseTest类 [TestFixture] public class ABCTest : BaseTest { [Test] [Retry(Constant.IterationRunsInCaseFailure)] public void ABC_Output() { Common.ExecuteTest(ABC.CheckAdd
[TestFixture]
public class ABCTest : BaseTest
{
[Test]
[Retry(Constant.IterationRunsInCaseFailure)]
public void ABC_Output()
{
Common.ExecuteTest(ABC.CheckAdd, GetType().Name, MethodName);
}
}
2) 这是基类,将在任何测试之前首先执行
[TestFixture]
public class BaseTest
{
[SetUp]
public void Init()
{
Driver.ConfigInit();
if (Driver.BaseAddress.Contains("dev.com"))
{
LoginPage.Login();
}
else
{
Assert.Fail("Please check URL ");
}
// I am calling this "TokenGenerate" method to get token and other stuff.
//since it's defined under "set up" method I am not sure how to change the property values.
string url = TokenRequest.TokenGenerate();
Driver.Instance.Navigate().GoToUrl(url);
}
}
3) 这是我感兴趣的“TokenGenerate”方法下的“TokenRequest”类
public class TokenRequest
{
public static string TokenGenerate()
{
var client = new RestClient("any url ");
var request = new RestRequest(Method.POST);
// I want change the value of this PostMe properties for few test cases. since it's a executed under"BaseTest" and called before any test so I am not sure how to change these properties "Name, ProxyUrl etc" according to test.
var postMe = new PostMe()
{
Name = "ABC ABC",
ManagementId = "ABC ABC",
ProxyUrl = ABC,
SourceFilename = ABC,
};
}
}
4) 这是要运行的测试的实际实现,在这里可以避免。
我有这样的测试用例,它们都使用PostMe属性的默认值,但是我想更改这个测试用例的值
public class ABC
{
public static bool CheckAdd()
{
CommonOutput.OpenMediaAndClickCheckbox(Constant.ABC);
return true;
}
}
请让我知道解决方案或不同类型的实现 将TokenRequst更改为:
public class TokenRequest
{
public PostMe PostMe { get; set; }
public TokenRequest()
{
PostMe = new PostMe()
{
Name = "ABC ABC",
ManagementId = "ABC ABC",
ProxyUrl = ABC,
SourceFilename = ABC,
}; ;
}
public TokenRequest(PostMe postMe)
{
PostMe = postMe;
}
public static string TokenGenerate()
{
var client = new RestClient("any url ");
var request = new RestRequest(Method.POST);
// I want change the value of this PostMe properties for few test cases. since it's a executed under"BaseTest" and called before any test so I am not sure how to change these properties "Name, ProxyUrl etc" according to test.
var postMe = PostMe;
}
}
public class TokenRequest
{
public PostMe PostMe { get; set; }
public TokenRequest()
{
PostMe = new PostMe()
{
Name = "ABC ABC",
ManagementId = "ABC ABC",
ProxyUrl = ABC,
SourceFilename = ABC,
}; ;
}
public TokenRequest(PostMe postMe)
{
PostMe = postMe;
}
public static string TokenGenerate()
{
var client = new RestClient("any url ");
var request = new RestRequest(Method.POST);
// I want change the value of this PostMe properties for few test cases. since it's a executed under"BaseTest" and called before any test so I am not sure how to change these properties "Name, ProxyUrl etc" according to test.
var postMe = PostMe;
}
}