How to create a reusable method outside the test case ?


#1

Is it possible to create a class with some methods outside the test cases and call them in test cases…? I see that it is possible to create methods inside the test case and use them in that specific test case, but I’d like to know how can these methods be reused in other test cases…? Is it possible to write those methods outside the test cases (tried CustomKeyWord, but didnt help)…?


#2

Custom Keywords are exactly what you’re asking for. But you only need the mechanism you use to create them (you don’t need make actual Keywords - read on)

Here’s a quick list of things you need:

1 - make your methods static.

static String myCoolStringMethod(String s, …) { … }

2 - don’t bother adding @Keyword – it’s not needed.

3 - in your test case, import your class file static too.

- static import my_stuff

4 - in your test case, call your method(s)

my_stuff.myCoolStringMethod(“Wow!” …)

5 - search the hell out of this forum. I’ve posted a ton of this stuff somewhere here.


#3

Thank you Russ, it worked for me…!!!


#4

Glad it worked for you, Qaddaffi.

Now you need to complete your task and make my answer the Best Answer -- there are good reasons to do so:

1 - When other people see this thread in the list, they will notice it has an actual Answer that works. Otherwise it just looks like a discussion with no answer yet.

2 - Giving it the Best Answer also…

  • makes me feel good the entire day
  • makes my head grow even bigger than it already is (it weighs a ton!)
  • gives me bragging rights and
  • lets me walk around here like I own the place.

Your call B)


#5

Gotcha…!!!


#6

B)