如何更改在BaseTest下调用的类的属性值 - 设置方法

时间:2018-03-13 16:43:42

标签: c# selenium-webdriver nunit

资源:c#,Nuniut,Selenium,VS 2017,restSharp

1)这是我的测试类,继承了BaseTest类。

[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)这是" TokenRequest"方法下的课程" TokenGenerate"我感兴趣的是。

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;            
    }
}    
this is expected value for any test :
PostMe class is define with these properties separately in the project.

var postMe = new PostMe()
                {
                    Name = "ABC ABC",
                    ManagementId = "ABC ABC",                
                    ProxyUrl = ABC,
                    SourceFilename = ABC,
                };

but what I want for few test cases is :

var postMe = new PostMe()
                {
                    Name = "ABCDEF ABCDEF ABCDEF ABCDEF  ",
                    ManagementId = "ABCDEF ABCDEF ABCDEF  ",                
                    ProxyUrl = ABCDEF  ABCDEF ABCDEF ,
                    SourceFilename = ABCDEF  ABCDEF ABCDEF ,
                };

请让我知道解决方案或不同类型的实施。

1 个答案:

答案 0 :(得分:1)

如何将TokenRequst更改为:

screen turn off