Cucumber not running selenium Code - selenium

When I try to run my code, it only shows cucumber skeleton. I use a JUnit runner class as JUnit test suite.
Code is below for all three classes.
Feature is :
Feature: Check addition in Google calculator
In order to verify that google calculator work correctly
As a user of google
I should be able to get correct addition result
#Runme
Scenario: Addition
Given I open google
When I enter "2+2" in search textbox
Then I should get result as "4"
Selenium Class :
package cucumberTest;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SeleniumTest {
private SeleniumTest()
{
}
private static WebDriver driver = null;
public static void seleniumTest() {
// Create a new instance of the Firefox driver
driver = new FirefoxDriver();
//Put a Implicit wait, this means that any search for elements on the page could take the time the implicit wait is set for before throwing exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Launch the Online Store Website
driver.get("http://www.store.demoqa.com");
// Find the element that's ID attribute is 'account'(My Account)
driver.findElement(By.xpath(".//*[#id='account']/a")).click();
// Find the element that's ID attribute is 'log' (Username)
// Enter Username on the element found by above desc.
driver.findElement(By.id("log")).sendKeys("testuser_1");
// Find the element that's ID attribute is 'pwd' (Password)
// Enter Password on the element found by the above desc.
driver.findElement(By.id("pwd")).sendKeys("Test#123");
// Now submit the form. WebDriver will find the form for us from the element
driver.findElement(By.id("login")).click();
// Print a Log In message to the screen
System.out.println("Login Successfully");
// Find the element that's ID attribute is 'account_logout' (Log Out)
driver.findElement (By.xpath(".//*[#id='account_logout']/a")).click();
// Print a Log In message to the screen
System.out.println("LogOut Successfully");
// Close the driver
driver.quit();
}
}
JUnit Class:
package cucumberTest;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
//#CucumberOptions(
// features = "Feature/googleCalc.feature"
////,glue={"stepDefinition"}
// )
#CucumberOptions(
features = {"Feature/googleCalc.feature"},glue={"stepDefinition"},
plugin = {"pretty"},
tags = {"#Runme"}
)
public class TestRunner {
}
Step Definitions :
package stepDefination;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
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;
import cucumberTest.SeleniumTest;
public class googleCalcStepDefinition {
#Given("^I open google$")
public void i_open_google() throws Throwable {
// Write code here that turns the phrase above into concrete actions
SeleniumTest.seleniumTest();
}
#When("^I enter \"(.*?)\" in search textbox$")
public void i_enter_in_search_textbox(String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
SeleniumTest.seleniumTest();
}
#Then("^I should get result as \"(.*?)\"$")
public void i_should_get_result_as(String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
SeleniumTest.seleniumTest();
}
}
Output shown is :
Feature: Check addition in Google calculator
In order to verify that google calculator work correctly
As a user of google
I should be able to get correct addition result
#Runme
Scenario: Addition [90m# Feature/googleCalc.feature:7[0m
[33mGiven [0m[33mI open google[0m
[33mWhen [0m[33mI enter "2+2" in search textbox[0m
[33mThen [0m[33mI should get result as "4"[0m
1 Scenarios ([33m1 undefined[0m)
3 Steps ([33m3 undefined[0m)
0m0.000s
You can implement missing steps with the snippets below:
#Given("^I open google$")
public void i_open_google() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
#When("^I enter \"(.*?)\" in search textbox$")
public void i_enter_in_search_textbox(String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
#Then("^I should get result as \"(.*?)\"$")
public void i_should_get_result_as(String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}

I found the reason it was not executing because i added Selenium test class and Junit runner class in Package cucumberTest; and skeleton was in package stepDefination; so what i did was i moved skeleton to pacakge cucumberTest; where junit runner and selenium classes are it resolved the issue for . Issue was occuring because when you place Junit class in package it will search for skeleton in that package but if you add JUnit runner class in source folder then it will be able to find the page under src folder

Related

Running selenium test with DrJava IDE

It is possible to run the selenium libraries on DrJava, if so how can I make the test case to run the respective libraries.
I'm tying to run some test cases in Junit
I think you can run Selenium on DrJava. Therefore you have to follow instructions here to get started. Then just create the sample class like this and enjoy the testing:
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.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Selenium2Example {
public static void main(String[] args) {
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new FirefoxDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Alternatively the same thing can be done like this
// driver.navigate().to("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
});
// Should see: "cheese! - Google Search"
System.out.println("Page title is: " + driver.getTitle());
//Close the browser
driver.quit();
}
}

Fitnesse wiki unable to call selenium method correctly

I am trying to write a simple fixture that opens the browser and navigates to www.google.com. When I run the wiki page, it passes with all green, but the browser never opens up (I don't think the method even gets called by the wiki). Can someone take a look at my fixture and wiki to see what I am doing wrong? Many thanks in advance,
Here is the Wiki -
!|SeleniumFitness|
|URL |navigateToSite?|
|http://www.google.com| |
After Running -
!|SeleniumFitnesse| java.lang.NoSuchMethodError: org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(Lorg/openqa/selenium/remote/service/DriverService;Ljava/util/Map;)V
|URL |The instance decisionTable_4.setURL. does not exist|navigateToSite?
|http://www.google.com|!The instance decisionTable_4.navigateToSite. does not exist |
Here is the Fixture -
package FitNesseConcept.fitNesse;
import java.util.Properties;
import org.junit.BeforeClass;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeMethod;
//import com.google.common.base.Preconditions.*;
//import com.google.common.collect.Lists;
import fit.ColumnFixture;
public class SeleniumFitnesse extends ColumnFixture {
public static ChromeDriver driver = null;
private String navigateToSite = "";
public String URL = "";
public SeleniumFitnesse() {
Properties props = System.getProperties();
props.setProperty("webdriver.chrome.driver", "/home/ninad/eclipse-workspace/chromedriver");
driver = new ChromeDriver();
}
// SET-GET Methods
public String getURL() {
return URL;
}
public void setURL(String uRL) {
URL = uRL;
}
public String getNavigateToSite() {
return navigateToSite;
}
public void setNavigateToSite(String navigateToSite) {
this.navigateToSite = navigateToSite;
}
// Navigate to URL
public void navigateToSite() throws Throwable {
System.out.println("Navigating to Website");
try {
driver.navigate().to(URL);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
You are getting some good recommendations as comments - but to answer your question directly, for an old-style ColumnFixture, which is what you have written, the method "navigateToSite" is indeed not going to be called.
These styles of fixtures are not often used anymore, Slim is preferred, and your fitnesse instance in its documentation will show you how to use Slim style. However, for a column fixture as you have written, if you want a method to be called it needs to be a "?" following name of the method in the header row.
See basic docs for column fixture:
http://fitnesse.org/FitNesse.UserGuide.FixtureGallery.BasicFitFixtures.ColumnFixture
You are mis-using column fixture, even granted the old style though. Column fixture's pattern is "here is a series of columns that represent inputs, now here is a method call I want to make to get the output and check result". Navigating a website does not often fit that pattern. In old style fitnesse it would probably be approached by an ActionFixture:
http://fitnesse.org/FitNesse.UserGuide.FixtureGallery.BasicFitFixtures.ActionFixture
In the newer Slim style, a good fit for navigation and checking where you are would be a Scenario Table.
http://www.fitnesse.org/FitNesse.UserGuide.WritingAcceptanceTests.SliM.ScenarioTable
In general doing WebDriver / Selenium tests through a wiki is worth extra thought as to whether it's your best medium. Fitnesse is really designed to be a collaborative tool for documenting and verifying business requirements, directly against source code.
Here's an example of how to do with a ColumnFixture, although again ColumnFixture not exactly appropriate:
|url|navigateToUrl?|
|www.google.com| |
java class:
public String url;
public void navigateToUrl() {
}
You could return an "OK" if it navigates alright, or return the title of the page as opposed to void if you wanted.

LeanFT and Selenium Compatibility?

I would like to know if Selenium and LeanFT can play nicely together. I don't know if anyone has tried to do this yet, but I think if it can work, LeanFT can provide some supplementary benefits to the selenium framework.
As I understand it currently, the limitations of Selenium are:
Selenium MUST open the initial browser to recognize it
Selenium MUST open all popups to recognize them.
Selenium WebDriver may become stale while waiting for non-Selenium procedures.
I have attempted the object flow UML for both HP's suggested model and my own idea of how this might work.
The Control flow would be something like:
#Before -> globalSetup (LeanFT init)
#BeforeClass -> testSetup (LeanFT init)
#BeforeClass -> getSeleniumDriver (Selenium)
#Test -> some selenium procedures
/**** To prevent Selenium from dying. ****/
#Test -> new Thread -> run leanFTsnippet1()
#Test -> resume selenium final steps..
#After -> reporting, closing Webdriver
Here is some of my current code from an example Test Class.
#BeforeClass
public static void beforeLFTClass() throws Exception {
globalSetup(CoreFunctionality.class);
}
#AfterClass
public static void afterLFTClass() throws Exception {
globalTearDown();
}
#Test
public void runLeanFtThread() {
// put selenium code here
// ...
// begin leanft part of test
Thread leanftThread = new Thread( new Runnable() {
#Override
public void run() {
try {
test();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
leanftThread.start();
try {
leanftThread.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void test() throws Exception {
//Starting Browser
Browser browser = BrowserFactory.attach(new BrowserDescription.Builder().title(driver.getTitle()).build());
Assert.assertEquals(browser.getTitle(), driver.getTitle());
}
Anyways, its a pretty interesting problem. Would really love to see what you guys think.
Thanks!
They indeed play nicely together. I have been using them in my scripts and I like to utilize the powers of each tool. What I have done is create a LeanFT test template and add the Selenium libraries to it.
Here is a sample code:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HP.LFT.SDK;
using HP.LFT.SDK.Web;
using Search_Regression_Test;
using TestAutomationReporting;
using UnifiedFramework;
using System.Configuration;
using System.Diagnostics;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using Selenium = OpenQA.Selenium;
namespace Search_Regression_Test
{
[TestClass]
public class LeanFtTest : UnitTestClassBase<LeanFtTest>
{
static IBrowser browser;
static IWebDriver chromeDriver;
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
GlobalSetup(context);
ChromeOptions CO = new ChromeOptions();
CO.AddExtension(#"C:\Program Files (x86)\HP\LeanFT\Installations\Chrome\Agent.crx");
chromeDriver = new ChromeDriver(CO);
chromeDriver.Manage().Window.Maximize();
browser = BrowserFactory.Attach(new BrowserDescription
{
Type = BrowserType.Chrome
});
.... and so on.
The new Version of LeanFT (14) even brings some explicit Selenium-integration: You can select Selenium as your automation SDK in the project creation wizard, there is a Selenium-specific Object Identification Center, and some additional locators and utilities. Full story here: LeanFT for Selenium.
I'm not entirely sure why this question doesn't have an accepted answer yet, but I'm going to take a stab at answering this with a sample that highlights once more that LeanFT and Selenium are playing nicely together
It's written in Java. Probably it can be optimized a bit, but it should clearly show how you can achieve simultaneous interaction with the same browser.
(The Java Project was created from LeanFT templates. UnitTestClassBase class comes from there. It basically initializes LeanFT and the reporter behind the scenes. To get around it if you don't want to use it you'd have to call SDK.init(), Reporter.init(), Reporter.generateReport() and SDK.cleanup() as needed - check the docs for details)
The AUT used is advantage shopping: http://advantageonlineshopping.com/
package com.demo;
import static org.junit.Assert.*;
import java.io.File;
import java.util.Calendar;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.Keys;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.remote.DesiredCapabilities;
import com.hpe.leanft.selenium.By;
import com.hp.lft.report.Reporter;
import com.hp.lft.report.Status;
import com.hp.lft.sdk.web.*;
import com.hp.lft.verifications.Verify;
public class SeleniumTest extends UnitTestClassBase {
private ChromeDriver chromeDriver;
private Browser browser;
public SeleniumTest() {
System.setProperty("webdriver.chrome.driver",this.getClass().getResource("/chromedriver.exe").getPath());
}
#BeforeClass
public static void setUpBeforeClass() throws Exception {
instance = new SeleniumTest();
globalSetup(SeleniumTest.class);
}
#AfterClass
public static void tearDownAfterClass() throws Exception {
globalTearDown();
}
#Before
public void setUp() throws Exception {
// SELENIUM: Construct and launch the browser with LeanFT agent
ChromeOptions options = new ChromeOptions();
File paths = new File("C:\\Program Files (x86)\\HP\\LeanFT\\Installations\\Chrome\\Agent.crx");
options.addExtensions(paths);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
chromeDriver = new ChromeDriver(options);
}
#After
public void tearDown() throws Exception {
// LEANFT: close the browser opened by selenium
browser.close();
}
#Test
public void test() throws Exception {
// SELENIUM: Go to the Advantage shopping website and maximize it
chromeDriver.get("http://156.152.164.67:8080/#/");
chromeDriver.manage().window().maximize();
// LEANFT: Attach to the browser
browser = BrowserFactory.attach(new BrowserDescription.Builder()
.type(BrowserType.CHROME).openTitle(" Advantage Shopping")
.build());
// LEANFT: Click on tablets button
browser.describe(WebElement.class, new WebElementDescription.Builder()
.className("categoryCell").tagName("DIV").innerText("TABLETS Shop Now ").build()).click();
// SELENIUM: Expand the display section after it was seen
(new WebDriverWait(chromeDriver, 10))
.until(new ExpectedCondition<org.openqa.selenium.WebElement>(){
#Override
public org.openqa.selenium.WebElement apply(org.openqa.selenium.WebDriver d) {
return d.findElement(By.cssSelector("h4#accordionAttrib0"));
}}).click();
// LEANFT: select the preferred display size, click the preferred tablet and add the tablet to the cart
browser.describe(CheckBox.class, new CheckBoxDescription.Builder()
.type("checkbox").role("").accessibilityName("").tagName("INPUT").name("").index(1).build()).set(true);
browser.describe(Image.class, new ImageDescription.Builder()
.alt("").type(com.hp.lft.sdk.web.ImageType.NORMAL).tagName("IMG").index(1).build()).click();
browser.describe(Button.class, new ButtonDescription.Builder()
.buttonType("submit").tagName("BUTTON").name("ADD TO CART").build()).click();
// SELENIUM: go to cart
chromeDriver.get("http://156.152.164.67:8080/#/shoppingCart");
// LEANFT: checkout
browser.describe(Button.class, new ButtonDescription.Builder()
.buttonType("submit").tagName("BUTTON").name("CHECKOUT ($1,009.00)").build()).click();
// SELENIUM: Register as a new user after the button was seen
(new WebDriverWait(chromeDriver, 10))
.until(new ExpectedCondition<org.openqa.selenium.WebElement>(){
#Override
public org.openqa.selenium.WebElement apply(org.openqa.selenium.WebDriver d) {
return d.findElement(By.xpath("//DIV[#id=\"newClient\"]/DIV[1]/SEC-FORM[1]/SEC-SENDER[1]/BUTTON[#role=\"button\"][1]"));
}}).click();
// LEANFT: fill in the user name and email
String username = "U" + Calendar.getInstance().getTimeInMillis(); // unique name each time
browser.describe(EditField.class, new EditFieldDescription.Builder()
.type("text").tagName("INPUT").name("userName").build()).setValue(username);
browser.describe(EditField.class, new EditFieldDescription.Builder()
.type("text").tagName("INPUT").name("userEmail").build()).setValue("myuser_email#emailsite.org");
// SELENIUM: Set password and confirm password
chromeDriver.findElementByXPath("//SEC-VIEW/DIV[normalize-space()=\"*Password\"]/INPUT[1]").sendKeys("Password1");
chromeDriver.findElementByXPath("//SEC-VIEW/DIV[normalize-space()=\"*Confirm password\"]/INPUT[1]").sendKeys("Password1");
// LEANFT: check the 'I agree' checkbox and register, then click on next shipping details.
browser.describe(CheckBox.class, new CheckBoxDescription.Builder()
.type("checkbox").tagName("INPUT").name("registrationAgreement").build()).set(true);
browser.describe(Button.class, new ButtonDescription.Builder()
.buttonType("button").tagName("BUTTON").name("REGISTER").build()).click();
browser.describe(Button.class, new ButtonDescription.Builder()
.buttonType("submit").tagName("BUTTON").name("NEXT").build()).click();
// SELENIUM: confirm the user name and pass
chromeDriver.findElementByXPath("//DIV[#id=\"paymentMethod\"]/DIV/DIV/SEC-FORM/SEC-VIEW/DIV[normalize-space()=\"*SafePay username\"]/INPUT[1]").sendKeys(username);
chromeDriver.findElementByXPath("//DIV[#id=\"paymentMethod\"]/DIV/DIV/SEC-FORM/SEC-VIEW/DIV[normalize-space()=\"*SafePay password\"]/INPUT[1]").sendKeys("Password1");
// LEANFT: click "Pay now" and confirm payment was done
browser.describe(Button.class, new ButtonDescription.Builder()
.buttonType("button").role("button").accessibilityName("").tagName("BUTTON").name("PAY NOW").index(0).build()).click();
Verify.isTrue(
browser.describe(WebElement.class, new WebElementDescription.Builder()
.tagName("SPAN").innerText("Thank you for buying with Advantage").build())
.exists());
}
}

Long press on AndroidElement in Appium

I`m trying to perform a long press action on AndroidElement in Appium. What I found is that i need to perform a TouchAction on this element, but... it only takes as argument WebDriver, no AndroidDriver that I`m using. For this reason it will not work.
TouchAction action = new TouchAction(AndroidDriver);
action.longPress(element, 10000);
I was looking for some answer for some time. LongPress (or something similar) is used in last test that I`m writting right now.
Try this.
TouchAction action = new TouchAction();
action.longPress(webElement).release().perform();
Workaround could be usage of io.appium.java_client.MultiTouchAction.
MultiTouchAction multiTouch = new MultiTouchAction(AndroidDriver);
multiTouch.add(createTap(element, duration));
multiTouch.perform();
Below code will perform single tap and long press for particular period of time in android app
Make use of it
package com.prac.com;
import java.net.MalformedURLException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebElement;
import io.appium.java_client.TouchAction;
import static io.appium.java_client.touch.TapOptions.tapOptions;
import static io.appium.java_client.touch.LongPressOptions.longPressOptions;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import static java.time.Duration.ofSeconds;
import static io.appium.java_client.touch.offset.ElementOption.element;
public class UdmeyCode extends Demo4TestBase {
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
AndroidDriver<AndroidElement> driver=Capabilities();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElementByXPath("//android.widget.TextView[#text='Views']").click();
//Tap
TouchAction t =new TouchAction(driver);
WebElement expandList= driver.findElementByXPath("//android.widget.TextView[#text='Expandable Lists']");
t.tap(tapOptions().withElement(element(expandList))).perform();
driver.findElementByXPath("//android.widget.TextView[#text='1. Custom Adapter']").click();
WebElement pn= driver.findElementByXPath("//android.widget.TextView[#text='People Names']");
t.longPress(longPressOptions().withElement(element(pn)).withDuration(ofSeconds(2))).release().perform();
//Thread.sleep(2000);
System.out.println(driver.findElementById("android:id/title").isDisplayed());
}
}

Junit/Webdriver - Why my browser is launching twice

Hi I am new to Webdriver and Junit. Need this puzzle solved. I did a lot of research but couldnt find the one that could help.
So I declared my driver up top as Static Webdriver fd and then trying to run cases on single class files (also tried multiple class files) but everytime I run the browser launches twice. I can seem to debug this problem please help. Here is my code:
package Wspace;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ErrorCollector;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class Wsinventory {
static WebDriver fd;
#Rule
public static ErrorCollector errCollector = new ErrorCollector();
#Before
public void openFirefox() throws IOException
{
System.out.println("Launching WebSpace 9.0 in FireFox");
ProfilesIni pr = new ProfilesIni();
FirefoxProfile fp = pr.getProfile("ERS_Profile"); //FF profile
fd = new FirefoxDriver(fp);
fd.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
fd.get("http://www.testsite.com");
fd.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
String ffpagetitle = fd.getTitle(); //ffpagetitle means firefox page title
//System.out.println(pagetitle);
try{
Assert.assertEquals("Webspace Login Page", ffpagetitle);
}catch(Throwable t){
System.out.println("ERROR ENCOUNTERED");
errCollector.addError(t);
}
}
#Test
public void wsloginTest(){
fd.findElement(By.name("User ID")).sendKeys("CA");
fd.findElement(By.name("Password")).sendKeys("SONIKA");
fd.findElement(By.name("Logon WebSpace")).click();
}
#Test
public void switchtoInventory() throws InterruptedException{
Thread.sleep(5000);
fd.switchTo().frame("body"); //Main frame
fd.switchTo().frame("leftNav"); //Sub frame
fd.findElement(By.name("Inventory")).click();
fd.switchTo().defaultContent();
fd.switchTo().frame("body");
}
}
The problem is that your #Before method is running before every test. When you run your second test, it is calling that method again, and throwing away that old instance of FirefoxDriver, and creating a new one (stored in that static instance of driver).
Use #BeforeClass instead.