-1

I am working on automation of a website in which I need to perform some action using user A then user B needs to approve the same.

By default the web-application takes credentials from the windows login itself as there is no login page for this.

So What I did was, I automated all the actions from user A. Now to perform the action from user B ,I created a .vbs utility which I am calling in my java code, this utility opens a web browser and sign into the application with user B (I used shell scripting in vbs for this). Now I have two web browser one which is opened by webdriver (On which I performed some action with User A) and the other which has been opened by the vbs utility(I need to perform some action on this browser) and since my second browser is not opened by Webdriver I am searching a way to attach it to webdriver so that I can perform some actions on it & approve the request created by User A.

Additional Information: I need to perform this in IE since this is client requirement. I am using java for selenium.

ankur
  • 1
  • 1

1 Answers1

0

From reading your question, I believe that you are tackling your problem incorrectly. Since I cannot tell what sort of authentication you are dealing with in your browser, I suppose I can show you a form and HTTP 401, which will most likely cover the general scenarios. If you need some other example, for a different way to authenticate, do let us know.

If I have misread your request, and you actually want to hook onto a manually started instance of a browser, which is not provided by default, you have to get really creative. Regardless, that question is answered here.

However, as far as my recommendation goes, I would highly recommend that you get rid of that vb script / manual browser starting if possible. If you can authenticate through your browser, than you can do it through selenium. Here are some examples:

Note, this is a good guide on how to use the InternetExplorerDriver

Scenario 1: Using an HTML Form Sample HTML Code:

<form>
    <table id="credentials_table">
    <tbody>
    <tr>
        <td class="credentials_table_label_cell"><label for="username" id="label_input_1">Username</label></td>
        <td class="credentials_table_field_cell"><input class="credentials_input_text" value="" id="username" autocomplete="off" autocapitalize="off" type="text"></td>
    </tr>
    <tr>
        <td class="credentials_table_label_cell"><label for="password" id="label_input_2">Password</label></td>
        <td class="credentials_table_field_cell"><input class="credentials_input_password" value="" id="password" autocomplete="off" autocapitalize="off" type="password"></td>
    </tr>
    <tr id="submit_row">
        <td class="credentials_table_field_cell"><input class="credentials_input_submit" value="Logon" type="submit"></td>
    </tr>
    </tbody></table>
</form>    

Sample Selenim Code to Login:

private WebDriver driverForA = new InternetExplorerDriver();
private WebDriver driverForB = new InternetExplorerDriver();

@After
public void after() {
    driverForA.close();
    driverForB.close();
}

@Test
public void testADoesThisAndBDoesThat() {

    driverForA.get("http://my.login.url");
    final WebElement usernameInput = driverForA.findElement(By.id("username"));
    final WebElement passwordInput = driverForA.findElement(By.id("password"));
    final WebElement submitButton = driverForA.findElement(By.xpath("//input[@type='submit' and @value='Logon']"));
    // perform the login stuff
    clearKeysAndSetValue(usernameInput, "Joe");
    clearKeysAndSetValue(passwordInput, "superSecret");
    submitButton.click();
    // navigate to other pages and do things

    driverForB.get("http://my.approval.page");
    final WebElement approveButton = driverForB.findElement(By.id("approval_Button"));
    approveButton.click();

}

private void clearKeysAndSetValue(final WebElement element, final String valueToSet) {
    element.clear();
    element.sendKeys(valueToSet);
}

Scenario 2: Using HTTP 401

private final WebDriver driverForA = new InternetExplorerDriver();
private final WebDriver driverForB = new InternetExplorerDriver();

@After
public void after() {
    driverForA.close();
    driverForB.close();
}

@Test
public void testADoesThisAndBDoesThatHttpBasic() {
    // authenticate as a
    WebDriverWait wait = new WebDriverWait(driverForA, 5);      
    Alert alert = wait.until(ExpectedConditions.alertIsPresent());     
    alert.authenticateUsing(new UserAndPassword("Joe", "superSecret"));
    // navigate to other pages and do things

    driverForB.get("http://my.approval.page");
    final WebElement approveButton = driverForB.findElement(By.id("approval_Button"));
    approveButton.click();
}
Community
  • 1
  • 1
angryip
  • 2,140
  • 5
  • 33
  • 67