From today I am going to give basic concept on automated functional testing using Geb and Selenium.Today I am going to explain Selenium concept and in next session I will explain Geb and how to use Selenium in Geb. First-of-all be clear that Selenium and Geb are used for automated functional testing.
To use Selenium just put the plug-in in BuildConfig.groovy:
1 2 3 4 5 6 7 8 9 10 |
[php] dependencies { compile org.seleniumhq.selenium:selenium-chrome-driver:2.3.0; compile org.seleniumhq.selenium:selenium-firefox-driver:2.39.0; } [/php] |
Now just make a functional testing class as defined below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
[php] import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.Assert; public class SampleTestSpec{ public static void main(String[] args) { WebDriver d1 = new FirefoxDriver(); //defined the webdriver d1.get("http://www.google.com"); // fetched the URL try { Thread.sleep(1000); //told browser to sleep for 1000 millisecond } catch (InterruptedException e) { e.printStackTrace(); }; d1.findElement(By.className("gbqfif")).sendKeys("facebook"); //setting text in text-field of Google d1.findElement(By.id("gbqfba")).click(); //clicking on search button } } [/php] |
Here I have used java code you could use any programing language which are supported by Selenium and Geb.
Here is the resultant screen when we run the SampleTestSpec.In next session I will explain you how to use Selenium via Geb.
Recent Comments