"EXECUTE_JAVA" Command

Description: This command makes a call to a snippet of Java/Selenium/Appium code you have written and uploaded to Subject7. Method field specifies the function/method to call in the code written.

Usage Scenarios:

A- Suppose we want to register on Reference app using a randomly generated password.

Procedure: Create a snippet that uses Java code to generate a random password. In your command options, enter the method “generate” which will automatically generate a random password for use in the registration. Your step will look like this:

B- Suppose we want to use Execute_Java to click on Register button.

Procedure: Create a snippet where Selenium files (.jar) are used as dependencies. In your command options, enter the method “clickRegisterButton” which will simulate clicking on the Register button. Your step will look like this:

Attachments and source code:

com.subject7.PasswordGenerator:

import java.util.Map; public class PasswordGenerator { private Map<String, String> parameterMap; public void setParametersMap(Map<String, String> parameterMap) { this.parameterMap = parameterMap; } public String generate() { String password = "5a8bxzFQxtRjY2zp"; parameterMap.put("@generated_password", password); return "PASS,Password generated successfully."; } }

com.subject7.WebAssistant:

import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import java.util.Map; public class WebAssistant { private WebDriver webDriver; private Map<String, String> parameterMap; public void setParametersMap(Map<String, String> parameterMap) { this.parameterMap = parameterMap; } public void setWebDriver(WebDriver webDriver) { this.webDriver = webDriver; } public String clickRegisterButton() { try { String registerButtonXpath = parameterMap.get("@registerButtonXpath"); WebElement element = webDriver.findElement(By.xpath(registerButtonXpath)); element.click(); } catch (Exception e) { return "FAIL," + e.getMessage(); } return "PASS,Clicked."; } }