-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MFA handling script in Selenium (#438)
Add selenium script to fill in fixed OTP. Signed-off-by: Najam Ul Saqib <[email protected]>
- Loading branch information
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
This script will fill the OTP if MFA is configured on web-app. Browser-based auth is the pre-requisite for this script. | ||
You need to analyze DOM of the web app this script needs to run on and modify the parameters accordingly. | ||
This script assumes that the web app has fixed OTP for testing which can be stored in the variable below. | ||
*/ | ||
|
||
function browserLaunched(utils) { | ||
var By = Java.type("org.openqa.selenium.By"); | ||
var Thread = Java.type("java.lang.Thread"); | ||
var url = utils.waitForURL(5000); | ||
var wd = utils.getWebDriver(); | ||
var OTP = "123456"; | ||
|
||
wd.get(url + "#/login"); | ||
Thread.sleep(30000); //Wait for ZAP to handle the auth. | ||
wd.findElement(By.id("one-time-code")).sendKeys(OTP); //Replace the input field as per your web-app's DOM | ||
Thread.sleep(1000); | ||
wd.executeScript("document.querySelector('[aria-label=\"Verify Code\"]').click()"); //Replace the submit label as per your web-app's DOM | ||
} |