I have started writting test cases for a project, The first page is login page.
i have started to write test case for valid email adress validation.
public void LoginValidEmailProvided(string baseUrl)
{
_driver.Navigate().GoToUrl(baseUrl);
UserIdField.Clear();
UserIdField.SendKeys("abc.xyz.com");
PasswordField.Clear();
PasswordField.SendKeys("");
LoginButton.Click();
}
Now my question is do we need to write different function for each variation for valid emaiil address checking.
Like on manual testing test usually do
some.com
#some.com
#some
some#
some###.com
and many more.
so do we have to write test cases for above varaitions in automate testing. or just one variation is suffucient. as I am checking the return message and comparing with expected and what I get. In each case it returns Invalid credentials. So I have just checked is page contains the message Invalid credentials then the Invalid Emaild address test case passed.
Please advise
Thanks
The better approach would be have two methods one to check valid email address and other to check invalid email address
Advantages of having two methods
You can have valid credentials seperately in a file or a data provider(incase of frameworks) and pass valid credentials only to the check valid_email method and invalid credentials to invalid_email method so that if there is any error you can locate it easily(ex : valid credentials is throwing an error saying that the credentials in invalid) if you combine both the credentials then it will be difficult for you to find which is valid and which is invalid
pseudecode :
public void correct_email(){
enter username and other details
click submit
Get the success page or page title of homepage to check email validation passed
}
public void wrong_email(){
enter username and other details
click submit
Get the error page and compare it with the actual error message
}
EDIT :
1.If you're keeping your valid and invalid credentials together and having one method to validate it how do you know if a valid login credentials failed to login it will also throw an error invalid credentials and you're test will pass and you will not notice this error
2.Moreover if you're using frameworks like ex: testng you will get these data in reports if ur parameterizing your tests so in reports also it gives you a clear view of data passed and failed ie)Parameters run using valid credentials and parameters run using invalid credentials .if you use one method to validate vaiid and invalid credentials all will be listed as one.
Hope this helps you.Kindly get back if you have any queries
Do not create a different method you can use data provider for each test !!!
(you can write a rapper that the data provider will look nicer )
http://testng.org/doc/documentation-main.html
//This method will provide data to any test method that declares that its Data Provider
//is named "test1"
#DataProvider(name = "test1")
public Object[][] createData1() {
return new Object[][] {
{ "Cedric", new Integer(36) },
{ "Anne", new Integer(37)},
};
}
//This test method declares that its data should be supplied by the Data Provider
//named "test1"
#Test(dataProvider = "test1")
public void verifyData1(String n1, Integer n2) {
System.out.println(n1 + " " + n2);
}
will print
Cedric 36
Anne 37
Related
i create a function test false login test but i want to assert with those loop test
here is my sample data
#DataProvider(name = "Lgindataprovides")
public Object[][] getData(){
Object[][] data= {
{"abcd#mail.com","12345666"}#email and password wrong (asset text = enter email is not available please register)
{"xyz#mail.com","12345666"},#email correct password wrong (assert text = password is wrong)
return data;
}
here is my test
#Test(dataProvider = "Lgindataprovides", dependsOnMethods = "boofoo")
public void logintest(String email, String passowrd) {
driver.get("https://dummyurl/login");
driver.findElement(By.id("email")).sendKeys(email);
driver.findElement(By.id("password")).sendKeys(passowrd);
driver.findElement(By.cssSelector("button[type='submit']"));
Assert.assertEquals(get1stdatatest, "enter email is not available please register")
Assert.assertEquals(get2nderrordatatest, "password is wrong")
}
buts it fails this test case how can I handle this?
what I want is
when this data"abcd#mail.com","12345666" is passed to the login test its should assert with this "enter email is not available please register"
when this dataxyz#mail.com","12345666 is passed to the login test its should assert with this "enter email is not available please register"
I see, you wand to check a unique error message per test data pair.
Add the 3rd item to data-provider with the error message text you expecting. So, each email/password will be linked with the error message.
#DataProvider(name = "Lgindataprovides")
public Object[][] getData(){
Object[][] data= {
{"abcd#mail.com","12345666", "error-message-1"},
{"xyz#mail.com","12345666", "error-message-2"}
}
return data;
}
Add 3rd arg to your test and assert that actual error matches the expected.
#Test(dataProvider = "Lgindataprovides", dependsOnMethods = "boofoo")
public void logintest(String email, String passowrd, String expectedError) {
driver.get("https://dummyurl/login");
driver.findElement(By.id("email")).sendKeys(email);
driver.findElement(By.id("password")).sendKeys(passowrd);
driver.findElement(By.cssSelector("button[type='submit']"));
Assert.assertEquals(getActualErrorMessage(driver), expectedError)
}
Adjust the method which getting the actual error message text. Your locator for driver.findElement sould find both password or email error messages. You might try to use xpath and search by some class //*[contains(#class, 'some-error-class']. So, you'll get any error message text on the form and it should work.
private String getActualErrorMessage(WebDriver driver) {
driver.findElement(By.xpath("...")).getText();
}
You might also do it inline without creating a new method. Also add some waits/timeouts if you need.
I've web application, I want recorded test cases and play back that cases.
1st release of the application, I've login module which has user name and password and recorded 500 test cases for entire application. Among 500 test cases 200 test cases are using logging by username and password.
2nd release of the application, I've login module which has only username, so I want use previous recorded test cases by modifications not like go to all the test cases change the password field. Here I'm having some requirements for the testing framework
Can I get what are test cases will effect by changing field like in above example?
Is there any way to update in simple, not going like in all the files and changing
I've used different UI Automation testing tools and record & Play back options are very nice, but I could not find the way I want in the UI Automation test framework.
Is there any Framework available which does the job for me?
Thanks in advance.
This is a prime example of why you never should record a selenium test case. Whenever you want to update something like login you have to change them all.
What you should do is create a test harness/framework for your application.
1.Start with creating a class for each webpage with 1 function for each element you want to be able to reach.
public By username(){
return By.cssSelector("input[id$='username']"); }
2.Create helper classes where you create sequences which you use often.
public void login(String username, String password){
items.username().sendkeys(username);
items.password().sendkeys(password);
}
3.In your common test setup add your login function
#BeforeMethod(alwaysRun = true)
public void setUp() {
helper.login("user","password");
}
This give you the opportunity to programmaticly create your test cases. So for example if you want to use the same test cases for a different login module where password element is not present it could be changed like this.
items.username().sendkeys(username);
if(isElementPresent(items.password())
items.password().sendkeys(password);
The function "isElementPresent" could look like this
public boolean isElementPresent(By locator){
try {
driver.findElement(locator);
logger.trace( "Element " + stripBy(locator) + " found");
} catch (NoSuchElementException e) {
logger.trace( "Element " + stripBy(locator) + " not found");
return false;
}
return true;
}
Any ideas on how can I list all the activities in my domain by using the new google+ domain's API in java?
The Developers' Live video shows at 4:00 minute mark that you can do something like this:
Plus.Activities.List listActivities = plus.activities().list("me", "domain");
The Link for this code is here.
But when I actually run the same line of code it shows me the following error.
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"location" : "collection",
"locationType" : "parameter",
"message" : "Invalid string value: 'domain'. Allowed values: [user]",
"reason" : "invalidParameter"
} ],
"message" : "Invalid string value: 'domain'. Allowed values: [user]"
}
The error makes sense as in the activities.list documentation it says that "user" is the only acceptable value for collection and not "domain."
So what should I do about this issue?
As you say, the only available way is to list posts by the currently logged user. You have to use user delegation (with service accounts) and loop over all users in the domain in order to get all published activities.
You can use the updated field on the response to check if there is anything new in a user's list of activities.
This line of thought applies to the whole Domains API: every operation is done on behalf of a user, there is no "admin" account with superpowers. This can be a limitation when acting on a big number of users, as you are forced to authenticate for each one in turn (if someone has an idea on how to achieve this in a more efficient way, please share!)
As the documentation sais, only "public" is allowed:
https://developers.google.com/+/api/latest/activities/list
However even using the code provided in the example in the API doc, after going through successful authentication I get 0 activities.
/** List the public activities for the authenticated user. */
private static void listActivities() throws IOException {
System.out.println("Listing My Activities");
// Fetch the first page of activities
Plus.Activities.List listActivities = plus.activities().list("me", "public");
listActivities.setMaxResults(100L);
// Pro tip: Use partial responses to improve response time considerably
listActivities.setFields("nextPageToken,items(id,url,object/content)");
ActivityFeed activityFeed = listActivities.execute();
// Unwrap the request and extract the pieces we want
List<Activity> activities = activityFeed.getItems();
System.out.println("Number of activities: " + activities.size());
// Loop through until we arrive at an empty page
while (activities != null) {
for (Activity activity : activities) {
System.out.println("ID " + activity.getId() + " Content: " +
activity.getObject().getContent());
}
// We will know we are on the last page when the next page token is null.
// If this is the case, break.
if (activityFeed.getNextPageToken() == null) {
break;
}
// Prepare to request the next page of activities
listActivities.setPageToken(activityFeed.getNextPageToken());
// Execute and process the next page request
activityFeed = listActivities.execute();
activities = activityFeed.getItems();
}
}
Anybody know how to get this to work?
when you use Google+ API you must use "public" but when you use Google+ Domains API you must use "user" parameter value.
I am trying implement custom client side validation.It is a cross coupled validation. I have followed all steps and its working fine. But my requirement requires me to modify the ErrorMessage which is will be part of metadata(HTML 5 Data Attribute). The example is as follows
IClientValidatable implementation:
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
ModelClientValidationRule rule = new ModelClientValidationRule();
rule.ValidationType = "salaryandloanconstraint";
rule.ValidationParameters.Add("loanconstraintvalue", _loanEligibleMultiplicity);
rule.ErrorMessage = "Salary Insufficient to sanction a loan amount of";
return new ModelClientValidationRule[] { rule };
}
The message which i have initilized to rule.ErrorMessage is incomplete. I want to append text which is taken from input field for LoanAmount property to the error message when the user enters.
In Summary is there any way which i can manipulate the error message(HTML5 DATA ATTRIBUTES) at the client side using JQuery?
check this url, may be this solve your issue:
$(".field-validation-error span", $("#form"))
.clone()
.appendTo("#error-summary")
.wrap("<li>");
I want to display an asterisk (*) next to a text box in my form when initially displayed (GET)
Also I want to use the same view for GET/POST when errors are present) so For the GET request
I pass in an empty model such as
return View(new Person());
Later, when the form is submitted (POST), I use the data annotations, check the model state and
display the errors if any
Html.ValidationMessageFor(v => v.FirstName)
For GET request, the model state is valid and no messages, so no asterisk gets displayed.
I am trying to workaround this by checking the request type and just print asterisk.
#(HttpContext.Current.Request.HttpMethod == "GET"? "*" : Html.ValidationMessageFor(v=> v.FirstName).ToString())
The problem is that Html.ValidationMessageFor(v=> v.FirstName).ToString() is already encoded
and I want to get the raw html from Html.ValidationMessageFor(v=> v.FirstName)
Or may be there is a better way here.
1. How do you display default helpful messages (next to form fields) - such as "Please enter IP address in the nnn.nnn.nnn.nnn format) for GET requests and then display the errors if any for the post?
2. What is the best way from a razor perspective to check an if condition and write a string or the MvcHtmlString
Further to my last comment, here is how I would create that helper to be used:
public static class HtmlValidationExtensions
{
public static MvcHtmlString ValidationMessageForCustom<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression, string customString)
{
var returnedString = HttpContext.Current.Request.HttpMethod == "GET" ? customString : helper.ValidationMessageFor(expression).ToString();
return MvcHtmlString.Create(returnedString);
}
}
And it would be used like this #Html.ValidationMessageForCustom(v=> v.FirstName, "Please enter IP address in the nnn.nnn.nnn.nnn format")