I have a task for work that I can't seem to complete because I don't fully get the toolset at hand. I am supposed to use JBehave along with Selenium Web Driver to be able to add a certain book to a wishlist on an amazon account. I have a given story and I supposed to use the previously mentioned tools to be used for "learning purposes". I understand that JBehave is a framework for BDD. So, I have some sort of story that I want to test. However, what confuses me is the configuration and "step definition" part which I don't really get. My problem is I don't really understand how to get all those parts working together. Where does Selenium WebDriver fit in the equation? Note that I have used Selenium with Java and that was a breeze.
I want to give you an example of a story in gherkin format and I would appreciate any insights on this subject matter, maybe a clarification on how all the pieces fit together.
Given user <username> with password <password> has a valid amazon.com account
And has a wish list
And wants to purchase book <title> at a later date
When a request to place the book in the wish list is made
Then the book is placed in the wish list
And the book <title> appears in the wish list when <username> logs in at a later date.
Now that you have your Story you need your Steps. The steps are the Java code that will be executed by the story. Each line in your story gets mapped to a Java Step. See the documentation on Candidate Steps.
Here is a really simple stab at what your story and steps might look like. But it should at least give you an idea of how the stories and steps tie together.
Story
Given user username with password passcode is on product page url
When the user clicks add to wish list
Then the wish list page is displayed
And the product title appears on the wish list
Steps
public class WishlistSteps {
WebDriver driver = null;
#BeforeScenario
public void scenarioSetup() {
driver = new FirefoxDriver;
}
#Given("user $username with password $passcode is on product page $url")
public void loadProduct(String username, String passcode, String url) {
doUserLogin(driver, username, passcode); // defined elsewhere
driver.get(url);
}
#When("the user clicks add to wishlist")
public void addToWishlist() {
driver.findElement(By.class("addToWishlist")).click();
}
#Then("the wish list page is displayed")
public void isWishlistPage() {
assertTrue("Wishlist page", driver.getCurrentUrl().matches(".*/gp/registry/wishlist.*"));
}
#Then("the product $title appears on the wish list")
public void checkProduct(String title) {
// check product entries
// assert if product not found
}
#AfterScenario
public void afterScenario() {
driver.quit();
}
}
Next you will need a runner which actually finds and runs the stories. See the documentation on Running Stories. Below is a very simple runner that would run as a JUnit test.
Runner
public class JBehaveRunner extends JUnitStories {
public JBehaveRunner() {
super();
}
#Override
public injectableStepsFactory stepsFactory() {
return new InstanceStepsFactory( configuration(),
new WishlistSteps() );
}
#Override
protected List<String> storyPaths() {
return Arrays.asList("stories/Wishlist.story");
}
}
This runner would then be executed as a JUnit test. You can configure your IDE to run it, or use Maven or Gradle (depending on your setup).
mvn test
I have found that the pages below provide a great overview of the whole setup. And the examples from the JBhave repository are useful as well.
Automated Acceptance-Testing using JBehave
JBehave Configuration Tutorial
JBehave Examples
Related
I have an Android app that I want to use with full screen Google ads.
I have got the small ad running, but the full screen ad does show any content.
The information I found on the internet is a little conflicting.
This link here https://github.com/chen-fishbein/admobfullscreen-codenameone advises to add several build hints to the project, but then it refuses to build.
The other one here https://github.com/shannah/admobfullscreen-codenameone does not mention any build hints, but then the ads won't load.
The answer here unable to build codename one app after adding admobfullscreen lib tells to ignore the includeGplayServices hint.
I have build the project with the sample code, but to no avail.
What would be the correct approach?
Edit : code added
String idTest = "ca-app-pub-3940256099942544/6300978111";
String idReal = "ca-app-pub-3524209908223138~0000000000";
admobTestId = new AdMobManager(idTest);
admobRealId = new AdMobManager(idReal);
f.addComponent(new Button(new Command("admob test load and show"){
public void actionPerformed(ActionEvent evt) {
admobTestId.loadAndShow();
}
}));
f.addComponent(new Button(new Command(" admob real load & show"){
public void actionPerformed(ActionEvent evt) {
admobRealId.loadAndShow();
}
}));
I know basic selenium web driver and also written code using Page Object Model in TestNG frame work for one small application registration and login page.
Bu i don't know, how can provide test report to development team and what are the check points for automation testing please help me.
Example:
Assume my application have two pages like Registration and signin page
My code:
public class Sample {
Authentication_Locators authenticate;
WebDriver d = null;
#BeforeTest
public void beforeTest() throws Exception {
d = InitDriver.wbDriver("chrome", testData.getProperty("testUrl"));
authenticate = PageFactory.initElements(d,
Authentication_Locators.class);
}
#Test (priority = 0)
public void signIn() throws Exception {
Thread.sleep(1000);
authenticate.userName.sendKeys("user1");
authenticate.password.sendKeys("password1");
authenticate.signin.Click();
}
}
TesgNG creates HTML report of the execution which is located in the current working directory under results folder with name emailable_report. Also for more accurate reports you can also use Soft and hard asserts.
Hope this helps.
Scenario: Unique application number(Zee1106) using to enroll students and running testng for Multiple browsers(parallel) like chrome, firefox in selenium webdriver.
In the above scenario, I have run the test suite,first browser(chrome) enrolled successfully and the next browser(firefox) is not enrolled. Because already enrolled alert was coming. In this scenario, How can i enroll students using unique application number for multiple browser in webdriver.
Thanks,
Vairamuthu
There are quite a few ways to achieve this. One easiest way is to have the "Application Numbers" stored as a comma separated values in your test data sheet and use each for the respective browsers. Example:
//Assume applicationNo is stored as a comma separated value in test data. Something like this
String applicationNo="zee1106, zee1107, zee1108"; //please read these data from test data sheet
String[] unquieAppNo=applicationNo.split(",");
//get the browserName
Capabilities caps = ((RemoteWebDriver) driver).getCapabilities();
String browserName = caps.getBrowserName();
//if the browser name is chrome then use one of the application id and so on for each browser.
if(browserName.equalsIgnoreCase("chrome")){
driver.findElement(By.id("<employee app number>")).sendKeys(unquieAppNo[0]);
}else if (browserName.equalsIgnoreCase("firefox")) {
driver.findElement(By.id("<employee app number>")).sendKeys(unquieAppNo[1]);
}else{ //any other browser
driver.findElement(By.id("<employee app number>")).sendKeys(unquieAppNo[2]);
}
It is hard to tell with no code posted at all. Which Language you are working on?Please post the way you instantiate you Webdriver. From your description, I'm guessing that you are using something like this (static):
public static WebDriver driver;
Whilst you need a different WebDriver instance everytime:
public WebDriver driver;
I want to develop a multi-agent system and I want to run different agents from different containers. I'm using eclipse with Jade framework for this and i have no idea how to configure the "run configuration" for the project in order to accomplish this. So far I have this: -gui -container main:Sender;a1:Receiver;a2:Pong and I want to put agents a1 and a2 in a separate container. Please help.
When starting a new jade project I usually create a Coordinator agent with the methods to launch and destroy other agents. I think this is good practice as you can extend these methods to other agents if need be.
I hope that this will help.
First Run the Agent jade graphical user interface (Ejade) (By Installing the Ejade Library)
or you can run it on the console:
C:\java jade.Boot -gui (You have to fix the system variable path to "C:\..\jade.far" and create a variable name classpath = "C:\..\jdk7\")
Run the code that allows you to create a new container to deploy on it your agents.
import jade.core.ProfileImpl;
import jade.core.Runtime;
import jade.domain.ams;
import jade.wrapper.AgentContainer;
import jade.wrapper.AgentController;
public class ContainerDeploy {
public static void main(String[] args) {
try{
Runtime runtime=Runtime.instance();
ProfileImpl profileImpl = new ProfileImpl(false);
profileImpl.setParameter(ProfileImpl.MAIN_HOST, "localhost");
AgentContainer agentContainer=runtime.createAgentContainer(profileImpl);
AgentController agentcontroller1 = agentContainer.createNewAgent("Name of Agent", "com.package.AgentClass", new Object[]{});
agentController1.start();
}catch(Exception e) {
System.out.println("Runtime Error\t");
e.printStackTrace();
}
}
}
I have a Enum class as:
global class Util {
global enum Session {
Winter,
Summer,
Rain
}
}
and a test class as :
public static testmethod void callTestData(){
test.starttest();
Util.Session se = Util.Session.Winter;
test.stoptest();
}
But still my code coverage is 0%?? Why.
Also I tried many ways to cover it but not able to can any one help!!
This seems like it should give you 100% coverage.
Sometimes Salesforce needs a bit of encouragement to give you the correct code coverage results.
Try:
Clearing all previous test case results
Setup > App Setup > Develop > Apex Text Execution > View Test History > Clear Test Results
Running the test case from the force.com IDE
That the class and the test method class are using the same API version in the metadata file. E.g. both 29.0.
Running the test case from an external tool, such as MavensMate in Sublime Text or the FuseIT SFDC Explorer that has both synchronous and asynchronous testing options.