How do I run specific scenario in cucumber - selenium-webdriver

How to run specific scenario in cucumber out of multiple scenario?
Feature file
Feature: Test Test Smoke scenario
Scenario: Test login with valid credentials
Given open firefox and start application
jhbhhjhj
When I click on Login
And enter valid "kumar.rakesh#yopmail.com" and valid "admin#123"
Then Click on login and User should be able to login successfully
Scenario: Test shop for cart
Given Click on shop for carts
And select plates
When Click on Add to cart
Then product should be added in the cart successfully
And verify the product
Scenario: Test login with valid credentials1
Given open firefox and start application
When I click on Login
And enter valid "kumar.rakesh#yopmail.com" and valid "admin#123"
Then Click on login and User should be able to login successfully
Scenario: Test shop for cart1
Given Click on shop for carts
And select plates
When Click on Add to cart
Then product should be added in the cart successfully
And verify the product
Test Runner
package runner;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#Cucumber.Options(features="features",glue={"steps"},format = {"pretty", "html:target/Destination"})
public class TestRunnr {
}

Use tags future in the cucumber like below.
Feature: Test Milacron Smoke scenario
#Test1
Scenario: Test login with valid credentials
Given open firefox and start application
When I click on Login
And enter valid "kumar.rakesh#thoughtfocus.com" and valid "Thought#123"
Then Click on login and User should be able to login successfully
#Test2
Scenario: Test shop for cart
Given Click on shop for carts
And select plates
When Click on Add to cart
Then product should be added in the cart successfully
And verify the product
#Test3
Scenario: Test login with valid credentials1
Given open firefox and start application
When I click on Login
And enter valid "kumar.rakesh#thoughtfocus.com" and valid "Thought#123"
Then Click on login and User should be able to login successfully
#Test4
Scenario: Test shop for cart1
Given Click on shop for carts
And select plates
When Click on Add to cart
Then product should be added in the cart successfully
And verify the product
If you want to run only Test1 scenario update runner file like below.
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features="features",glue={"steps"},format = {"pretty", "html:target/Destination"},tags={"#Test1"})
public class TestRunner {
}
If you want to execute multiple scenarios keep comma sepearated tags as mentioned below.
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features="features",glue={"steps"},format = {"pretty", "html:target/Destination"},tags={"#Test1,#Test2"})
public class TestRunner {
}

Like the other answers suggest, use tags. If you use maven, you don't have to change the runner file - just add this to your maven call
-Dcucumber.options="--tags #Test1"
The thing I like about this method is that I don't risk committing the tags in the runner file.
Also, here is an example on running multiple tags in maven.

You can either use selective feature file or selective scenarios in the feature using tags. Please try with this solution.
Lets consider the you have n number of feature files and you need to run only selective feature from that. Then name each feature file with #tag name.
eg.: Under this folder, if you are having n number of features - "src/main/resources/publish"
1st Feature file name:
Login.feature
//Inside the file start with feature tag name
#Login
Feature: To Login to Email
//Then feature name followed with scenario tag name
#User1
#Scenario1:
Scenario Outline: Navigate and logon to gmail application
Given User launches gmail application
When User updates emailID <emailID>
And User updates pwd <pwd>
Then User clicks on Login Button
Examples:
| emailID | pwd |
| a#gmail.com| 123 |
#User2
#Scenario2:
Scenario Outline: Navigate and logon to facebook application
//Write the code for scenario 2 as similar to above
2nd Feature File name:
CreateEmail.feature
#Createmail
Feature: Create email
Scenario: Blah blah blah...
//Write all Given when And Then
3rd Feature File name:
SendEmail.feature
#Sendemail
Feature: Send email
Scenario: Blah blah blah...
//Write all Given when And Then
So From the above Test files. Lets consider you want to test 1st and 3rd feature alone, Then you can use code as below:
eg.:
//This is to run specific feature files, which is 1 and 3. Likewise you can use the tags for scenario as well if you have n number scenario in same feature file.
#CucumberOptions(features= "src/main/resources/publish", tags="#Login, #Sendemail", format = {"pretty"} )
// This is to run specific scenario in the feature file. If you have multiple scenario, then you can write your specify your scenario tags followed by comma.
#CucumberOptions(features= "src/main/resources/publish/Login.feature", tags="#User2", format = {"pretty"} )

You need to use tags to filter out the scenario. Put the tag on the feature file and add this to the cucumberoptions of the runner.
#RunScenarioExample
Scenario: Test login with valid credential
#Cucumber.Options(features="features",glue={"steps"},format = {"pretty", "html:target/Destination"}, tags={"#RunScenarioExample"})

Related

Keeping same session, 1 single browser

The title of the question may be irrelevant to what I am trying to find out. My goal is to write a test that will
A) login to Hotmail
B) Delete the junk mail in my junk folder.
Design wise I have created 2 separate test classes. TestSignInPage1.class is only testing the user login part which is working and passed.
TestJunkFolderDelete.class will go to junk mail folder and do the deletion. I understand I simply can’t use the junk delete test on its own, a user 1st needs to login to the account so I called the TestSignInPage1 class in the junk folder.
#Test
public void testJunk(){
//The part below will get my login credential from TestSignPage class
TestSignInPage1 t= new TestSignInPage1();
t.testPage1();
//The following part will handle junk folder clean operation
WebDriver driver=br.openBrowser("firefox", "https://outlook.live.com/owa/?realm=hotmail.com&path=/mail/junkemail");
JunkMail jm= PageFactory.initElements(driver, JunkMail.class);
jm.doJunkClean();
Problem: Once the login part has been executed, the junk folder delete test opens up another new browser and again asks for login information.
Question: In professional world how would you tackle this (i.e.: you will have 1 test only, is there a way to keep the same session 1 browser) etc?

Updating user info in liferay database

I need to update info of an existing user in my database programmaticaly
I need to update user name birth date values in user_ table in Liferay database
basically I need to run an update query.
It is not recommended to update the liferay database directly, you should use Liferay API instead to do these things. As per this liferay forum post:
The Liferay database is not published for a reason. The reason is the API does significantly more stuff than just simple SQL insert statements. There are internally managed foreign keys, there are things which are updated not just in the database but also in the indices, in jackrabbit, etc.
Since all of this is managed by the code and not by the database, any updates to the code will change how and when the database is updated. Even if it did work for you in a 6.1 GA1 version, GA2 is coming out in a couple of weeks and the database/code may change again.
Sticking with the API is the only way to insure the changes are done correctly.
Ok enough preaching and back to your problem, here are some ways you can do these:
you can either build a custom portlet and use liferay's services and update the username, birthdate etc using UserLocalServiceUtil.updateUser() method.
Or you can build a web-service client based on SOAP or JSON to update the details which would call the same method
Or you can use Liferay's Beanshell tool to do this from the control panel, following is some code to update the user (created just for you ASAP):
import com.liferay.portal.model.Company;
import com.liferay.portal.model.Contact;
import com.liferay.portal.model.ContactConstants;
import com.liferay.portal.model.User;
import com.liferay.portal.service.CompanyLocalServiceUtil;
import com.liferay.portal.service.ContactLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
long companyId = 10135; // this would be different for you
User user = UserLocalServiceUtil.getUserByEmailAddress(companyId, "test#liferay.com");
// Updating User's details
user.setEmailAddress("myTest#liferay.com");
user.setFirstName("First Test");
user.setLastName("Last Test");
user.setScreenName("myTestScreenName");
UserLocalServiceUtil.updateUser(user, false);
// Updating User's Birthday
// December 12, 1912
int birthdayMonth = 11;
int birthdayDay = 12;
int birthdayYear = 1912;
Calendar cal = new GregorianCalendar();
cal.set(birthdayYear, birthdayMonth, birthdayDay, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
Date birthday = cal.getTime();
System.out.println("Updated User: " + user + "\nBirthdate to be updated: " + birthday);
long contactId = user.getContactId();
Contact contact = ContactLocalServiceUtil.getContact(contactId);
if(contact == null) {
contact = ContactLocalServiceUtil.createContact(contactId);
Company company = CompanyLocalServiceUtil.getCompany(user.getCompanyId());
contact.setCompanyId(user.getCompanyId());
contact.setUserName(StringPool.BLANK);
contact.setCreateDate(new Date());
contact.setAccountId(company.getAccountId());
contact.setParentContactId(ContactConstants.DEFAULT_PARENT_CONTACT_ID);
}
contact.setModifiedDate(new Date());
contact.setBirthday(birthday);
ContactLocalServiceUtil.updateContact(contact, false);
System.out.println("Users birthdate updated successfully");
The contact code is built with the help of Liferay's source code for UserLocalServiceImpl#updateUser method
In case you are wondering what is bean-shell and where to put this code, here is where you can find it in Liferay Control Panel Control Panel --> Server --> Server Administration --> Script
It depends on whether you have to do this in a portlet code or by sending a direct query to db.
Liferay basically caches everything, so if you update a record in the Liferay database while the portal is running, most likely that record is already in cache, and so the new column values won't be read at all. You will have to clear the database cache by going to Control Panel -> Server Administration.
On the contrary, if you have to do such a thing in a portlet code, you should call one of the methods of the Liferay services. You're trying to update a User, so you should call the method UserLocalServiceUtil.updateUser (or UserServiceUtil.updateUser if you also want to check permissions).
You can see there are some different updateUser methods, one of them has a lot of parameters and another has only the bean as a parameter. While the first one contains all the business logic (validation, reindexing, update of related entities, etc.), the second one was just autogenerated and should not be used (except when you absolutely know what you're doing). So, use the method with a lot of parameters, simply passing user.getCOLUMN() (eg. user.getFacebookId()) if you don't want to change the value of that column.
Hope it helps, and sorry for my bad English...
update user_ set firstName="New First Name", lastName="New Last Name" where emailAddress="test#test.com";
update contact_ set birthday="date string" where contactId in(select contactId from user_ where emailAddress="test#test.com");
By first update query you can change firstName, lastName of user and by second query you can change birthdate of user.
Hope its clear!
Try this code..
Here i am updating only user First name(rest you can do by your own way)
userId = you can get this using theme display
User user = UserLocalServiceUtil.getUser(userId);
user.setFirstName("new name");
UserLocalServiceUtil.updateUser(user);
Hope this will help you !!!

Oracle Apex - Creating own Login page

I created a new login page wherein only those account that can be found on the database could login to our home page...
What i plan is when i click the login button, the user will be redirected to the home page.. I do this by creating a new branch and then in the conditions tab, i put the code for checking the existence of the account that has been inputted in the text field.. but what happened is it just show an error message 'invalid login credentials' always...
i'm sure that the code in conditions that we put is correct,,,, it could detect that the username and password is wrong because it shows the error message i created that returns when this happend...
here is the code in my conditions.. check_login is a procedure that returns true if the account is found in the database...
if CHECK_LOGIN(:P111_USERNAME, :P111_PASSWORD) then return true;
else
return false;
end if;
could anyone help us with this one? Thanks in advance
You need a custom authentication scheme to solve this, not conditional branching etc. You also do not need to build a new login page. The standard login page will hold all you need, and will simply use the current active authentication scheme. Authentication schemes can be found under the Shared Components.
You can find some oracle documentation here. There are also plenty of blog posts to be found when you search for "oracle apex custom authentication" on google!
Also, when creating a custom scheme, you can click the item labels for help. For example, this is in the authentication function name help:
Specify the name of the function that will verify the user's username
and password, after they were entered on a login page. If you enter
nothing, you allow any username/password to succeed. The function
itself can be defined in the authentication's 'PL/SQL Code' textarea,
within a package or as a stored function.
This function must return a boolean to the login procedure that calls
it. It has 2 input parameters 'p_username' and 'p_password' that can
be used to access the values an end user entered on the login page.
For example, enter the following code in the 'PL/SQL Code' textarea
function my_authentication (
p_username in varchar2,
p_password in varchar2 )
return boolean
is
l_user my_users.user_name%type := upper(p_username);
l_pwd my_users.password%type;
l_id my_users.id%type;
begin
select id , password
into l_id, l_pwd
from my_users
where user_name = l_user;
return l_pwd = rawtohex(sys.dbms_crypto.hash (
sys.utl_raw.cast_to_raw(p_password||l_id||l_user),
sys.dbms_crypto.hash_md5 ));
exception
when NO_DATA_FOUND then return false;
end;
and
my_authentication
as 'Authentication Function'.
Note that your function requires parameters p_username and p_password!
You can leave the other fields blank, they will be handled by default functions!

How can I let individual users import their own external blog feeds in Drupal 7?

So, I'm trying to build a 'blog gateway' in Drupal 7 that will let users add/edit/remove feeds from their own external sites to a collective stream for rating, comments etc.
The site should do something along the lines of:
Let the user add a URL for their feed via the registration form
Import the most recent posts from the feed upon registration (and afterwards continually).
Create a node for each item in the feed, which can be rated by other users.
Create lists from these nodes.
Okay, so Views in combination with the Feeds module can do most of this (import feeds, create nodes for each item and create lists). I've managed to allow users to import feeds 'manually' using the Feeds module.
The problems are that I can't find a way to limit the number of feeds a user can import, and I can't figure out how to make a URL from the registration form the basis of an import.
I've been trying to solve these problems using the Rules module, but with no results.
Methinks something along the lines of the Profile Blog Information module could do the trick, but it's only available for Drupal 6 and doesn't work with the Feeds module.
Any thoughts on solutions or alternatives?
I can't find a way to limit the number of feeds a user can import
If you use the default settings of the Feeds module, you should have a "Feed" content type already. So, if you want to control the number of "feeds" a user can import, http://drupal.org/project/node_limit should do the trick, I think. It'll help you set the number of nodes of the "Feed" content type that a user can create (which should be the same thing, right?)
how to make a URL from the registration form the basis of an import
Now, I'm going to suggest a custom module route here. It should do the trick but you may/may not want to add a custom module depending on the nature of your project/your level of expertise with Drupal.
Add a URL field (probably an instance of the URL field type) to the user profile. Check to allow it to be shown in the registration form. Lets say we call it feed_url.
Implement hook_user_insert() which is called when a new user is added to the site:
/**
* Implements hook_user_insert().
*/
function MY_MODULE_user_insert(&$edit, $account, $category) {
if (isset($edit['feed_url'])) {
$index = array('feed_url', LANGUAGE_NONE, 'value');
// Get the feed URL from the registration form values.
$feed_url = drupal_array_get_nested_value($edit, $index);
if (!empty($feed_url)) {
// Create a new feed on behalf of the user
_MY_MODULE_create_feed($feed_url, $account->uid);
}
}
}
/**
* Creates a new feed on behalf of a user.
*
* #param string $url
* Feed URL
* #param numeric $uid
* {users}.uid of the user for whom this feed is being created.
*/
function _MY_MODULE_create_feed($url, $uid) {
// #todo Add more validations here
$node = new stdClass();
$node->uid = $uid;
$node->type = 'feed';
$node->feeds['FeedsHTTPFetcher']['source'] = $url;
$node->language = language_default('language');
node_save($node);
}

ATK4 What is the procedure for setting up an Admin Area?

I have setup a CRUD area on my frontendAPI.php file (testing my models)... and I even managed to secure it. I would like to do this the proper way... I would like to establish a separate directory/ Page for the Admins. Please advise on this.
Still new at this but I'm trying to do the same for a news page, think i've got the login part working but having problems with the CRUD (will post a question on it shortly) - i have a table to populate with data from an rss feed (but will be manually populated with a CRUD to start with) and then have a page on the front end to pull out the details using views to format each news story.
Create a new directory called /page/Admin
Create a new file here based on the function e.g. news.php containing
class page_admin_news extends Page {
function init(){
parent::init();
$p=$this;
$crud=$p->add('CRUD');
$g=$crud->setModel('News');
if($crud->grid)
$crud->grid->addPaginator(30);
}
}
In Frontend.php, you need to enable the login - for an admin only access, the BasicAuth may be sufficient but there are also classes to use a database to obtain username and password infromation e.g. for a membership site - heres the basic one.
// If you wish to restrict access to your pages, use BasicAuth class
$auth=$this->add('BasicAuth')
->allow('demo','demo')
;
You need to modify Frontend.php to enable pages that can be viewed
without being logged in
$auth->allowPage('index');
$auth->allowPage('news');
$auth->allowPage('links');
$auth->allowPage('About');
if (!$auth->isPageAllowed($this->api->page))
{
$auth->check();
}
And also in Frontend.php, you need to create a different menu if logged in. Note the login and logout pages dont actually exist.
if ($auth->isLoggedIn())
{
$this->add('Menu',null,'Menu')
->addMenuitem('News','admin_news')
->addMenuitem('logout')
;
} else {
$this->add('Menu',null,'Menu')
->addMenuitem('News','news')
->addMenuitem('Links','links')
->addMenuItem('About')
->addMenuItem('Login')
;
}
When you login, it goes to page/index.php by default so if you want it to redirect to a particular page when you log in so you can add this to page/index.php
class page_index extends Page {
function init(){
parent::init();
$p=$this;
if($this->api->auth->isLoggedIn())
$this->api->redirect('admin_news');
Hope that helps.
Trev

Resources