I am a bit new to eclipse and the cucumber/selenium combo. I have three files: a feature, a TestRunner, and the stepDefintion file. I would like to be able to run these files outside of the eclipse IDE. I need to be able to run these tests on a different computer that does not have Eclipse or access to external websites, only the one that will be tested. I've included code for the three sample files (this does not include the proper URL or credentials). I would like to make this somehow executable, however I know that lacking a main method, I can't run this as a Jar.
Feature:
Feature: Login Action
Scenario: Successful Login with Valid Credentials
Given User is on Home Page
When User enters "maximo" and "source1"
Then Message displayed Login Successfully
Scenario: Successful LogOut
When User LogOut from the Application
Then Message displayed LogOut Successfully
TestRunner
package cucumberTest;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
features = "Feature"
,glue={"stepDefinition"}
, monochrome = true
, plugin = {"pretty"}
)
public class firstTestCase {
}
And the actual Step Definitions
package stepDefinition;
import java.util.concurrent.TimeUnit;
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;
import org.openqa.selenium.support.ui.WebDriverWait;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class Test_Steps {
public static WebDriver driver;
private String baseUrl;
static WebDriverWait wait;
#Given("^User is on Home Page$")
public void user_is_on_Home_Page() throws Throwable {
System.setProperty("webdriver.chrome.driver",
"C:\\Selenium\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
baseUrl = "https://maximo-demo76.mro.com/";
wait = new WebDriverWait(driver, 60);
driver.get(baseUrl + "/maximo/webclient/login/login.jsp?welcome=true");
}
// #When("^User Navigate to LogIn Page$")
// public void user_Navigate_to_LogIn_Page() throws Throwable {
// driver.findElement(By.xpath(".//*[#id='account']/a")).click();
// }S
#When("^User enters \"(.*)\" and \"(.*)\"$")
public void user_enters_UserName_and_Password(String realUsername, String realPassword) throws Throwable {
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys(realUsername);
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys(realPassword);
driver.findElement(By.id("loginbutton")).click();
}
#Then("^Message displayed Login Successfully$")
public void message_displayed_Login_Successfully() throws Throwable {
System.out.println("Login Successfully");
}
#When("^User LogOut from the Application$")
public void user_LogOut_from_the_Application() throws Throwable {
WebElement logOut =
driver.findElement(By.id("titlebar_hyperlink_8-lbsignout_image"));
Actions actions = new Actions(driver);
actions.moveToElement(logOut).click().perform();
}
#Then("^Message displayed LogOut Successfully$")
public void message_displayed_LogOut_Successfully() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("LogOut Successfully");
}
}
Related
I have written a step definition file but still its not getting identified,below is my feature,step definition,Runner file.
Feature: Google Search feature
Scenario: To verify search bar functionality
Given user is on google search page
When user enters a search keyword in a search bar
And user clicks on Enter keyboard button
Then search results are displayed
Then Close the browser
package com.mavenDemo;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class StepDefination {
WebDriver driver;
#Given("^user is on google search page$")
public void user_is_on_google_search_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.setProperty("webdriver.chrome.driver", "F://chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.google.com");
}
#When("^user enters a search keyword in a search bar$")
public void user_enters_a_search_keyword_in_a_search_bar() throws Throwable {
driver.findElement(By.name("q")).sendKeys("Test");
}
#And("^user clicks on Enter keyboard button$")
public void user_clicks_on_Enter_keyboard_button() throws Throwable {
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
}
#Then("^search results are displayed$")
public void search_results_are_displayed() throws Throwable {
boolean searchText = driver.findElement(By.xpath("//span[#class='wUrVib']")).getText().contains("Test");
Assert.assertTrue(searchText);
}
#Then("^Close the browser$")
public void close_the_browser() throws Throwable {
driver.quit();
}
}
package com.mavenDemo;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features =
"C:/Users/BR/workspace/com.mavenDemo/src/main/java/Login.features",
glue = {
"/com.mavenDemo/src/main/java/com/mavenDemo/StepDefination" })
public class TestRunner {
}
What Might be the reason to it not to recognize step definition file?
I have double checked the code but I am unable to find the solution also tried solution provided for similar problem but even that didn't work
Please help me in resolving this.
Thanks
I have found an answer!!
mistake was in a test runner file,while specifying a step definition path in glue we need to specify folder name not the test runner path,
Changed glue to
glue = {"com.mavenDemo" }
Thanks.
Please remove /com.mavenDemo from glue path
I am working on a Selenium testing framework tutorial of John Sonmez and ran into problem trying to perform the very first test. The test part consists of two methods: 1. LoginPage.GoTo(); which opens wordpress login page and 2. LoginPage.LoginAs("admin").Login(); which inserts username and clicks continue.
What happens when I run the test is wordpress loginpage opens and after 2 seconds blank Chrome browser opens and JUnit displays NoSuchElementException. The author of tutorial solved this problem adding some WebDriverWait and switchTo.ActiveElement.getAttribute() to LoginPage.GoTo(); method. However he is coding in C# and offers no solution for Java I'm coding in. I tried to apply WebDriverWait also but the problem is still there. Can anyone please suggest me how to solve this problem using WebDriverWait in Java.
LoginTest
import static org.junit.Assert.*;
import org.junit.Assert;
import org.junit.Test;
import wordpressAutomation.Driver;
import wordpressAutomation.LoginPage;
public class LoginTest extends Driver {
#Test
public void admin_user_can_login() {
LoginPage l = new LoginPage();
l.GoTo();
LoginPage.LoginAs("scenicrail").Login();
//Assert.assertTrue(DashboardPage.IsAt, "Failed to login");
}
}
LoginPage
import org.junit.Test;
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.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class LoginPage extends Driver {
#Test
public void GoTo() {
openBrowser().get("https://wordpress.com/log-in");
}
public static LoginCommand LoginAs(String username) {
return new LoginCommand(username);
}
}
public class LoginCommand extends Driver {
private String username;
private String password;
public LoginCommand(String username) {
this.username = username;
}
public LoginCommand WithPassword(String password) {
this.password = password;
return this;
}
public void Login() {
WebElement login = openBrowser().findElement(By.xpath("//*[#id='usernameOrEmail']"));
login.sendKeys(username);
openBrowser().findElement(By.xpath("//button[#type = 'submit']")).click();
}
}
public class Driver {
public WebDriver openBrowser() {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\KatarinaOleg\\Desktop\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
return driver;
}
}
After opening the page, where you get the NoSuchElementException you can add in something like this.
FluentWait<WebDriver> webDriverWait = new WebDriverWait(driver, 25).pollingEvery(5, TimeUnit.SECONDS);
webDriverWait.until(ExpectedConditions.visibilityOf(webElement));
Just add in whatever element you want to use as your check to make sure the page has loaded
you have called the Openbrowser multiple times in Login Method from LoginCommand Class.So, It will be unnecessarily create different driver instance. So, your code needs to be modified as below along with explicit wait (Driver Class also needs to be changed as below)
Login Method from LoginCommand Class:
public void Login() {
WebDriverWait wait=new WebDriverWait(driver,20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id='usernameOrEmail']")));
WebElement login = driver.findElement(By.xpath("//*[#id='usernameOrEmail']"));
login.sendKeys(username);
driver.findElement(By.xpath("//button[#type = 'submit']")).click();
}
Driver Class:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Driver {
WebDriver driver;
public WebDriver openBrowser() {
System.setProperty("webdriver.chrome.driver", "drivers/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
return driver;
}
}
Edit: (dmin_user_can_login() method in LoginTest class)
#Test
public void admin_user_can_login() {
LoginPage l = new LoginPage();
l.GoTo();
l.LoginAs("scenicrail").Login();
//Assert.assertTrue(DashboardPage.IsAt, "Failed to login");
}
LoginPage Class:
import org.junit.Test;
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.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class LoginPage extends Driver {
#Test
public void GoTo() {
openBrowser().get("https://wordpress.com/log-in");
}
public LoginCommand LoginAs(String username) {
return new LoginCommand(username);
}
}
I'm new with cucumber and learned this doc carefully to understand how could I implement my first cucumber java project. I have done a lot of analysis and gone through almost all the articles related to it over internet, why its not picking up step definition but could not find the cause. However, everything seems to be OK as per my understanding, I have great expectation that you guys can find my fault at one go.
Looking forward for a +ve response.
Hence I'm sharing the code, message(on console window) and folder structure.
Thanks
Rafi
Feature file:
#MyApplication
Feature: Post text Hello Rafi on Rafi facebook account
Scenario: Login successfully on Facebook application
Given Open Facebook application
When Enter valid id and password
And Click on Login button
Then Facebook home page should open
TestRunner class:
package test.java.runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
//glue = {"helpers", "src.test.java.steps"},
#RunWith(Cucumber.class)
#CucumberOptions(
features = {"src/features"},
glue = {"helpers", "src.test.java.steps"},
plugin = {"pretty","html:target/cucumber-html-report"},
dryRun = true,
monochrome = true,
tags="#MyApplication",
strict=false)
public class TestRunner {
}
StepDefinition class:
package test.java.steps;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class StepDefinition {
private static WebDriver driver = null ;
private static String password = "*********";
WebDriverWait wait=new WebDriverWait(driver, 30);
WebElement waitElement;
#BeforeClass
public void setup() throws Throwable
{
System.setProperty("webdriver.gecko.driver", "C:\\Selenium Automation\\selenium\\Selenium 3 and Firefox Geckodriver\\geckodriver.exe");
driver = new FirefoxDriver ();
driver.manage().window().maximize();
}
#AfterClass
public void teardown() throws Throwable
{driver.quit();}
// First scenario
#Given("^Open Facebook application$")
public void open_Facebook_application() throws Throwable{
System.out.println("this is not working");
driver.navigate().to("https://www.facebook.com/");
}
#When("^Enter valid id and password$")
public void enter_valid_id_and_password() throws Throwable{
driver.findElement(By.name("email")).clear();
driver.findElement(By.name("email")).sendKeys("rafiras16#gmail.com");
driver.findElement(By.name("pass")).clear();
driver.findElement(By.name("pass")).sendKeys(password);
}
#When("^Click on Login button$")
public void click_on_Login_button() throws Throwable {
driver.findElement(By.xpath("//input[starts-with(#id,'u_0')]")).click();
}
#Then("^Facebook home page should open$")
public void facebook_home_page_should_open() throws Throwable{
String strTitle = driver.getTitle();
System.out.print(strTitle);
}
}
image for message on console window and folder structure
BuildPath details
I think the glue attribute on the CucumberOptions class is wrong. If you want to refer to the step definitions using the file path then you need to change that to:
glue = {"helpers", "src/test/java/steps"},
If you want to refer them by package then you need to remove the "src." prefix:
glue = {"helpers", "test.java.steps"},
Try changing,
glue = {"helpers", "src.test.java.steps"}
to
glue = {"test.java.steps"}
And what is this helpers package i don't see it in the screenshot.
The #AfterClass and #BeforeClass annotations are useful only if the class is a junit test class. You have placed them in a normal class, thus they will not be run. This leads to the driver remaining uninitaialized.
The easy way out is to use the cucumber #Before and #After annotation. Change the #BeforeClass to #Before and #AfterClass to #After.
I have a question related to improving my Selenium Java code. I am really beginner in Java and Selenium either.
I have written a code which I got an example from the internet and adapted to my reality. The coding works fine as described below:
package test;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import page.Login;
public class LoginTest extends BaseTest {
Login login = new Login(driver);
#Test
public void loginWithSuccess() {
sendLoginData("my_user#something.com", "my_password");
login.clickLogin();
assertEquals("View Posted Jobs", login.checkLoginSuccess());
}
private void sendLoginData(String user, String password) {
login.sendUser(user);
login.sendPassword(password);
}
}
The above program is testing and performing a loginWithSucess in the WebSite
package config;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class WebDriverFactory {
public static WebDriver createFirefoxDriver() {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
return driver;
}
}
In this above example I am instancing a new object WebDriver called driver.
package test;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.openqa.selenium.WebDriver;
import config.WebDriverFactory;
public class BaseTest {
protected static WebDriver driver;
private static boolean setUpIsDone = false;
#BeforeClass
public static void setUp() {
if (setUpIsDone) {
return;
}
// Creating first browser for student login
driver = WebDriverFactory.createFirefoxDriver();
driver.get("http://test-tuitiondesk.rhcloud.com/auth");
driver.manage().window().maximize();
setUpIsDone = true;
}
The above example is where I open my WebSite to authenticate
package page;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class Login {
private WebDriver driver;
public Login(WebDriver driver) {
this.driver = driver;
}
public void sendUser(String user) {
driver.findElement(By.xpath("//*[#id='email']")).sendKeys(user);
}
public void sendPassword(String password) {
driver.findElement(By.id("password")).sendKeys(password);
}
public void clickLogin() {
driver.findElement(By.xpath("//*[#id='login-box']/div/div[1]/form/fieldset/div[2]/button")).click();
}
public String checkLoginSuccess() {
return driver.findElement(By.xpath("//a[contains(text(),'View Posted Jobs')]")).getText();
}
}
The above example I have methods which will send a user id and password to the webpage.
So far is everything working fine. The program is performing the following steps:
1 - Open the firefox
2 - Open the webpage
3 - Send the correct user_id, password and click in login button
4 - Check if login was performed with success.
My question now is that I need open a new firefox driver and login with different user_id and this new user_id will interact some actions with the first user_id, so I will need two browsers opened to perform actions with both users in the same time.
I would like to write this implementation the best way than simply write every method again with the second driver. What I thought for the first time was create a new WebDriver called driver2 and create again all methods referring to driver2, but I think I should reuse my methods and classes in a clever way.
Does Anybody have any idea how to implement this second browser in my code?
Thank you
André
You can do this simply by entering this code:
driver2 = WebDriverFactory.createFirefoxDriver();
driver2.get("http://test-tuitiondesk.rhcloud.com/auth");
//call log in function for driver2
//code to interact driver2 with driver1
Hi Guys I am following Page Object Model in Java with Cucumber.
I have following classes:
AbstractClass.java: Initiates the webdriver instance and serves as Master class for other object classes.
package ObjectRepository;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
/**
* Hello world!
*
*/
public class AbstractClass {
public static WebDriver driver=null;
Properties p = new Properties(); // create an object of properties
public AbstractClass(WebDriver driver){
this.driver=driver;
}
public void setup() throws IOException{
// file input stream obect
FileInputStream fi= new FileInputStream("C:\\Users\\sulemanmazhar\\Google Drive\\Automation Learning\\Java\\udemyWorkspace\\DebitCard_PageObject\\src\\test\\java\\Banking\\global.properties");
p.load(fi); // load the properties
if (p.getProperty("browser").contains("fireFox")){ // if browser in property file is firefox
driver=new FirefoxDriver();
};
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
public loginPage navigateToWelcomePage(){
String url=p.getProperty("url");
System.out.println(url);
driver.navigate().to(url);
return new loginPage(driver);
}
public String getTitle(){
String title= driver.getTitle().trim();
return title;
}
public void quitDriver(){
driver.quit();
}
}
loginPage.Java: Serves as Object repository class for login Page of my SUT. Inherits Abstract Class
package ObjectRepository;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
/**
* This class is within the object repository package
* This package will contain all the objects which will
* These objects will be stored and the will be accessed from the test/java folder
public class loginPage extends AbstractClass
public loginPage(WebDriver driver){
super(driver);
}
// all login page objects belong to this page
By username = By.name("userName"); // object
By password = By.name("password");
By name= By.name("login");
By registerLink = By.linkText("REGISTER");
By signInLink=By.linkText("SIGN-ON");
// constructor passes a webdriver object
public flightFinder login(String userId,String passw){
driver.findElement(username).sendKeys(userId);
driver.findElement(password).sendKeys(passw);
driver.findElement(name).click();
return new flightFinder(driver);
}
public registerPage navigateToRegister() {
driver.findElement(registerLink).click();
return new registerPage(driver);
}
public loginPage navigateToSignOn(){
driver.findElement(signInLink).click();
return new loginPage(driver);
}
}
I also have registerPage.java,flighFinder.java which serves the same purpose as loginPage.java
I have corresponding test classes for each of the classes. The two classes I want to discuss are:
stepsDefiniton.java : This class contains most of the common methods that are applicable across different classes.
package TestClasses;
import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import ObjectRepository.flightFinder;
import ObjectRepository.loginPage;
import ObjectRepository.registerPage;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class StepsDefinition {
WebDriver driver;
loginPage loginPage;
//flightFinder flightFinder;
registerPage registerPage;
#Before
public void setUp() throws IOException{
System.out.println("Executing before method");
loginPage = new loginPage(driver);
loginPage.setup();
loginPage.navigateToWelcomePage();
}
#After
public void CloseDriver(){
System.out.println("Executing after method");
loginPage.quitDriver();
}
/* Shared steps */
#Given("^I am on \"([^\"]*)\" page$")
public void i_am_on_page(String page) {
if(page.equalsIgnoreCase("sign-on")){
loginPage=loginPage.navigateToSignOn();
}
if(page.equalsIgnoreCase("register")){
registerPage=loginPage.navigateToRegister();
}
String Title =loginPage.getTitle();
System.out.println("Actual page title is :"+ Title+" Expected Title is :"+page);
Assert.assertTrue(Title.contains(page));
}
#When("^I click on \"([^\"]*)\" button$")
public void i_click_on_button(String button) {
if (button.equalsIgnoreCase("register")){
registerPage=loginPage.navigateToRegister();
}
else if(button.equalsIgnoreCase("sign-on")){
loginPage=loginPage.navigateToSignOn();
}
}
#Then("^I should be navigated to \"([^\"]*)\" page$")
public void i_should_be_navigated_to_page(String page) {
String Title =loginPage.getTitle().trim();
System.out.println("Actual page is :"+Title +" Expected page is :"+page);
Assert.assertTrue(Title.contains(page));
}
}
LoginTest.Java : Is the Test class contains the code to test the logiN Page.
package TestClasses;
import org.openqa.selenium.WebDriver;
import ObjectRepository.flightFinder;
import ObjectRepository.loginPage;
import ObjectRepository.registerPage;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;
public class LoginTest {
//WebDriver driver;
loginPage loginPage;
flightFinder flightFinder;
registerPage registerPage;
/* Login Page */
#When("^I input my details as \"([^\"]*)\" and \"([^\"]*)\"$")
public void i_input(String username, String password) {
flightFinder=loginPage.login(username,password);
}
#Given("^I am logged in as \"([^\"]*)\" and \"([^\"]*)\"$")
public void i_am_logged_in(String username, String password){
flightFinder=loginPage.login(username,password);
}
}
Ok my question is:
When I execute the test all the tests within the StepsDefinition.java runs fine and as expectedly. As soon as it moves onto LoginTest.Java I get following error:
5 Scenarios ([31m3 failed[0m, [32m2 passed[0m)
16 Steps ([31m3 failed[0m, [36m5 skipped[0m, [32m8 passed[0m)
1m30.444s
java.lang.NullPointerException
at TestClasses.LoginTest.i_am_logged_in(LoginTest.java:30)
at ✽.Given I am logged in as "test" and "test"(featureFiles/flightFinder.feature:5)
java.lang.NullPointerException
at TestClasses.LoginTest.i_input(LoginTest.java:23)
at ✽.When I input my details as "test" and "test"(featureFiles/login.feature:12)
java.lang.NullPointerException
at TestClasses.Register_Test.i_input_my_details(Register_Test.java:21)
at ✽.When I input my details(featureFiles/register.feature:12)
What I think happening is, I am initiating the objects in stepsDefinition.Java class and as soon as the test moves onto another test class it is not carrying on with the previous state of the object.
If thats the case how can I pass on the state of one object to another? If not then where am I going wrong? Any help will be much appreciated.
The WebDriver is instantiated in the abstract class.
In the loginPage.Java,registerPage.java,flighFinder.java you are using driver which is not instantiated or driver which is instantiated in the abstract class is not passed to these classes.
Solution can be Remove driver=new FirefoxDriver(); from the setup of Abstract class instead place that in LoginTest and pass the driver object during loginPage,registerPage object creation.
ex: WebDriver driver = new ChromeDriver();
loginPage loginpage = new loginPage(driver);
I have tried it worked.