0

I have class Login.

public class Login
{
private WebDriver driver;

@Beforetest
public void SetUp()
{
doingsmth();
//How to do this?
driver = FirefoxDriver or Chromedriver depending on smth.
}

@test
public void loginFirefox_a(){}
@test
public void loginFirefox_b(){}
@test
public void loginFirefox_c(){}
@test
public void loginFirefox_d(){}
@test
public void loginChrome_a(){}
@test
public void loginChrome_b(){}
@test
public void loginChrome_c(){}
@test
public void loginChrome_d(){}
}

I know I somehow can use parametrized, but don't know how to use it (f.e how test recognise param name?) Any help will be appreciated.

atish shimpi
  • 4,873
  • 2
  • 32
  • 50
user2678074
  • 768
  • 3
  • 9
  • 22

2 Answers2

0

Basically you can pass FirefoxDriver or Chromedriver as a run time custom parameter while running junit class. Ex : -Ddriverclass="FirefoxDriver". In doingsmth you can get the driver value by System.getProperty("driverclass").

How to pass the -D System properties while testing on Eclipse?

Pass command line arguments to JUnit test case being run programmatically

Community
  • 1
  • 1
  • Not in this case, cose value for first 4 tests has to be different than for 4 next, like driver=firefoxDriver(); run first 4 tests; driver=ChromeDriver; run next 4 tests. – user2678074 Jan 28 '15 at 16:53
0

Either one of these:

You can use the Parameterized runner, more here https://github.com/junit-team/junit/wiki/Parameterized-tests

If you're familiar with Guice I would use Jukito with @All, more https://github.com/ArcBees/Jukito/wiki/@All

Lev Kuznetsov
  • 3,520
  • 5
  • 20
  • 33
  • I read your question as testing for all possibilities, as in both Chrome and Firefox, is that what you want? – Lev Kuznetsov Jan 27 '15 at 13:57
  • I want to make two collections of tests, and assign every one of them separate setUp methods. So, for Chrome tests i need driver=ChromeDriver() and for Firefox i need driver = FirefoxDriver() – user2678074 Jan 28 '15 at 16:37
  • about your links, could you write an example for assigning different drivers using Parametrized runner? Example from link uses square table for fibonnacci and it is completly not readable for me. I nned smth simpler like passing one boolean or one String variable. – user2678074 Jan 28 '15 at 16:42
  • Their example is as simple as it gets. It has nothing to do with Fibonacci in particular. The static function annotated with `@Parameters ` returns an `Iterable` over construction parameters passed to `FibonacciTest`. So in this case the framework will create 8 instances first passing 0, 0 then 1, 1 next 2, 1 and so on. Then it will invoke all methods annotated with `@Test` on each created instance. – Lev Kuznetsov Jan 28 '15 at 16:59