Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make usable as a library #12

Open
geekdenz opened this issue Sep 4, 2017 · 15 comments
Open

Make usable as a library #12

geekdenz opened this issue Sep 4, 2017 · 15 comments

Comments

@geekdenz
Copy link
Contributor

geekdenz commented Sep 4, 2017

Soon after I published this to a Maven repository, I noticed, that one cannot use this as a library. I've changed my own fork a lot and after a lot of googling and browsing through the Cucumber Java source code found that it is indeed possible to use the step definitions from this library:

https://github.com/geekdenz/selenium-cucumber-java/blob/fb23d90fee928718458370d4f9922bf46c937b20/src/test/java/stepDefintions/RunCukeTest.java#L13

Also see the README:
https://github.com/geekdenz/selenium-cucumber-java/blob/master/README.md#using-canned-tests-in-your-project

You are more than welcome to merge these changes in. I also made it so that if a test fails, it makes a screenshot and puts it into the directory with the scenario ID.

Also, I made the headless Firefox the default driver, so this can be used on a build server. For this some libraries may need to be installed:

sudo apt install libgtk-3-0 libdbus-glib-1-2 xvfb
@sameer49
Copy link
Member

sameer49 commented Sep 5, 2017

@geekdenz thanks for putting your efforts to contribute this library
I will check and merge soon.

@sameer49
Copy link
Member

sameer49 commented Sep 6, 2017

@geekdenz can you provide examples/tests using selenium-cucumber-java as a library?

@geekdenz
Copy link
Contributor Author

geekdenz commented Sep 6, 2017

I will create a sample project soon.

@geekdenz
Copy link
Contributor Author

geekdenz commented Sep 6, 2017

Here you go: https://github.com/geekdenz/selenium-cucumber-java-examples

Hope it works for you. It seems to work fine on Linux. For Windows and MacOS you may need to download the OS's web drivers for Firefox etc.

@sameer49
Copy link
Member

sameer49 commented Sep 8, 2017

@geekdenz I ran the example, its not picking up pre-defined steps from library as it showing steps not implemented errors.

@geekdenz
Copy link
Contributor Author

geekdenz commented Sep 8, 2017

@sameer49 This is bizarre since it works perfectly for me. Are you using ./gradlew on Linux?

@sameer49
Copy link
Member

sameer49 commented Sep 8, 2017 via email

@geekdenz
Copy link
Contributor Author

geekdenz commented Sep 8, 2017

Can you please try with gradlew? It works even when you don't have it installed and gradle is more powerful than maven. Android uses it as its default build system and it has a Turing complete scripting language in the bills tool. You will need the driver in the same directory on windows. I can look into making it work with Maven later maybe, although I don't know why you would use maven over gradle tbh.

@geekdenz
Copy link
Contributor Author

geekdenz commented Sep 8, 2017

If you really want to use Maven, you need to look at the test task in the build.gradle file for its parameters to make it work and possibly write a maven plugin if it doesn't support the same options with xml or an existing plugin.

@sameer49
Copy link
Member

sameer49 commented Sep 8, 2017 via email

@geekdenz
Copy link
Contributor Author

geekdenz commented Sep 9, 2017

Hi @sameer49

Yeah, sorry but I assumed it would work on Windows as well, which it doesn't. It does work on Linux though, which is weird since it is Java and supposedly cross-platform. I'm looking into what might be the problem but I am getting an exception when I try to run the tests on Windows.

How did you manage to get it to a state where the tests were suggested? I don't even get that far on Windows. It fails when it tries to connect to the browser driver, although I have it in the folder.

Could you post in more detail the errors you are getting, please?

@geekdenz
Copy link
Contributor Author

geekdenz commented Sep 9, 2017

Hi @sameer49

I think it should work now also on Windows. Did some cleanup of how the DriverUtil is used to ensure there is only one instance used.

Can you please try again on Windows with Gradle?

@sameer49
Copy link
Member

okay

@sameer49
Copy link
Member

following error I got when try to run with gradle.

tk.landcare.sampletests.TestRunner STANDARD_OUT
Expected only one instance, but found too many: [cucumber.runtime.java.picocontainer.PicoFactory@493e3dd, cucumber.runtime.java.guice.impl.GuiceFactory@234a73a5]
More than one Cucumber ObjectFactory was found in the classpath
You probably may have included, for instance, cucumber-spring AND cucumber-guice as part of
your dependencies. When this happens, Cucumber falls back to instantiating the
DefaultJavaObjectFactory implementation which doesn't provide IoC.
In order to enjoy IoC features, please remove the unnecessary dependencies from your classpath.

Feature: Learning selenium-cucumber using java
  As a tester I want to learn selenium-cucumber

tk.landcare.sampletests.TestRunner > Scenario: I am learning selenium-cucumber.classMethod STARTED

tk.landcare.sampletests.TestRunner > Scenario: I am learning selenium-cucumber.classMethod STANDARD_OUT
Failure in before hook:PredefinedStepDefinitions.before()
Message: org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:23911 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect


When I run using maven it opens multiple instance of browser and at end it shows all test steps as pass but scenario fail.
https://github.com/selenium-cucumber/selenium-cucumber-java-maven-example

Failed scenarios:
features/my_first.feature:4 # Scenario: I login with valid credential

1 Scenarios (1 failed)
6 Steps (6 passed)
0m25.552s

java.lang.NoSuchMethodError: env.DriverUtil.closeDriver()V
at info.seleniumcucumber.stepdefinitions.PredefinedStepDefinitions.tearDown(PredefinedStepDefinitions.java:561)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at cucumber.runtime.Utils$1.call(Utils.java:40)
at cucumber.runtime.Timeout.timeout(Timeout.java:16)
at cucumber.runtime.Utils.invoke(Utils.java:34)
at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:60)
at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:224)
at cucumber.runtime.Runtime.runHooks(Runtime.java:212)
at cucumber.runtime.Runtime.runAfterHooks(Runtime.java:206)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:46)
at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:95)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:38)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at cucumber.api.junit.Cucumber.run(Cucumber.java:100)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

@sameer49
Copy link
Member

sameer49 commented Sep 22, 2017

@geekdenz it working now, in my project few files ware outdated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants