Cucumber -Given precondition - cucumber

Hello everyone,
To proceed with order product scenario I should log in, I am asking if I could use in my scenario a given step like :
Scenario: Order product
Given I log in
.
.
And in the steps defintion class I will call the login steps inside the given of order product:
#Given("^I log in$")
public void I_log_in(){
Given(string.Format("I am on login page"));
When(string.Format("I log in with valid username and password));
Then (string.Format("I should be logged in));
}
PS: I tried to use the hook before to run login actions before this scenario using a tag (above it), but I find it's not a good practice to set actions on before, also the Backgound keyword will not work here beacause there are scenarios in the same feature don't require login.
Thanks in advance

I don't think you can do this and you definitely don't want to do this.
If we look at each step you want to nest and think about the code inside it we have
Note: I don't cuke in java but I'll try and explain using your code
Given(string.Format("I am on login page"))
foo code
...
When(string.Format("I log in with valid username and password));
bar code
...
note: the ellipsis represent all the code that does stuff
Now if you want to implement I am on login page and I log in with valid username and password then you can just do
Given(string.Format("I am on login page and I log in with valid username and password")
foo code
...
bar code
...
Now the only problem you have is that you have two copies of foo code. You can solve that by extracting a method. This would give you
Given(string.Format("I am on login page and I log in with valid username and password")
call foo code
call bar code
and would mean that you rewrite your original steps as
Given(string.Format("I am on login page"))
call foo code
When(string.Format("I log in with valid username and password));
call bar code
If you write all your step definitions as single line calls, then you can easily make compound step definitions by just combining calls.
Finally you should make your compound step definition a single call
Given(string.Format("I am on login page and I log in with valid username and password")
call baz code
and then implement baz as
void baz() {
foo
bar
}
So now even your compound call is defined outside of your step definitions.
To do this you have to understand Cucumbers mechanism for allowing you to define and call methods outside of step definitions. This is really easy in Ruby, but I don't know the java equivalent, apologies.
Eventually you'll end up with a number of methods foo, bar, baz that you have to organise. Thats a known simple problem which all programming languages support. By taking this problem out of Cucumber and into Java you will (in the longer term) make things much simpler for yourself.
I hope you can use the ideas here to make you Cuking simpler.

Since it's a precondition, I'd rewrite to Given I am logged in (or maybe even provide some information about what type of user logs in, rather than use I? like a customer, admin, ...?)
Note that you cannot call steps from steps in cucumber-jvm (by design!)
Inside your login() method, you can call several helper methods that perform the actions needed to actually be logged in, like:
navigateToLoginPage();
enterUsernamePassword("user", "pass);
assert.something() // Make sure login was successful
Also, log a message when login was not successful; which will help you analyse failures)

Related

Issues regarding calling a custom function in a Netsuite CS script on button click

I added a button to my employee form via a UE script to which I bound the 'createDebtor' function, which I made in the CS script which I attached to my UE script.
I am not really familiar with this method yet and run into some errors in my CS script. The following is the start of my CS script:
I added both console and script logging, because the script logging did not work. Note that the alert function works, so the initialization of the code and binding of the function works correctly. I have the following questions regarding my code:
*Why does log.debug not work (I am owner of the script and the script deployment has debug log level and testing status)
*Trying to console.log the 'employee' variable returns a readOnly object with the methods like 'getvalue', but no properties containing data. Is there an easy way to obtain and log all the properties of this object?
*As a followup to the previous question I tried to use the 'getValue' function to obtain data, but this returns 'undefined' for the 'subsidiary' field. (the field ID should be correct, as I got it from the employee form itself). Could someone advice what I am doing wrong here?
Suite Answers 68476, 74121, and 10564 suggest that you try/confirm the following:
In the User Event script, call form.setScript() before form.addButton().
Check the execution log of the User Event script, not the Client Script.
Confirm that the Log Level is set correctly, I assume on the User Event script and the Client Script.

router.get(), use only part of url?

Currently I have this code:
router.get('/admins', function(res,req) {
However, I want it to be when someone goes to say, 'localhost:5000/admins/54323', I want the node-js app to notice 'hey, they're requesting for an admins list! lets find it'. However, with the router.get() function it only works if it is exactly that, is there a way to have it so if only the start is /admins then it sets a variable for the final part?
Through more research, I found an answer. I just put /:id after the /admins bit,
you can access the rest of the string in req.params.id where .id is the same as the string written after the : sign

My program turns a spreadsheet into an Excel-file. But it only works for one user

I've made a larger (1000+ lines of code) App Script. It works great, for me. No other user can run it. I want them to be able to run it as well, and I can not figure out why they can't.
The problem occurs on this part:
var id = 'A_correct_ID_of_a_Google_Spreadsheet';
var SSurl = 'https://docs.google.com/feeds/';
var doc = UrlFetchApp.fetch(SSurl+'download/spreadsheets/Export?key='+id+'&exportFormat=xls',googleOAuth_('docs',SSurl)).getBlob();
var spreadsheet = DocsList.createFile(doc);
The function (and structure) was published here: other thread
function googleOAuth_(name,scope) {
var oAuthConfig = UrlFetchApp.addOAuthService(name);
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setConsumerKey('anonymous');
oAuthConfig.setConsumerSecret('anonymous');
return {oAuthServiceName:name, oAuthUseToken:"always"};
}
I can't see any reason why the program only would run for one user. All the files are shared between all the users and ownership have been swapped around.
When a script uses oAuth (googleOAuth_(name,scope) in you case) it needs to be authorized from the script editor, independently from the other authorization that the user grands with the "normal" usual procedure.
This has been the object of an enhancement request for quite a long time and has no valid workaround as far as I know.
So, depending on how your script is deployed (in a SS or a Doc or as webApp) you might find a solution or not... if, as suggested in the first comment on your post, you run this from a webapp you can deploy it to run as yourself and allow anonymous access and it will work easily, but in every other case your other users will have to open the script editor and run a function that triggers the oAuth authorization process.

"immediate_failed" - Could not automatially log in the user

I have a problem when I developed my website with Google+ sign-in:
I did step by step that the doc told me but I always failed at step4:
https://developers.google.com/+/web/signin/
the result was always ""immediate_failed" - Could not automatially log in the user", I just don't kown why, can anyone help me, thanks very much! :-(
Note that in the sample code you pointed to, the "immediate_failed" check is commented out. This is intentional, since the first time a user encounters the Sign-in button on the page, it will fail.
The reason it fails is that when the page first loads, before the user even presses the button, a request is sent to Google to determine if the user has already logged in (via Google or another site, for example). If they are - there is no need for them to log in again, so the button never needs to be shown. But if they have not been logged in already, you will get the "immediate_failed" response, and will need to either show (or not clear) the button.
tl;dr - Don't worry aout getting immediate_failed when the page first loads. This is normal.
As a workaround I use gapi.auth.authorize method in the gapi.auth.signIn callback. Here is my code:
gapi.auth.signIn({
'callback': gPlusLoginCallback
});
function gPlusLoginCallback(authResult) {
if (authResult['status']['signed_in']) {
doSmth(authRes['access_token']);
} else if (authResult['error'] == "immediate_failed") {
gapi.auth.authorize({
client_id: gplusClientId,
scope: 'https://www.googleapis.com/auth/plus.login email',
immediate: true
}, function (authRes) {
if (authRes['status']['signed_in']) {
doSmth(authRes['access_token']);
}
});
}
}
function doSmth(accessToken){
//Do smth
}
Change this setting "immediate: true", to be false " immediate: false".
But if you like to make more complex implementation look at the first sample here https://developers.google.com/api-client-library/javascript/start/start-js. You have to calls to Google's "gapi.auth.authorize({...", the first one with "immediate: true", and the second one with "immediate: false".
The question is old but I faced this issue recently.
In my case, it was because I specified the URI parameter prompt to none. I guess Google doesn't like that if the user has never been logged to your platform before.
Whenever I changed that to consent or totally removed it, it worked great.
In my case, the error was because of explicitly specifying the authorization parameter prompt to 'none',similar to a previous answer.
It worked for me by specifying prompt=None or as per the official docs,you may skip this parameter.

Masking part of URL in jetty request log

I would like to log all HTTP request in Jetty, which is well documented, but I can;t find any resources how can I mask some of the arguments.
E.g.:
json/users/detail?id=dsgrw543
should be logged as:
json/users/detail?id=********
or similar.
The main motivation is that I could give those logs for analytics, without worries that privacy of our users could be compromised. Ideally on-line, without using batch processing or other script.
Please note, that I use other authentication mechanism (cookies/all write methods are POST/etc.) and I can't change the existing URLs.
So far my only idea is to implement it as a class on top of NCSARequestLog:
http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/server/NCSARequestLog.html
What are the better ways of doing that?
you may write a simple util like this, use it wherever you are logging
Enumeration<String> s = request.getParameterNames();
String q = "";
while(s.hasMoreElements()){
q += s.nextElement() + "=***&";
}
String url = request.getServletPath()+(q.length()>0?"?"+q:"");
or may be request.getRequestedURI() in place of getServletPath

Resources