Adding to the answer from @ gaspar-nagy This follows the design of the class in C programming. In any case, the common group of classes has common properties / methods, these properties / methods can be reorganized into a base class.
In our SpecFlow tests, it looks like this: common browser functions are in the base classes:
Login() Logout() NavigateToUrl(string url) UserHasPermission(string permission) WaitForElementToAppearById(string id) WaitForElementToAppearByClass(string class)
And each of these methods can have 1 or more Given / When / Then attributes, indicated as @ gasper-nagy.
Another method that is invaluable is to share variables between .features and their corresponding C # step files to use ScenarioContext.
For example, whenever Login() is called to initiate our browser-based tests, we do the following:
ScenarioContext.Current.Set<IWebDriver>(driver, "driver")
Then in any other place where you need a driver, you can get it:
var driver = ScenarioContext.Current.Get<IWebDriver>("driver")
This leads to the reuse of steps, for example, to custom input tests for validation, which you can take to pass the element to be checked as follows: ScenarioContext.Current.Set<IWebElement>(element, "validation-element")
jmb.mage
source share