Chrome launching twice when running a Cucumber feature - selenium

I have a problem where Chrome driver is launching twice when I run a feature file.
I'm using Cucumber with Selenium Java using IntelliJ.
The problem came about when I created a new stepdef file for a new area of functionality that I'm working on. So I'm pretty sure this is something to do with how the features are linked to step defs. I'm still learning the ropes here so this is an area I haven't had much experience in.
My Step Defs each come with #Before code to run before every stepdef method and the #Before code contains a
driver.get("https://mywebsite_under_test");
This website URL is different for each of the two StepDef files.
When I launch my test I can see that the two chrome sessions it starts are the ones mentioned in the #Before of each Step Def file. I'm launching from the IDE where I just run the feature.
My project structure is as follows:
├───main
│ ├───java
│ └───resources
└───test
├───java
│ ├───Database
│ ├───Pages
│ └───stepdefs
│ ├───MOPStepDefs
│ └───MOSStepDefs
└───Resources
├───MOP Features
└───MOS Features
I'm out of ideas here. I've messed about with Glue value in the Config but not getting any luck.

With your before tag add the scenario tag so it only runs when you run that scenario i.e. #Before("#MOP") where #MOP is a tag of your feature or scenario. In your instance the syntax should be #Before("#Automated, #MOP")

Related

Karate summary reports not showing all tested features after upgrade to 1.0.0

I have recently upgraded to version 1.0.0 from 0.9.6 and noticed that the generated karate-summary.html file, it doesn't display all the tested feature files in the JUnit 5 Runner unlike in 0.9.6.
What it displays instead was the last tested feature file only.
The below screenshots are from the provided SampleTest.java sample code (excluding other Tests for simplicity).
package karate;
import com.intuit.karate.junit5.Karate;
class SampleTest {
#Karate.Test
Karate testSample() {
return Karate.run("sample").relativeTo(getClass());
}
#Karate.Test
Karate testTags() {
return Karate.run("tags").relativeTo(getClass());
}
}
This is from Version 0.9.6.
And this one is from Version 1.0.0
However, when running the test below in 1.0.0, all the features are displayed in the summary correctly.
#Karate.Test
Karate testAll() {
return Karate.run().relativeTo(getClass());
}
Would anyone be kind to confirm if they are getting the similar result? It would be very much appreciated.
What it displays instead was the last tested feature file only.
This is because for each time you run a JUnit method, the reports directory is backed up by default. Look for other directories called target/karate-reports-<timestamp> and you may find your reports there. So maybe what is happening is that you have multiple JUnit tests that are all running, so you see this behavior. You may be able to over-ride this behavior by calling the method: .backupReportDir(false) on the builder. But I think it may not still work - because the JUnit runner has changed a little bit. It is designed to run one method at a time, when you are in local / dev-mode.
So the JUnit runner is just a convenience. You should use the Runner class / builder for CI execution, and when you want to run multiple tests and see them in one report: https://stackoverflow.com/a/65578167/143475
Here is an example: ExamplesTest.java
But in case there is a bug in the JUnit runner (which is quite possible) please follow the process and help the project developers replicate and then fix the issue to release as soon as possible.

Karate UI standalone - can there be screenshots attached to reports on failure?

I am evaluating Karate UI and really like it. I use it as standalone jar (as the team do not want to support Java project but is fine with JS) and am wondering how can I attach screenshots of the web app generated right when a step fails?
I have seen this question - Attaching screenshots to json report and hope it would be possible to doing something with the standalone version as well.
If you look at the section on "hooks": https://github.com/intuit/karate#hooks
You should be able to use an afterScenario hook like this:
* configure afterScenario = function(){ if (karate.info.errorMessage) driver.screenshot() }
Works with with 0.9.5.RC4. With latest official release 0.9.4 it does not.
Edit2 - works globally with the following line in karate-config.js
karate.configure('afterScenario', read('afterScenarioScreenshot.js'))
Where afterScenarioScreenshot.js contains the JS function from above

Run Cucumber JVM #BeforeClass Without Feature Files

The title may be a bit confusing at this point; hopefully I can clear it up.
What I Have
I'm running Cucumber JVM with Selenium WebDriver to automate our system test cases. These test cases are currently stored in JIRA using the XRay Test Management plugin. XRay also provides APIs to fetch the feature files as well as upload the results back to JIRA.
I have created a custom JIRA utility class to download the tests as feature files and upload the test results from and to JIRA - as well as demonstrated that it does work. These are run in the #BeforeClass and #AfterClass in the Cucumber Runner class respectively.
I have also demonstrated that the developed test framework does work by manually running with feature files created on my computer.
What I Want
I want to be able to (eventually) run the automation test framework automatically with our CI tools. Along with this, it would pull the defined automation tests from JIRA and push the test results back to JIRA.
I do not want the feature files stored with the code. In my opinion, this defeats the purpose of it being dynamic as the tests we execute will change over time (in number executed and the steps themselves).
What Is Happening (Or More Specifically, Not Happening)
When I try to execute the Cucumber Runner class without any feature files in the framework, Cucumber says "No features found at [src/test/resources/features/]". This is understandable since there are no feature files (yet).
However, it does not run the #BeforeClass; thus it does not download the feature files to be run. I have tried this both with and without tags in the runner class.
Code
#RunWith(Cucumber.class)
#CucumberOptions(
tags={"#smoketests"},
features= {"src/test/resources/features/"},
plugin={"json:target/reports/cucumber.json"},
monochrome=true)
public class RunCucumberTest {
#BeforeClass
public static void executeBeforeTests() {
JiraUtil.getFeatureFiles();
//String browser = "firefox";
String browser = "chrome";
//String browser = "safari";
//String browser = "edge";
//String browser = "ie";
DriverUtil.getInstance().setDriver(browser);
}
#AfterClass
public static void executeAfterTests() {
DriverUtil.getInstance().resetDriver();
JiraUtil.uploadTestResults();
}
}
Back To My Question
How can I execute the JIRA Util code so I can download the feature files?
Is it possible to achieve what I want? Or do I have to admit defeat and just have all the feature files stored with the code?
This is the expected behavior when using JUnit. A test suite will not invoke the #BeforeClass, #AfterClass or #ClassRule when there are no tests in the suite or if all tests are ignored[1]. This avoids the execution of a potentially expensive setup for naught.
This does mean you can't use a class rule to bootstrap your tests. Nor should you attempt to do so. In a build process it is a good practice to fetch all sources and resources prior to compilation.
If you are using maven could write a maven instead and attach it to the generate-test-sources phase[2]. Creating a maven plugin is a bit more involved then a JUnit Rule but not prohibitively so. Check the Guide to Developing Java Plugins.
I assume there are similar options for Gradle.

running dart project says dart:html is not available for the standalone vm

I used Git to pull a project
I then start IntelliJ, and say: Open Project.
The project itself looks like it has 4 modules, Lab1, Lab2, Solution2, Solution2
I open the full project. In Lab1, i want to run to see how my web page looks, but when i say: Run main.dart the error kicked back is:
C:\code\dart-sdk\bin\dart.exe --ignore-unrecognized-flags --checked --enable-vm-service:51293 --trace_service_pause_events C:\code\workspace\tw_remoting_training\codelab_01\web\main.dart
Observatory listening on http://127.0.0.1:51293
The built-in library 'dart:html' is not available on the stand-alone VM.
'package:remoting_training/remoting_printer.dart': error: line 20 pos 1: library handler failed
import 'dart:html';
^
Process finished with exit code 254
Im not sure what is going on here though. As a secondary option, i will also try to Right-Click on index.html and click: Open with > Dartium but that shows a blank page. It shouldve done 4 async calls which printed strings to the screen.
Is there something I am missing? Is it not running because of it being a module in a project?
If your Dart script imports dart:html or a library that imports dart:html you can run that script only from the Dartium browser (by adding a script tag to HTML that points the that Dart script, or if you run it through pub build or dart2js in any browser), but it can't be run from the console.
With dart:io it's exactly the opposite, it can't be run in the browser.

Organizing Selenium tests in Django

I am trying to organize my selenium tests better in a Django project.
I have a folder project/app/selenium_tests/ into which I placed an __init__.py, and a tests.py which contains my selenium tests. in the __init__.py I import the tests like so:
from tests import *
But when I do ./manage.py test app.selenium_tests I get:
ValueError: Test label 'app.selenium_tests' does not refer to a test
What could I be missing here? I even added a models.py to the selenium_test package but no joy.
Any help much appreciated.
you need to put the folder selenium_tests under the tests directory of the app, otherwise the default Django test runner will not find it.
so, move this project/app/selenium_tests/ to project/app/tests/selenium_tests/