3

I'm trying to pass username and passwords in different combinations (valid-valid, valid-invalid, invalid-valid, invalid-invalid) and have them assigned to String variables userName and password and have used a parameterized class.

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

@SuppressWarnings("deprecation")
@RunWith(Parameterized.class)
public class FunctionalTestCaseActiTimeParameterization {

    Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox","http://localhost/login.do");

    String userName;
    String password;

    public FunctionalTestCaseActiTimeParameterization(String userName, String password){
        this.userName = userName;
        this.password = password;
    }

    @Parameters
    public static Object[][] getData(){
        return new Object[][]{
            {"admin","manager"},
            {"admin","test"},
            {"test","manager"},
            {"test","test"}
        };
    }

    @Before
    public void openApplication(){
        selenium.start();// start interaction with proxy server
        selenium.open("/");// to open application
        selenium.windowMaximize();// to maximize the window
        selenium.windowFocus();// to focus on current window
    }

    @After
    public void closeApplicaton() throws InterruptedException{
        Thread.sleep(5000);
        selenium.close();// close window
        selenium.stop();// stop interaction with server
    }

    @Test
    public void mainTestMethodLoginLogout() throws InterruptedException{
        selenium.type("//input[@id='username']", userName);
        selenium.type("//input[@type='password']", password);
        Thread.sleep(3000);
    }
}

and i didn't get any errors or warnings (I've used parameterized but not inside a function so getting a little confused about how to use it inside the type function, when run the code gives failure (no error).

I'd be glad if some one can point me in the right direction.

ParkerHalo
  • 4,341
  • 9
  • 29
  • 51
Lau Xing
  • 31
  • 3
  • 1
    I know this doesn't answer your question, but why are you doing new work using Selenium RC? It's been deprecated for years: http://stackoverflow.com/q/10779571/954442 – Andrew Regan Feb 01 '16 at 10:26
  • i know. i'm trying to learn webdriver but learning the whole selenium from scratch including rc so that when selenium 3 comes i can learn it easily – Lau Xing Feb 01 '16 at 10:29
  • AFAIK, the RC api is just going in the trash, so I'd really concentrate on WebDriver only. – Andrew Regan Feb 01 '16 at 10:34
  • so is it completely useless to learn how to pass values from a parameterized to inside a function ? – Lau Xing Feb 01 '16 at 10:41
  • No, it's a good question in a way, just try to switch to the WD API. Doesn't affect the answer I've given. – Andrew Regan Feb 01 '16 at 10:42

2 Answers2

0

I think the two-dimensional array approach is a mistake, because looking a little further you need to associate your {username:password} combinations with expected outputs.

Perhaps the expectation only needs to be a boolean ("OK" vs "Not OK"), in which case you could use a List<MyTestSpec> where MyTestSpec comprises {username, password, wasOK} - but you probably have additional needs, e.g. checking successful login redirects to profile page for different user-levels, checking different types of login failure.

You should really start out by having a separate, distinct @Test for each scenario and make each one as comprehensive and detailed as it should be.

Worry about refactoring your Selenium API logic (creating helper functions etc.) only once you have made your failing tests pass and you have locked-down your expectations.

Note that the same applies whether using Selenium's RC or WebDriver API.

Andrew Regan
  • 5,087
  • 6
  • 37
  • 73
  • i have already done the program as you have described (4 test cases, boolean o/p and printing the warning if got any or succesful page redirect) but this was given as a challenge to our creativity and were also asked to get it by any means necessary (googling, asking in forums, stealing from people who have already done it etc., (i know the last one is ridiculous) ) and were told this was not a programming ability test rather a different one and we will get to know why we were asked to do it only after we do it !! – Lau Xing Feb 01 '16 at 10:48
  • i tried the "let me do it on my own" but have gotten stuck! – Lau Xing Feb 01 '16 at 10:49
  • oh! and we are not allowed to even think about collections forget using them – Lau Xing Feb 01 '16 at 10:56
0

I found the problem myself. The code i posted was actually correct but it was not accepting the parameter because i was calling parameters before the page loaded completely. adding a Thread.sleep(2000); resolved the problem. Thank you for whomever tried..

Lau Xing
  • 31
  • 3