I want to use some construction like this in Appium in my Tests:
if (element.exists()) {
System.out.println("OK");
}
But Test failed with NoSuchElementException. Thy/catch constructiont doesnt work too.
How can I use if/else statements in Appium?
You can check if the element exists or not by first fetching the list of that element and then checking its size. If the size is greater than 0 it means it is present on the page else it is not present.
You can do it like:
List<WebElement> elementList = driver.findElements(By.xpath("Enter your xpath here"));
if(elementList.size()>0){
//Element is present
}
else{
//Element is not present
}
Try this.
public boolean verifyElementIsVisible(){
MobileElement element=driver.findElement(By.id("#enter your id here");
if(element.isVisible())
{
return true;
}
else
{
return false;
}
}
Related
I am playing around with Dart and came up with the following code
List<String> lst = new List<String>();
main()
{
lst.add("hello");
lst.where((String str) {
if(str=="hello"){
print("Found");
}
});
}
While debugging I noticed its not going into the where statement and printing "Found" . Am I doing something wrong ?
var filteredList = lst.where((String str) {
if(str=="hello"){
print("Found");
return true;
}
return false;
});
print(filteredList);
where()
should return true or false to indicate whether the item fulfills the condition
creates and returns a new iterable, it does not modify the original collection
is lazy, which means it is not executed before the result is used. toList() is one of the operations that require the result to materialize and to execute the where condition on every item (many collection methods are lazy).
Hi i am using Ranorex for my wpf app
In Ranorex recording we are having validation part
but in my testcase,i not added recording file,i am just test case and code module to test an application
please help me how to add validation function in code module as we do in recording or let me know about any alternative
Thanks
i got the solution
using validate.Attribute we can validate actual and expected data
you can make your own validation function pass the parameters to it and verify for example:
public Boolean verifyErrorMessage(string errorMessage)
{
Boolean result= false;
try
{
repo.Gmail.ErrorMessage.InnerText.ToString();
if(errorMessage.Trim().Equals(errorMessageReceived.Trim()))
{
result=true;
}
}
catch(Exception e)
{
Report.Error(e.Message);
}
return result;
}
I need to remove a node from a linked list using recursion. this is the code that I have so far...
public class SortedSetNode implements Set {
protected String value;
protected SortedSetNode next;
public boolean remove(String element) {
if (value.equals(element))
{
next = next.getNext();
return true;
}
else
{
return next.remove(element);
}
}
Well, without knowing what the problem is that you are facing, you would need a clause in there to check whether the item you are removing is actually in the linked list, i.e.
if(next == null){
return false;
}
Other than that your code looks fine. What is the issue you are encountering?
If the value attribute is the value of the current node, then you'll need to delete itself when value equals element, rather than delete the next. Unless it's the value of next node.
You might need a start point, so when you compare value, you compare the next node's value with the string, and if found, do your next = next.getNext();. Of course a check of null is needed.
Presently i use a method which returns me the ICommand object based on the string comparisons got from the supplied key.
public ICommand getCommand(string mCommand)
{
foreach (object obj in objCommandList)
{
ICommand command = (ICommand)obj;
if (command.m_strCommandName == mCommand)
{
return command;
}
}
return null;
}
where objCommandList contains ICommand objects.
Now I want to improve my code or rather try an alternative to search amongst the collection i.e using an option such as Predicate delegate in retrieving the filtered object amongst the collection.
ie.
objCommandList.Find(Predicate syntax which is needed here...)
Can anyone help me with this.
You might try something like this:
objCommandList.Find(delegate(Icommand command) { return command.m_strCommandName == mCommand; });
or
objCommandList.Find(c => c.m_strCommandName == mCommand);
I have a custom validator like -
validator: { userEmail, userAccount ->
if (userAccount.authenticationChannel == "ABC") {
boolean valid = true;
UserAccount.withNewSession {
if (UserAccount.findByEmail(userEmail)){
valid = false;
}
else if (UserAccount.findByName(userEmail)) {
valid = false;
}
...
So basically, I need some validation based on some condition and in my validation I need to execute a query.
But, now if I do -
def admin = new UserAccount(firstname:'Admin',email:'admin#example.com')
admin.save(flush:true)
admin.addToAuthorities("ADMIN").save(flush:true)
It fails.
Grails is running the validation, even on update and since email exists validation fails. How is this different if I do
email {unique:true}
Is Grails saying that I cannot write a custom validator which checks uniqueness.
Not sure if this is your issue or not, but when I tried to create a validation like this (ie. one that does queries against the database), I would get a StackOverflowError. The reason is that, when you run a query (like findByEmail), Hibernate will try to flush the session, which will cause it to validate all transient objects, which in turn calls your custom validator again, resulting in infinite recursion.
The trick to prevent this is to set the flush mode of the session to "manual" for a short time while running the queries. This prevents Hibernate from trying to flush the session before running the queries. The side-effect is that your query won't return entities you created in the current session but haven't been persisted (flushed) back to the database yet.
UserAccount.withNewSession { session ->
session.flushMode = FlushMode.MANUAL
try {
if (UserAccount.findByEmail(userEmail)){
valid = false;
}
else if (UserAccount.findByName(userEmail)) {
valid = false;
}
}
finally {
session.setFlushMode(FlushMode.AUTO);
}
}
See UniqueConstraint for an example of how this is done.
An alternative might be to do the checks in the save method.
def save = {
..
if (some_checks_succeed(userEmail, userAccount)) {
admin.save(flush: true)
}
..
}
def some_checks_succeed = { String userEmail, String userAccount ->
boolean valid = true;
if (userAccount.authenticationChannel == "ABC") {
UserAccount.withNewSession {
if (UserAccount.findByEmail(userEmail)) {
valid = false;
} else if (UserAccount.findByName(userEmail)) {
valid = false;
}
..
}
return valid
}
Some modifications might be necessary, but the above code gives you an example
Thanks. I could get this to work.The admin.save() calls validation both on insert and update. I handled both the cases (insert and update) and was able to get this working.
Thanks