Automate login for desktops

During desktop web tests, when you need to authenticate, the browser's user/password security pop-up windows can be automated using the following code examples:

Copy
Internet Explorer 11 and 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);
                     
     }     
Copy

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);