This test opens a demo page, right-clicks a button, and checks if the context menu appears.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class ContextClickTest {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
try {
driver.get("https://swisnl.github.io/jQuery-contextMenu/demo.html");
WebElement button = driver.findElement(By.cssSelector("span.context-menu-one.btn.btn-neutral"));
Actions actions = new Actions(driver);
actions.contextClick(button).perform();
WebElement menu = driver.findElement(By.cssSelector("ul.context-menu-list.context-menu-root"));
if(menu.isDisplayed()) {
System.out.println("Context menu appeared - Test Passed");
} else {
System.out.println("Context menu did not appear - Test Failed");
}
} finally {
driver.quit();
}
}
}