2

I need to test this scenario with Webdriver using Java.

I open two browsers and go to the same URL in each browser.

driverOne;
driverTwo;

I login on driverOne browser as userOne and see the dashboard

I login on driverTwo browser as userOne, then perform some action.

I expect userOne to be logged off automatically from the driverOne browser and shown a message like "this session is invalid".

I don't know how to use Webdriver with Java to test this scenario.

  • 1
    It is always preferred that you tell what you want to do, what you have tried at your end, what is the issues(Error) that you faced. If possible the code and the exception. – Alok Jan 26 '17 at 8:59
  • 1
    I'm going to edit this post assuming that you want help testing that one user can only have one session open at any time. Feel free to revert my edits if that is not what you are asking. – Kate Paulk Jan 26 '17 at 13:46
1

Here is a sketch of the solution in Java:

WebDriver driver1 = new FirefoxDriver();
WebDriver driver2 = new FirefoxDriver();

login(driver1);
assertThat(driver1, canAccessProtectedPage());
assertThat(driver2, not(canAccessProtectedPage()));

login(driver2);
assertThat(driver2, canAccessProtectedPage());
assertThat(driver1, not(canAccessProtectedPage()));

You may want to add additional timeouts and waits until a user is logged out in first browser (driver1) before you check access.

0

The only possible way I can think is using TestNG priority, groups and dependsOnGroups properties.

You'll have to run the full group for this works and you'll need to have at least two test on the LoginTest. Without the second test, LoginTest will close after the validateLogin finish and validateSession will fail.

The code below will follow the execution:

  1. Will start LoginTest and SessionTest suites
  2. Test "validateLogin" and "validateSession" will start first since it has priority = 1
  3. But "validateSession" will wait "validateLogin" because it dependsOnGroups = "smoke"
  4. When "validateLogin" finish, "validateSession" will start
  5. Test "validateLoginStuff2" will wait "validateSession" because it dependsOnGroups = "session"
  6. When "validateSession" finish "validateLoginStuff2" will start and the session validation will be done.

public class LoginTest{

WebDriver driver;

@beforeClass

protected void beforeClass() {driver = new FirefoxDriver();
driver.get("www.url.com");
}

  @Override
  protected void afterClass() { 
      driver.quit();
  }

  @Test(priority = 1, groups = {"smoke", "full"})
  public void validateLogin() {
    //do login stufs
  }

  @Test(priority = 2, groups = {"full"}, dependsOnGroups = "session")
  public void validateLoginStuff2() {
    //do login stuff2 validation
  }
}

public class SessionTest{

  WebDriver driver;

  @beforeClass
  protected void beforeClass() {
    driver = new FirefoxDriver();
  }

  @Override
  protected void afterClass() { 
      driver.quit();
  }

  @Test(priority = 1, groups = {"session", "full"}, dependsOnGroups = "smoke")
  public void validateSession() {
    //do validate session things
  }
}
-1

I think rather using two browsers ,use a one browser with two tabs. Because you are trying to deal with sessions. So i dont think 1st browser session will override with some other browser's session.

  • 1
    -1 because it depends how session is represented but the most common way is a session cookie. Tabs of the same browser instance share cookie store so that would be a different scenario. – dzieciou Jun 25 '17 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.