The android application that I'm testing using Appium with Java has the tag/mention users feature. Now I want to test this feature. I'd like to send multiple mentions and verify that the mentions are sent or not. The application that I'm testing is similar to slack/messaging application.
Test case steps:
Open chatroom
Tap on send message field to activate the keyboard
Type # and wait for list of users to tag/mention appear
Tap user 1
Send a space after the user1 is tagged/mentioned
Type # again and wait for list of users to tag/mention appear
Tap user 2
Tap message send button
I'm using page object model. So to perform the above steps I created a method named sendMultiMention in the page class as follows:
#Override
public ChatroomPage sendMultiMention(int index0, int index1){
sendKeyToElement(SENDMESSAGEFIELD, "#");
List<MobileElement> mentionPersonNamesList =
waitAndReturnElementListIfDisplayed(MENTIONPERSONNAME);
MobileElement mentionPersonNameSelect0 = mentionPersonNamesList.get(index0);
tapOnElement(mentionPersonNameSelect0);
sendKeyToElement(SENDMESSAGEFIELD, "#");
MobileElement mentionPersonNameSelect1 = mentionPersonNamesList.get(index1);
tapOnElement(mentionPersonNameSelect1);
tapOnElement(SENDMESSAGEBUTTON);
return this;
}
So the problem with the above code is the 2nd sendKeytoElement overwrites (i.e. clears) the previously filled text in the send message text field.
So what it does is the following:
types # -> selects user1 -> clears #user1 ->types # again -> selects #user2.
But what I want is to do the following:
types # -> selects user1 -> give a space ->types # again -> selects #user2
(i.e. DO NOT CLEAR #user1 FROM THE SEND MESSAGE TEXT FIELD)
Any help will be highly appreciated!
Related
Background:
There are more than 500 users. Their user name and password are stored in a CSV file.
Each user must pass this .feature file which consists of 18 scenarios.
Problem:
I know we can use data tables, scenario outline, but data mentioned here will be limited to associated scenarios only not for entire feature file. I want once .feature done executing first row of data it should go to next row from CSV file, and continue doing it until the end of CSV file.
I tried replacing Data table with MS Excel sheet, used (POI apache files to read spreadsheet), but again same thing happened it ran for that particular scenario only.
E.g. This a .feature file
#regression #userValidation
Feature: User permission validation
Scenario Outline: Verify that user is able to login
Given I am on login page
When I enter "username" and "password"
Then I see new user successfully loggedin
Examples:
| username |password| // picked from excel sheet
| uname |pwd | // picked from excel sheet
Scenario: Verify that user can change the password
Given I am on user profile page
When I enter change password twice
Then I get password successfully changed pop-up
Now, scenario one keep on running 500 times (number of rows in csv file) once all data is finished, it starts second scenario. What I want is it both scenario
should run for row 1, then both scenario should for row 2 and so on for 500 times.
How can I do it? Is there a Java or Junit way to do it, if not possible in Cucumber?
I am using Java, Selenium WebDriver, JUnit, Cucumber, Maven on Windows
One of the way is adding examples in each scenario in the feature file, you are already reading data from external source so it will not duplicate data at scenario level. Still you need to add examples to each scenario. For example:
#regression #userValidation
Feature: User permission validation
Scenario Outline: Verify that user is able to login
.....
Examples:
| username |password| // picked from excel sheet
| uname |pwd | // picked from excel sheet
Scenario Outline: Verify that user can change the password
...
Examples:
| username |password| // picked from excel sheet
| uname |pwd | // picked from excel sheet
In this case you need to be cautious on execution order of each scenario. If you use gherkin with qaf, it may look like below:
#regression #userValidation
Feature: User permission validation
Scenario: Verify that user is able to login
.....
Examples: {'datafile':'resources/usersdata.csv'}
Scenario: Verify that user can change the password
...
Examples: {'datafile':'resources/usersdata.csv'}
More over, with latest BDD2 syntax, you can have your feature file as below:
#regression #userValidation
#datafile:resources/usersdata.csv
Feature: User permission validation
Scenario: Verify that user is able to login
.....
Scenario: Verify that user can change the password
...
Regarding execution order, qaf makes sure to run scenario in order they defined in feature file. Still you can specify priority in meta-data when using BDD2 syntax, for instance, #priority:1 on first scenario, #priority:2 on second and so forth.
Other alternate for above case is change first scenario as per-condition and consider it as background, for that refer how to use background with examples.
I am building a reply keyboard oriented bot using java and I need it to treat differently two scenarios in which the latest message's text is the same based on the text of the previous message. How can I get or store the text of the previous message as a public variable?
My conceptual modelling is as follows:
I have a large If-Else-If statement where the condition for each If block goes along the lines of if(update.hasMessage() && messageText.equals("aaa")) where "aaa" is some text that appears on a reply keyboard that popped up for the user earlier (since the keyboard buttons send the string on them as text and there is no option for a button press event in Telegram bot's api). messageText is defined as update.getMessage().getText().
I want the code to treat differently two scenarios in which messageText is the same based on the message that came before it. if(update.hasMessage() && messageText.equals("aaa") && previousMessage.equals("bbb")) { } else if(update.hasMessage() && messageText.equals("aaa") && previousMessage.equals("ccc")){}. How can I store the previous message without it getting updated upon a new message recieved?
There are lots of patterns that you can use for controlling the state of users, But as a simple trick what I did in my telegram bot, you can generate next message data based on current message response. For example when user send "aaa" as the first message response, and you want to generate the next message you can add first message data to it's callback like this: "aaa,bbb" and when calls the api you notice that previous message was "aaa" by splitting the callback data with ','.
I have java code for one of my automation website and I copy that code to other PC to run other Website however the first step is running ok which is open the URL but the rest can not be run , unable to locate the element id , here is the code in Java:
#When("^I enter (.*) in the (.*)$")
public void i_enter_in_the_Username_txt_box(String emailaddress,String boxname) throws Throwable {
WebDriverWait wait = new WebDriverWait(driver,LOAD);
By id = By.id(boxname);
wait.until(ExpectedConditions.elementToBeClickable(id));
driver.findElement(By.id(boxname)).sendKeys(emailaddress);
}
BDD for this code is :
Feature: XYZ
Scenario: Add valid username and password then click on login button
Given User at login page // this one is working fine
When I enter Admin in the username // this one is not working , error saying that the Id for the username field can not find
And I enter Admin in the password
Then Home page will display
Would you please let me now if you know where is the issue ?
I tried the following but still i got the error :
Add Thread.sleep(1000); to wait but still i got the error
I added "" for the Admin and the Id for the field in the BDD file but still it did not work
I am using cucumber , Firefox , selenium , Eclipse , BDD, Maven and Java
Thanks a lot
Try change this driver.findElement(By.id(boxname)).sendKeys(emailaddress); to driver.findElement(id).sendKeys(emailaddress);
I found couple of issue. I am not clear what error you are getting that's reason I am trying to debug multiple way.
Feature: XYZ
Scenario: Add valid username and password then click on login button
Given User at login page // this one is working fine
When I enter Admin in the username // this one is not working , error saying that the Id for the username field can not find
And I enter Admin in the password
Then Home page will display
This is not correct. Given statement will work because you are not passing any value as parameters from statement to step definition.
It is failing here When I enter Admin in the username
because you didn't add parameter well.
I think you can do this way
When I enter "stack#stack.com" in the "username"
Currently It will take two user parameters as per your step definition requirement.
I am expecting "username" is your box name.
other reason could :
WebDriverWait wait = new WebDriverWait(driver,LOAD);
Are you sure you are getting driver and LOAD in step definition ?
I found online google drive script that sends an email with the changes on the prices of Amazon products that I insert.
This is the file
I couldn't make it work for 100%.. It work sometimes only for some of the products, and I cant find the reason.
Please help me to understand what is wrong.
Also, I wanted to know if I could modify the script so it will send me an alert twice a day and not only once, as it is now.
Configuring Email Notification Intervals
The email notifications are configured as Google Apps Scripts triggers invoking the priceEmail function. They're randomly assigned when you initialize the spreadsheet (refer to the Start_Tracking implementation).
To configure email notifications manually – e.g. adding a second daily email – open the Copy of Amazon Price Tracker by ctrlq.org script associated with the spreadsheet (via the spreadsheet Tools > Script editor... menu command). Then proceed to opening the triggers dialog (Resources > Current project's triggers menu command) and add a new time-driven trigger for the priceEmail hook.
Script Errors
By default, the priceEmail function handles all errors silently. There's not much clue to what would cause the script to not work 100% of the time. If you'd like to be notified of the errors, either remove the exception handling in the current implementation or update the priceEmail body.
I'd advice making the following modifications (again via the spreadsheet Tools > Script editor... menu command):
function priceEmail() {
var sheet, data, page, table="";
sheet = SpreadsheetApp.getActiveSheet();
data = sheet.getRange(2, 2, 21, 2).getValues(); // Note that the script will only look at the first 20 rows.
try {
for (i in data) {
if (data[i][0] !== "") {
page = UrlFetchApp.fetch(
"http://ctrlq.org/aws/lookup/", {
"method": "post", "payload": {"url":data[i][0]}
}).getContentText();
table = table + tableRow(page);
}
}
} catch (e) {
Logger.log(e.toString());
// Following line inserted to include any error messages in your daily email(s).
table += "<tr><td><strong>Error:</strong></td><td>" + e + " (url: \"" + data[i][0] + "\")</td></tr>";
}
// ...
I am using Webdriver with java. I want to input some numeric value in a text field by using Java. I am using the following code:
driver.findElement(By.id("igtxtctl00_MasterPlaceHolder_WTxtZip")).sendKeys("25025");
But after entering the value completely, the entered value is erased automatically.
After the value is stored, I have to click on tab (using script), so that the City field is populated automatically after running the back end process.
I have achieved the same thing using Selenium RC by using below code:
selenium.typeKeys("igtxtctl00_MasterPlaceHolder_WTxtZip", "25025");
Thread.sleep(x);
selenium.keyPress("igtxtctl00_MasterPlaceHolder_WTxtZip", "9");
try some thing like this
driver.findElement(By.id("igtxtctl00_MasterPlaceHolder_WTxtZip")).sendKeys("25025");
after typing zip code just try to click some where else in the page
driver.findElement(By.id("igtxtctl00_MasterPlaceHolder_WTxtZip")).sendKeys(Keys.TAB);
OR
Try with Actions class.
new Actions(driver).sendKeys(driver.findElement(By.id("igtxtctl00_MasterPlaceHolder_WTxtZip")), "").perform();
From inspecting your code, I see that there is client-side logic based on that zip element. There is a post-back to the server to determine the city. The trigger to the post-back is the tab key.
This means that if you want to effectively test your page, you must send the tab key.