Show Table of Content

Executing Custom Selenium Code

If needed, Screenster can run custom Selenium code on locally installed servers and private cloud instances. By running custom Selenium code, you can add additional functionality to your Screenster tests. To do this, click to add a new step in the “Test commands” menu and select “Execute Selenium code” in the “Type” dropdown:

Important: remember that adding Selenium code can change the flow of your current test. The executed code can break the overall flow of your existing test.
Simple code that checks a custom attribute of an element and if the attribute is wrong then breaks the test through SeleniumException:

package commands;
import com.agileengine.screenster.logic.browsers.Browser;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import com.thoughtworks.selenium.SeleniumException;
import java.util.concurrent.TimeUnit;

public class SeleniumCommand {
 /* Main entry point, don’t rename this method, class and package */
 public void run(WebDriver driver, Browser browser) throws Exception {
 // TODO Auto-generated method stub, put your code here
  myCustomMethod(driver);
 }
 public void myCustomMethod(WebDriver driver) throws Exception {
  TimeUnit.SECONDS.sleep(10);
  WebElement element = driver.findElement(By.id(“divWithCustomAttribute”));
  String attributeValue = element.getAttribute(“customAttribute”);
  if(!”0″.equals(attributeValue)) {
   throw new SeleniumException(“Wrong custom attribute”);
  }
 }
}



Visit the Release History page to check what is new and what has been improved in your current Screenster version.



 

Want to try Screenster on the cloud?

Try Online


 

WordPress Image Lightbox Plugin