'When I try to assert some web elements,if assertion fails cucumber stops execution with error
AssertionError:'567'='abc'
Feature file:
Scenario: Validation of button
Given I hit login page
When login page gets loaded
Then validate text on button
Scenario:Login to the page
Given user provide login details
When clicks on login button
Then sign in the user
Cucumber stops abruptly and result of passed steps is not shown.
If assertion fails,I want to go cucumber to execute next steps .please help and thanks.'
Update with step example:
this.Then(/^Validate text on button$/, function() {
var textonbutton = browser.driver.findElement(by.xpath("it's xpath"));
textonbutton.getText('innerText').then(function(innerText) {
return assert.equal(innerText, "567");
});
});
Related
I want to make a section of my meteor error string as a link.
if (customer.password) {
throw new Meteor.Error('server-error_email-in-use', 'Email already in use with a non-guest account, please log in to complete your order');
}
how can i make "log in" a hyperlink to login page?
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"})
(Sign In) this is the html tag of yahoo sign in. I want to click on the sign in using selenium web driver, and also get the value which is in the title="sign in"? can anyone solve my problem please.
WebElement el = driver.findElement(By.cssSelector(".social-enabled-txt"));
String elementValue = el.getText(); //This one gets the value
el.click(); // This one clicks on the signin button on yahoo.com homepage.
If you want to click on the yahoo sign-in link using the selenium web driver and want to get the value in the title = "sign", the Below code has been given.
driver.get("https://in.search.yahoo.com/?fr2=inr");
//get the text of title in sign in
String text = driver.findElement(By.className("text")).getText();
// Print the title of value
System.out.println("Title of sign in button is : "+text);
//click on sign in link using xpath
driver.findElement(By.xpath("//*[#id=\"ysignin\"]/div")).click();
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!
I'm writing a Silverlight 4 application using "Silverlight 4 Unleashed" as a foundation.
I have a ChildWindow for loggin in with Username, Password, and Remember Me. The OK button is tied to my AuthUserViewModel SignIn using RelayCommand.
Since I'm just starting, I don't have any data validation yet and noticed something weird.
If I click "OK" on my Login child window, my Action callback tells me I have invalid credentials in a MessageBox...which is perfect. I'm using my own Authentication service for various reasons.
However, if I click "OK" again, my service gets called once, but the Action callback is fired twice, telling me I have invalid credentials. If I press "OK" again, the service is called once, but the Action callback is fired three times, and so on and so on.
Why would it be doing that?
Here is the offending code:
public void SignIn(AuthUserDataModel authUser, Action<ErrorContainer> callback)
{
EnsureClient();
client.SignInCompleted += (sender, result) =>
callback(new ErrorContainer
{
AsyncException = result.Error,
CustomError = result.Result.CustomMessage //holds "Invalid credentials"
});
client.SignInAsync(authUser);
}
Like I said, the button event is fired once, the web service is called once, but the callback is fired an amount equaling the number of times I press OK.
Thank you.
Ah! your client object is a field, and you ensured that it is shared across calls. It prevent it from being initialized on each SignIn call, but each time you add an handler to the SignInCompleted vent before executing the SignInAsyncFunction.
Therefore it's normal that the handler gets executed one time by subsequent SignIn.
To prevent this, you have 2 approaches:
1) create a new client in each SignIn call (it will be garbage collected later)
2) attach your handler when you initialize the client.
ie in your EnsureClient, you should have something like:
if(client == null)
{
client = new MyClient();
client.SignInCompleted +=(sender,result) =>{...};
}
and in the SignIn function:
EnsureClient();
client.SignInAsync(authUser);