Instance of Cucumber Selenium WebDriver Java union:
In the prior lesson, we delved into the Cucumber instrument, its functionality, and its miscellaneous attributes.
Recommended IPTV Service Providers
- IPTVGREAT – Rating 4.8/5 ( 600+ Reviews )
- IPTVRESALE – Rating 5/5 ( 200+ Reviews )
- IPTVGANG – Rating 4.7/5 ( 1200+ Reviews )
- IPTVUNLOCK – Rating 5/5 ( 65 Reviews )
- IPTVFOLLOW -Rating 5/5 ( 48 Reviews )
- IPTVTOPS – Rating 5/5 ( 43 Reviews )
Building upon our extensive Selenium online education sequence, we will now delve into how to set up a cucumber project and meld Selenium WebDriver with Cucumber.
We will establish a Maven project for Cucumber. Kindly look at this Maven lesson from the very series for establishing Maven on your computer.
Configuring a Cucumber Scheme
Procedure #1: Create a Fresh Maven Approach:
Right Click -> New -> Others -> Maven -> Maven Scheme -> Next
Procedure #2: Following this, the scheme will surface as shown below:
Procedure #3: Incorporate the subsequent dependencies to the pom.xml archive
<dependencies> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-java</artifactId> <version>1.0.2</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-junit</artifactId> <version>1.0.2</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> </dependencies>
Procedure #4: Create a sample.feature archive beneath src/test/resources.
@smokeTest
Characteristic: Verifying if my cucumber test is functioning
I desire to execute a sample characteristic file.
Circumstance: Configuring cucumber
Given a sample characteristic archive is prepared
When I execute the characteristic archive
Then the execution should be triumphant
Procedure #5: Formulate a class beneath src/test/java and establish all the stages in this class.
public class stepDefinition { @Given("^sample feature file is ready$") public void givenStatement(){ System.out.println("Given statement executed successfully"); } @When("^I run the feature file$") public void whenStatement(){ System.out.println("When statement executed successfully"); } @Then("^run should be successful$") public void thenStatement(){ System.out.println("Then statement executed successfully"); } }
Procedure #6: Formulate a JUnit runner to execute the assessments.
@RunWith(Cucumber.class) @Cucumber.Options(format={"pretty","html:reports/test-report"},tags= "@smokeTest") public class CucumberRunner { }
Designate the direction of the report as shown above. The reports will be accumulated in the ‘test-report’ directory beneath the scheme directory and the “pretty” format establishes the kind of report.
Procedure #7:: Junit Result and Assessment Report:
The snapshot beneath displays the report for a successful cucumber test. The green bar in Junit indicates a passed test, while a red bar indicates a failed test.
If you desire to utilize the default reporting, steer to the path suggested in the JUnit Runner. In this context, the path is reports->test-reports->index.html.
Unlock this report in Internet Explorer or Firefox to authenticate the results. Here is a sample display of the report:
Cucumber Selenium WebDriver Union
The Cucumber framework can be utilized to evaluate web-centered applications along with Selenium WebDriver. The evaluation instances are inscribed in straightforward characteristic archives that can be effortlessly comprehended by project managers, non-technical shareholders, and business evaluators. These feature archive stages are then instigated in the stage elucidation archive. If you are utilizing Maven, you need to tag on dependencies for Cucumber and WebDriver.
Displayed below is a sample evaluation instance established employing Cucumber and WebDriver. As shown beneath, the circumstance in the characteristic archiving is self-explanatory.
Characteristic: Login Characteristic Archive
@selenium
Circumstance: Scrutinize login functionality for Gmail
Given navigate to the Gmail webpage
When the adherent logs in exploiting the username ‘userA’ and the code ‘password’
Then the home webpage should be demonstrated
WebDriver Imposition in Cucumber stepDefinitions:
public class stepDefinition { WebDriver driver; @Given("^navigate to gmail page$") public void navigate(){ driver = new FirefoxDriver(); driver.get("http://www.gmail.com"); } @When ("^user logged in using username as "(.*)" and password as "(.*)"$") public void login(String username, String password){ driver.findElement(By.xpath("//*[@id='Email']")).sendKeys(username); driver.findElement(By.xpath("//*[@id='Passwd']")).sendKeys(password); driver.findElement(By.xpath("//*[@id='signIn']")).click(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); } @Then("^home page should be displayed$") public void verifySuccessful(){ String expectedText="Gmail"; String actualText= driver.findElement(By.xpath("//*[@id='gbq1']/div/a/span")).getText(); Assert.assertTrue("Login not successful",expectedText.equals(actualText)); } }
In this scrutiny, we deployed Firefox as the browser to test the Gmail login functionality.
The WebDriver object is a class variable and is deployed throughout the class.
The Given pronouncement commences the browser and steers to the webpage.
The When pronouncement logs into the application employing the username ‘userA’ and code ‘password’. Both values are retrieved from the characteristic archive and should be utilized in the same succession.
The Then pronouncement authenticates the prerequisites after logging into the application.
This is a sample scrutiny corroborating the utilization of Cucumber and Selenium. Based on your scheme requisites, you can fabricate a multi-layered architecture.
Rounding up:
In this Cucumber Selenium Java union Lesson, we grazed over a miscellany of Cucumber theories, including Cucumber and its union with WebDriver.
This technique minimizes the intricacy of code essential for designing established frameworks like Keyword Driven and Hybrid Frameworks. Cucumber is extensively applied in projects where the agile methodology is followed, as Behaviour Driven Development is an essential facet of Agile Software methodology.
Following Lesson #32: We have now finished all technical lessons from this Selenium education sequence. Up next, we will cover crucial broad themes like ‘agreement approximation for Selenium schemes’ and ‘responding Selenium interview questions.’
If you have any inquiries concerning the Cucumber Selenium Lesson, kindly don’t hesitate to inquire.