Usage: java cucumber.api.cli.Main [options] [ [FILE|DIR][:LINE[:LINE]*] ]+ - selenium

I am getting this error while running my feature file
Usage: java cucumber [options] [ [FILE|DIR][:LINE[:LINE]*] ]+
Options:
-g, --glue PATH Where glue code (step definitions and hooks) is loaded from.
-f, --format FORMAT[:PATH_OR_URL] How to format results. Goes to STDOUT unless PATH_OR_URL is specified.
Built-in FORMAT types: junit, html, pretty, progress, json.
FORMAT can also be a fully qualified class name.
-t, --tags TAG_EXPRESSION Only run scenarios tagged with tags matching TAG_EXPRESSION.
-n, --name REGEXP Only run scenarios whose names match REGEXP.
-d, --[no-]-dry-run Skip execution of glue code.
-m, --[no-]-monochrome Don't colour terminal output.
-s, --[no-]-strict Treat undefined and pending steps as errors.
--snippets Snippet name: underscore, camelcase
--dotcucumber PATH_OR_URL Where to write out runtime information. PATH_OR_URL can be a file system
path or a URL.
-v, --version Print version.
-h, --help You're looking at it.
Exception in thread "main" cucumber.runtime.CucumberException: Unknown option: --plugin
at cucumber.runtime.RuntimeOptions.parse(RuntimeOptions.java:119)
at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:50)
at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:44)
at cucumber.api.cli.Main.run(Main.java:20)
at cucumber.api.cli.Main.main(Main.java:16)
my runner class
package cucumber;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith( value = Cucumber.class)
#CucumberOptions(dryRun = false, strict = true,
features="/STAF/src/main/java/CucumberFeature/GmailLoginLogout.feature/",
tags ={"~#/ReCall/src/SeleniumWithCucumber/FbTest.java"})
public class CucumberRunner {
}
my feature file
Feature: Gmail login Logout
Scenario: Login and Log out to Gmail
Given Open gmail
When Login with valide credential
Then Home page should come
my step defination
package StepDfination;
import org.openqa.selenium.WebDriver;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class GmailLoginLogout {
WebDriver driver;
#Given("^Open gmail$")
public void Open_gmail(){
System.out.println("gmailopened ");
}
#When("^Login with valide credential$")
public void Login_with_valide_credential(){
System.out.println("cridential entered");
}
#Then("^Home page should come$")
public void Home_page_should_come(){
System.out.println("in home page");
}
}

Use of CLI command to invoke it as a Java program would be
public static void main(String args[]) {
Main.main(new String[]{"-g", "StepDfination", "-t", "<your tag what you need to test", "/STAF/src/main/java/CucumberFeature/GmailLoginLogout.feature"});
}
As grasshopper suggested, if you need invoke it as TestNG, you need a runner class.
Note that your feature file location should be the last. Let me know if it helps!

It looks like you are trying to get started. Your steps will only report that they are executed. However, your approach seems very complicated and you are getting an error you don't understand. You have a problem with Gall's law.
I would suggest that you start from another angle. Start from something that works and then transform it into something that you want.
Clone the getting started project supplied by the Cucumber Team and then transform it in small steps to the example you really would like to have.

Try using "-p" instead of "--plugin".
I found out it by a similar error of mine. Hope this log would help.
Usage: java cucumber.api.cli.Main [options] [[[FILE|DIR][:LINE[:LINE]*] ]+ | #FILE ]
Options:
-g, --glue PATH Where glue code (step definitions, hooks
and plugins) are loaded from.
-p, --[add-]plugin PLUGIN[:PATH_OR_URL]
Register a plugin.
Built-in formatter PLUGIN types: junit,
html, pretty, progress, json, usage, rerun,
testng. Built-in summary PLUGIN types:
default_summary, null_summary. PLUGIN can
also be a fully qualified class name, allowing
registration of 3rd party plugins.
--add-plugin does not clobber plugins of that
type defined from a different source.
-f, --format FORMAT[:PATH_OR_URL] Deprecated. Use --plugin instead.
-t, --tags TAG_EXPRESSION Only run scenarios tagged with tags matching
TAG_EXPRESSION.
-n, --name REGEXP Only run scenarios whose names match REGEXP.
-d, --[no-]-dry-run Skip execution of glue code.
-m, --[no-]-monochrome Don't colour terminal output.
-s, --[no-]-strict Treat undefined and pending steps as errors.
--snippets [underscore|camelcase] Naming convention for generated snippets.
Defaults to underscore.
-v, --version Print version.
-h, --help You're looking at it.
--i18n LANG List keywords for in a particular language
Run with "--i18n help" to see all languages
--junit,OPTION[,OPTION]* Pass the OPTION(s) to the JUnit module.
Use --junit,-h or --junit,--help to print the
options of the JUnit module.
Feature path examples:
<path> Load the files with the extension ".feature"
for the directory <path>
and its sub directories.
<path>/<name>.feature Load the feature file <path>/<name>.feature
from the file system.
classpath:<path>/<name>.feature Load the feature file <path>/<name>.feature
from the classpath.
<path>/<name>.feature:3:9 Load the scenarios on line 3 and line 9 in
the file <path>/<name>.feature.
#<path>/<file> Parse <path>/<file> for feature paths generated
by the rerun formatter.

Related

Is there any selenium/python script for the Screen Recording?

I want to record the screen by using selenium in python, I searched for these, but I only get results for java, and for the screenshots. Please let me know if there is any script by which I can record the screen.
you need record the whone screenshot? try this library
and try this code:
from clicknium import clicknium as cc, locator, ui
cc.get_screenshot("D:\\test.jpg")
Try this, very popular framework for eg. java or python etc.
in cmd line : pip install allure-pytest
go here: https://docs.qameta.io/allure/
section 2.1. Installing a commandline
download the newest version for eg. windows xxx.zip
copy path of bin folder eg: D:\Drivers\allure-2.18.1\bin
and paste it to Environment Variables > find 'Path' and edit it> add new path with bin path.
to Your test.py file:
import allure
from allure_commons.types import AttachmentType
and add it at the end of Your test in eg.: assertion statement
example:
method_name = self.driver.find_element(By.XPATH, "xxx").text
if method_name == 'some text':
assert True
else:
allure.attach(self.driver.get_screenshot_as_png(), name="test_name",
attachment_type=AttachmentType.PNG)
assert False
In IDE terminal or cmd do this:
pytest -v -s --alluredir="D:\projectPath\raport" Path/to/your/tests
then tests will be executed
in terminal do this to read raport wfrom test:
allure serve "D:\raport\Path"
with this allure framework You will have reports of tests with screenshots:

TomEE Microprofile: microprofile-config.properties ignored

i'm having problems getting config values into my microprofile app. I have created a META-INF/microprofile-config.properties file like this:
configEntry=HelloWorld
I've got a simple test class like this:
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Initialized;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.inject.ConfigProperty;
#ApplicationScoped
public class ConfigTest {
#Inject
#ConfigProperty(name = "configEntry", defaultValue = "missing")
private String configValue;
#Inject
Config conf;
public void init(#Observes #Initialized(ApplicationScoped.class) final Object init) {
System.out.println("configEntry = " + configValue);
}
}
I run this on TomEE MP 8.0.10 (downloaded standalone binaries). But whatever I do, configEntry is always 'missing' and when I debug-inspect the Config instance, I can see that there are 3 ConfigSources loaded (SystemPropertyConfigSource, SystemEnvConfigSource,TomEEConfigSource) but none is containing any entry for configValue.
I have also tried to create my own ConfigSource via META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource. Same problem here: My test ConfigSource never gets included in the list of ConfigSoruces.
Is there any kind of secret (TomEE flag) to make this work? Did I miss something crucial, or is TomEE simply not supporting microprofile-config.properties (any longer)?
I found the problem:
This was due to an incompatible maven build configuration. All guides and tutorials I found usually specify the pre-build location of the file, not the location they must end up in the war file/dir. I did put them into the correct pre-build location, but maven placed them 'wron' (inside /META-INF/ not WEB-INF/classes/META-INF).
So, here for all with a similar confusion, after the build this is where the files must reside to be found:
microprofile-config.properties: /WEB-INF/classes/META-INF/
spi services directory: /WEB-INF/classes/META-INF/
spi custom ConfigSource text file: /WEB-INF/classes/META-INF/services/

Cucumber feature file unable to locate glue code when clicking on Recalculate Steps and throws error message

I am currently working on creating a Test Suite using Cucumber framework. I have created feature files for each of the functionality I have to test.
The feature file never shows the conditions to be covered via glue code. On click of Recalculate steps it throws an error : An internal error occurred during: "Scanning for step definitions".
java.lang.NullPointerException
I tried to change the path of glue in the Test Runner class but it did not solve the problem as well. The feature can be executed without any issue and the code runs fine, only issue is feature files keep on stating that there is no matching glue code.
#OrderInteraction
#Orders
Feature: Validating Order functionality
Background: Pre-requisites of Order Functionality
Given WebDriver is initialized
And Website is up and running
When User Enter "Username" and "Password" as Credentials
Then Validate User Login
Test Runner :
package Cucumber;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
#RunWith(Cucumber.class)
#CucumberOptions(features = "Features", glue=
{"src/main/java/CucumberStepDefinitions"})
public class CucumberTestRunner {
}
I would like to find a way in which Cucumber feature files can recognize the glue code present. Feel free to guide me to a existing question which answers this or a documentation which will be of help.
There is a possible solution in this discussion https://github.com/cucumber/cucumber-eclipse/issues/303
Which basically says to make sure you don't have
import cucumber.api.java.en.*;
in your steps files, and to use
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
instead.
Which fixed it for me
I finally was able to find the solution to this issue. Issue lies with the cucumber plugin version, I referred to Cucumber-Eclipse-Update-SiteSnapshot for resolution.
The steps were as below :
1.From Eclipse, go to menu Help > Install New software
2.Work with: https://cucumber.github.io/cucumber-eclipse-update-site-snapshot
3.Select the check-box for Cucumber Eclipse Plugin
4.Select Next as per the instruction shown during installation.
5.Restart your Eclipse after completion of instruction.
Once the plugin was updated Feature file automatically scanned for steps and found the matching glue code.

TeamCity - Testing with JUnit

I am using Intellij Idea version 12 (ultimate). Just installed Team City (version 8). One default agent, running in linux.
I've created a very simple test application:
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
public int sum(int x, int y) {
return x+y;
}
}
... and a very simple test...
import junit.framework.Assert;
import org.junit.Test;
public class MainTest {
#Test
public void testSum() throws Exception {
Main test=new Main();
Assert.assertEquals("Sum should be 7",7,test.sum(4,4));
}
}
If I run this in IntelliJ, the test gets run and fails just like it should.
If instead I commit this project and push it up to github, TeamCity sees the change and begins a build. The build fails fairly quickly with the following errors:
/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:1: package junit.framework does not exist
import junit.framework.Assert;
^
/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:2: package org.junit does not exist
import org.junit.Test;
^
/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:12: cannot find symbol
symbol : class Test
location: class MainTest
#Test
^
/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:15: cannot find symbol
symbol : variable Assert
location: class MainTest
Assert.assertEquals("Sum should be 7. Loser!!",7,test.sum(4,4));
^
So yeah, I see that TeamCity is not seeing JUnit.
On the TeamCity Discussion forum, one respondent to my question there asked me if junit.jar was added as a dependency (module or library) in the build. It was listed as a module dependency, but for kicks I tried it as a library dependency. I also tried checking and unchecking export and trying the compile and test scopes, but each time I get the same errors. My run configuration is shared.
I am not using Ant or Maven. Perhaps someday, but I'd like to start as simple as possible.
Clearly, I'm missing something, but the documentation on the subject is sparse.
Thank you.
So I heard back from Jetbrains tech support this and, in the interest of completeness and saving someone else the trouble, here's the response I received:
Seems the problem is that junit.jar is not placed in version control
under your project. In order to build your project on TeamCity agent,
the project ideally should be self contained. In your case junit.jar
only exists on your local machine, I suppose there is no such file on
agent at required location. So you have two options actually: put
junit.jar under version control into your project, or define global
library in IDEA and configure this global library on IDEA Project
runner page (Check/Reparse must be started), after that put library
files on all of the agents where your build will be executed.
Personally, I think the first approach is much simpler and better.
I added junit to version control and now the build works properly in TeamCity.

Does PHPUnit_Selenium Code Coverage Work?

In the PHPUnit docs, it says that it's possible to get code coverage data:
PHPUnit_Extensions_SeleniumTestCase can collect code coverage information for tests run through Selenium:
Copy PHPUnit/Extensions/SeleniumTestCase/phpunit_coverage.php into your webserver's document root directory.
In your webserver's php.ini configuration file, configure PHPUnit/Extensions/SeleniumTestCase/prepend.php and PHPUnit/Extensions/SeleniumTestCase/append.php as the auto_prepend_file and auto_append_file, respectively.
In your test case class that extends PHPUnit_Extensions_SeleniumTestCase, use
protected $coverageScriptUrl = 'http://host/phpunit_coverage.php';
to configure the URL for the phpunit_coverage.php script.
I haven't been able to get this to output any coverage information. I am able to get code coverage info through normal unit tests.
For my app running at http://localhost/ts2_templates/ I've copied phpunit_coverage.php to http://localhost/phpunit_coverage.php.
I've added the following to php.ini:
auto_prepend_file = "/path/to/pear/share/pear/PHPUnit/Extensions/SeleniumTestCase/prepend.php"
auto_append_file = "/path/to/pear/share/pear/PHPUnit/Extensions/SeleniumTestCase/append.php"
... and verified they are being called with a die("yep it's me");.
Finally, I added the following to my test case:
<?php
class WebTest extends PHPUnit_Extensions_Selenium2TestCase
{
# added line below
protected $coverageScriptUrl = 'http://localhost/phpunit_coverage.php';
protected function setUp()
{
$this->setBrowser('firefox');
$this->setBrowserUrl('http://localhost/ts2_templates');
}
public function testTitle()
{
$this->url('http://localhost/ts2_templates');
$this->assertContains('test', $this->title());
}
}
?>
Here's the command for running the test with code coverage, generated by PHPStorm:
/Applications/MAMP/bin/php5.3/bin/php -dxdebug.coverage_enable=1 /private/var/folders/pp/0t4y41f95j5313qm_f8b42fw0000gn/T/ide-phpunit.php --coverage-clover /path/to/coverage/ts2_templates$WebTest.coverage --no-configuration WebTest /Users/Ian/php/ts2_templates/tests/WebTest.php
Heres the output of the coverage XML file:
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1341015508">
<project timestamp="1341015508">
<metrics files="0" loc="0" ncloc="0" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
</project>
</coverage>
The test itself passes.
I have verified there are no exit or die statements anywhere in the code.
Any ideas?
I also had some issues getting things to work. The following post in the YII forum by Samuel Goldstein helped me out:
I ended up moving the prepend.php and append.php into my project's document root.
I also found that the temporary file location made a difference - I originally was trying to save them to /tmp/ and PHP was silently failing. When I changed $GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] to myroot/protected/runtime/tmp and did a chmod 777 on that directory, it started working.
One thing that might frustrate you a bit is that code run through Ajax does not get flagged as being covered.
This appears to be a known problem with Selenium. Google "github sebastianbergmann phpunit-selenium issues" and track down closed issue #22 for more information.
It is definitely working. I have set up selenium tests in symfony measuring the coverage according to the documentation.
The biggest issue I had was, that the coverage data had the wrong path to the files in it, and therefore could not align the sources with the coverage data. This is because I executed tests from a different place, as the server kept the files in. Therefore I tweaked the append.php to rewrite the path to the place where my source files are.