I started learning Cucumber (Behavior Driven Testing Framework) and based on certain videos and some reading, I understood that Cucumber will auto generate a skeleton code for the step definitions, defined in feature file. However, I do not see any test being executed or any code being generated. My project setup is as below
Project
----src/main/java/testrunner/MyTestRunner.java
----src/main/resources/feature/dailyroutine.feature
Feature file is looking like below
Feature: Test Facebook smoke Scenario
Scenario: Test with valid credentails
Given: Open firefox and start application
When: when I enter with valid username and password
Then: I should be able to login into Facebook Homepage
TestRunner is as below
package testrunner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features ={"src/main/resources/feature/dailyroutine.feature"},
dryRun=true,
strict=true,
monochrome=true)
public class MyTestRunner {
}
When I run the TestRunner as JUnit I'm getting
0 Scenarios
0 Steps
0m0.000s
What is the mistake I'm doing
I would like to propose an alternative feature file scenario steps
Feature Test Facebook smoke Scenario
Scenario Success login with valid credentails
Given Using the browser "firefox"
And Username is "myUsername" with Password "myPassword"
When Submit login request
Then Successfully logged in to Facebook
The problem could be how the feature file is worded, namely the extra colons for the Given, When and Then.
I've also made changes to how the feature file has been written, in order to better inform the reader about what the test is trying to achieve - as the #1 thing that Behaviour Driven Development (and the frameworks for it) focus on is communication between the development team and the business.
Feature: Logging into Facebook...
Scenario: with valid credentials
Given I navigate to "Facebook"
When I log in with my valid login details
Then I should be able to see my newsfeed
There may be other issues, but for the time being, the colons are the issue that sticks out to me
Edit
I should have read the comments section, because this was solved 2 days before this answer
Remove the colon (:) after the keywords (Given, When, etc) in your feature file.
Related
I'm trying to send the currently logged-in user in a Post-Request to a REST-Endpoint when the issue is assigned. I set up a project automation with a ScriptRunner Script.
According to several sources (see below) the following should do the magic.
import com.atlassian.jira.component.ComponentAccessor
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
This snippet works, but it's always my user, that is sent. Doesn't matter if I'm logged in or my colleague. What am I missing?
The same problem occurs when I use the built-in field currentUser.
Sources:
https://community.atlassian.com/t5/Jira-questions/How-to-get-current-user-in-jira-application/qaq-p/818002
https://scriptrunner.adaptavist.com/5.2.1/jira/recipes/behaviours/scripted-conditions.html
https://innovalog.atlassian.net/wiki/spaces/JMWE/pages/138353228/Getting+the+current+user+-+Groovy
I'm working on a CLI with OCLIF. In one of the commands, I need to simulate a couple of clicks on a web page (using the WebdriverIO framework for that). Before you're able to reach the desired page, there is a redirect to a page with a login prompt. When I use WebdriverIO methods related to alerts such as browser.getAlertText(), browser.sendAlertText() or browser.acceptAlert, I always get the error no such alert.
As an alternative, I tried to get the URL when I am on the page that shows the login prompt. With the URL, I wanted to do something like browser.url(https://<username>:<password>#<url>) to circumvent the prompt. However, browser.url() returns chrome-error://chromewebdata/ as URL when I'm on that page. I guess because the focus is on the prompt and that doesn't have an URL. I also don't know the URL before I land on that page. When being redirected, a query string parameter containing a token is added to the URL that I need.
A screenshot of the prompt:
Is it possible to handle this scenario with WebdriverIO? And if so, how?
You are on the right track, probably there are some fine-tunings that you need to address to get it working.
First off, regarding the chrome-error://chromewebdata errors, quoting Chrome DOCs:
If you see errors with a location like chrome-error://chromewebdata/
in the error stack, these errors are not from the extension or from
your app - they are usually a sign that Chrome was not able to load
your app.
When you see these errors, first check whether Chrome was able to load
your app. Does Chrome say "This site can't be reached" or something
similar? You must start your own server to run your app. Double-check
that your server is running, and that the url and port are configured
correctly.
A lot of words that sum up to: Chrome couldn't load the URL you used inside the browser.url() command.
I tried myself on The Internet - Basic Auth page. It worked like a charm.
URL without basic auth credentials:
URL WITH basic auth credentials:
Code used:
it('Bypass HTTP basic auth', () => {
browser.url('https://admin:admin#the-internet.herokuapp.com/basic_auth');
browser.waitForReadyState('complete');
const banner = $('div.example p').getText().trim();
expect(banner).to.equal('Congratulations! You must have the proper credentials.');
});
What I'd do is manually go through each step, trying to emulate the same flow in the script you're using. From history I can tell you, I dealt with some HTTP web-apps that required a refresh after issuing the basic auth browser.url() call.
Another way to tackle this is to make use of some custom browser profiles (Firefox | Chrome) . I know I wrote a tutorial on it somewhere on SO, but I'm too lazy to find it. I reference a similar post here.
Short story, manually complete the basic auth flow (logging in with credentials) in an incognito window (as to isolate the configurations). Open chrome://version/ in another tab of that session and store the contents of the Profile Path. That folder in going to keep all your sessions & preserve cookies and other browser data.
Lastly, in your currentCapabilities, update the browser-specific options to start the sessions with a custom profile, via the '--user-data-dir=/path/to/your/custom/profile. It should look something like this:
'goog:chromeOptions': {
args: [
'--user-data-dir=/Users/iamdanchiv/Desktop/scoped_dir18256_17319',
],
}
Good luck!
Using Serenity-Cucumber, I am trying to build a test suite so that I can reuse the step definitions (Given, When, Then, And..) through out multiple feature files.
For example:
Scenario: User Logs in
Given User is on the Login page
When User Logs in using 'userName' and 'password'
Then User on page containing: '/logedin/url/path'
The above test case logs in a user and I will need to use it for other Scenarios. For example, if I add a test case to update a password, the above Scenario will need to be performed before the update password scenario.
The test will need to perform the Login steps and then update password steps. From my limited knowledge, it seems like I will need to have this in the Background: step. So before my update password scenario I will have the following:
Background: User Logs in
Given User is on the Login page
When User Logs in using 'userName' and 'password'
Then User on page containing: '/logedin/url/path'
Scenario: User Updates Password
Given User is on the Manage Account page
When User clicks Update Password
And User type 'existingPassowrd' and 'newPassword'
And User clicks Update Password
Then Password is displayed as 'newPassword'
This gives me an error cucumber.runtime.DuplicateStepDefinitionException which I understand, but I keep reading that serenity-cucumber gives the the option to reuse steps, which again, I get and is a good idea.
So, How do I reuse scenarios or a scenarios' step definitions in other tests? I don't need a new method for them, I just need to call the existing method that I created in the previous scenario.
Is there a way to do this?
Can I do something like this? (or do i not even need to write out the background?)
#Steps
User user;
//This is the background in the feature file.
//Instead of creating methods, I would just reference the pre-existing ones from the other test case.
#Given("^User is on the Login page$")
#When("^User Logs in using '(.*)' and '(.*)'$")
#Then("^User on page containing: '(.*)'$")
//This is the Scenario in the feature file
#Given("^User is on the Manage Account page$")
public void user_is_on_the_manage_account_page(String expectedUrl) throws Exception {
user.is_on_page(expectedUrl);
}
#When("^User clicks Update Password$")
public void user_clicks_update_password() throws Exception {
user.click_update_password();
}
code continues
...
...
...
Found the answer...
As long as the feature file text:
Given User is on the Login page
is written the same in multiple feature files, you only need to write the "step definition" method once
#Given("^User is on the Login page$")
public void user_is_on_the_login_page() throws Exception {
user.is_on_login_page();
}
"User is on the login page" can keep getting re-written on multiple feature files, it will always use that same method user_is_on_the_login_page() and no code needs to be written on that test's step definition file.
Below is python test code to login jira using username and password and it works fine.
from jira import JIRA
jira = JIRA('http://xxx')
jira = JIRA(basic_auth=('username','password'),options={'server': 'http://xxx'})
issue = jira.issue('XXXX-762')
print "For task", issue,", summary is-", issue.fields.summary
Now I require to log in jira without using password.
can anyone help?
Aim of this is to hide the password in general script and also make the script independent of jira password expiry.
Jira version used: JIRA v7.5.2
Thank you.
If I understand correctly, you're wanting to obfuscate the password inside of the script? If so, this is not really a JIRA/python problem. The easiest is to base64 encode the password beforehand and then just use:
jira = JIRA(basic_auth=('username',base64.b64decode("<encrypted_password")),options={'server': 'http://xxx'})
This, of course, doesn't fully protect you but at least makes it much less obvious.
You can work with your Jira administrator to set up OAuth for authentication for your script instead of basic auth, which would eliminate the need for a password. It requires considerable setup to get it working, but would ultimately serve your needs.
Here is an overview from Atlassian on how the overall process works: https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-oauth-authentication/
Here is a link to the Atlassian repository for examples on setting up OAuth including an example in Python: https://bitbucket.org/atlassian_tutorial/atlassian-oauth-examples/overview
I just set the password in an environment variable and have the script read it.
from jira import JIRA
jira_user = os.environ.get("JIRA_USERNAME", None)
jira_password = os.environ.get("JIRA_PASSWORD", None)
jira_server = {'server': "https://jiraserver.url"}
jira = JIRA(options=jira_server, basic_auth=(jira_user, jira_password))
I'm a programmer who is just getting started working with groovy in Jira in order to automate some tasks.
I'm trying to write a custom listener script using the inline editor in Jira, but haven't gotten past trying to get a Hello World program to work.
I don't know if the script is running, and can't see any output, and I really need some help with figuring out how to debug the script, preferably through outputs to some kind of console (or even just by reading the Jira logs if necessary), just so that I can actually start trying to learn how to use this tool.
I'm working with the information HERE as a general guideline to start learning to work with the inline editor.
For a little more context, you can see another related question that I asked HERE.
I've set the debug level to DEBUG for the event which I'm attaching the listener, as shown in this screenshot, based on the information found HERE:
Here is a screenshot of the inline editor I'm working in in JIRA. In this screenshot, I'm just trying to output 'Hello', and have just clicked the 'Preview' button:
As you can see, in the 'Result' tab at the bottom of the screen, there is nothing of interest. The 'Logs' tab is also empty, and the 'Timing' tab just says 'Elapsed: 0 ms CPU time: 0 ms', so it seems like nothing if happening.
If I check the log on the server (in the file catalina.2017-10-13.txt), I see the following output:
13-Oct-2017 07:01:50.942 WARNING [http-nio-8080-exec-6] com.sun.jersey.spi.container.servlet.WebComponent.filterFormParameters A servlet request, to the URI http://somevmserver:8080/rest/scriptrunner-jira/latest/listeners/com.onresolve.scriptrunner.canned.jira.workflow.listeners.CustomListener/params, contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using #FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.
13-Oct-2017 07:02:26.740 WARNING [http-nio-8080-exec-12] com.sun.jersey.spi.container.servlet.WebComponent.filterFormParameters A servlet request, to the URI http://somevmserver:8080/rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.common.StaticCompilationChecker, contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using #FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.
13-Oct-2017 07:02:26.974 WARNING [http-nio-8080-exec-1] com.sun.jersey.spi.container.servlet.WebComponent.filterFormParameters A servlet request, to the URI http://somevmserver:8080/rest/scriptrunner-jira/latest/listeners/com.onresolve.scriptrunner.canned.jira.workflow.listeners.CustomListener/preview, contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using #FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.
This output doesn't mean a whole lot to me, but it seems apparent that it's being populated as a result of trying to preview the script.
I'm not getting any errors in the inline editor, and it's really simple code, so I don't think it's that.
The only other information I can include that I think is pertinent is that this is a test instance of Jira cloned from our production environment, and its base URL is still set to the URL of the prod environment. Not sure if that has any bearing, but I'm not really a Jira admin, just the programmer tasked with doing this, so I don't want to go fiddling around where I don't need to.
Thanks!
When using scriptrunner within jira, you'll need to import the logger to use the debugger or to output to the console. This can be done with the following:
// Enable debugger
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
And then, you'll be able to see the logged information using log.debug "hello"
To see your debug message "Hello" in the log, you must update a issue in your selected project. The Result, Logs and Timing Tabs at the bottom are useless in this view. Just trigger the Listener with a issue update in your selected project and search your debug message in the atlassian-jira.log file.
Hint: To view the Log in the browser you can use this jira app https://marketplace.atlassian.com/plugins/com.cps.lastLog/server/overview