Page tree
Skip to end of metadata
Go to start of metadata

Last updated: Nov 25, 2019 14:51

During desktop web tests, when you need to authenticate, the security pop-ups can be automated using the following code examples:

Internet Explorer 11 & Edge
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
            
try {
            
driver.get("LOGIN_ADRESS_HTTPS_URL");
                           
      } catch (Exception e) {
                           
String indentifier = "Windows Security";
String user = "USERNAME";
String pass = "PASSWORD";
                     
Map<String, Object> params = new HashMap<>();
params.put("label", indentifier);
driver.executeScript("mobile:button-text:click", params);
params.clear();
params.put("label", indentifier);
params.put("text", user);
driver.executeScript("mobile:edit-text:set", params);
params.clear();
params.put("label", "Password");
params.put("ignorecase", "case");
driver.executeScript("mobile:button-text:click", params);
params.clear();
params.put("label", indentifier);
params.put("text", pass);
driver.executeScript("mobile:edit-text:set", params);
params.clear();
params.put("label", "OK");
driver.executeScript("mobile:button-text:click", params);
                     
     }     
FireFox
driver.manage().window().maximize();
driver.get("LOGIN_ADRESS_HTTPS_URL");

driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

String user = "USERNAME_VALUE";
String pass = "PASSWORD_VALUE";

Map<String, Object> userParam = new HashMap<>();
userParam.put("label", "username");
userParam.put("text", user);
userParam.put("label.direction", "above");
userParam.put("label.offset", "35");
userParam.put("timeout", "20");
String res = (String) driver.executeScript("mobile:edit-text:set", userParam);
if (res.equals("false"))
{
    throw new Exception("Cannot populate/find username field");
}

driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

Map<String, Object> passParam = new HashMap<>();
passParam.put("label", "password");
passParam.put("text", pass);
passParam.put("label.direction", "above");
passParam.put("label.offset", "70");
passParam.put("timeout", "20");
String res1 = (String) driver.executeScript("mobile:edit-text:set", passParam);
if (res1.equals("false"))
{
    throw new Exception("Cannot populate/find password field");
}

driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

Map<String, Object> params2 = new HashMap<>();
params2.put("label", "OK");
params2.put("threshold", 80);
params2.put("operation", "single");
driver.executeScript("mobile:button-text:click", params2);