0

My code is(I replace actual URL with ../../../).

[TestInitialize] public static void Initalize() { AppiumOptions desiredcap = new AppiumOptions(); desiredcap.AddAdditionalCapability("app", @".../../../..../"); driver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), desiredcap); if (driver == null) { Console.WriteLine("App not running"); return; } } 

I want to make URL dynamic of

desiredcap.AddAdditionalCapability("app", @".../../../..../"); 

because i want to use this method in different project. Is it possible to write variable url instead of ../../../ and take url value from some other file or from Testcase.

1 Answer 1

2

So, you can create base class with Initalize(string capUrl) method and call it in derived classes as here:

 [TestInitialize] public static void Initalize() { base.Initalize("http://SomeUri.com") } 

If you need to specify it in Testcase. Then you need to remove [TestInitialize] and it's better to rename it to something like "PrepareTest". And call it by hands in test method. Like this:

[Testcase("http://SomeUri.com")] public void TestMethod(string uri) { this.PrepareTest(uri); } 

Is this solution helps you? Or you need something other?

Sign up to request clarification or add additional context in comments.

4 Comments

So we cannot pass URL variable directly in [TestIntialize] Method.???
No. TestInitialize should setup things that common for all tests. In your case you can use DataDrivenTest (learn.microsoft.com/en-us/visualstudio/test/…) or TestContext (learn.microsoft.com/en-us/dotnet/api/…)
But I recomend you to use separate classes that extends base class. Then you will split a lot of tests to different groups and split it to different files.
I get you. Now i have used SetURL and GetURL property and use this properties in My [TestInitialize] Method.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.