Explicit wait is not accepting webelement - automated-tests

Iam using Page object model ...if i declare element like this
#FindBy(xpath=" ")
Public WebElement element;
Then I am unable to use explicit wait
Wait.until(ExpectedConditions.visibilityOfElementLocated(element):
explicit wait is not accepting webelement. Can anyone help me on how to pass webelement .

There will be two methods for each condition, one visibilityOfElementLocated and other visibilityOfElement. The first one accepts By object and later one accept element.
For your case you pass, you have to use method name which doesn't end with word Located.
wait.until(ExpectedConditions.visibilityOf(element))

Related

Clicking a Webbutton which is the Child of a Webelement using Microsotf UFT

I'm currently working on developing a testautomatisation strategy for a web-client. On this web-client all web-elements have a data-testid which is used to identify the object.
Unfortunately in some cases the data-testid is not unique, so clear identification of the object is not possible, I cannot change those data-testids.
So I try to write a component which identifies a webelement based on a data-testid and then presses the button which is a child of that element.
Unfortunately my code doesn't work, becausse UFT cannot identify my object, I'm unfortunately not able to find the solution by myself.
This is how the HTML of the element looks like:
I want to find the Webelement with the data-testid "Orderbeleg_Segmentumbuchung" and then click its child withe the data-testid "add:b".
This is the code I wrote:
Option Explicit
Dim bcName
bcName = "Webbuttonclick_add"
'---------------------------------------------------------------------------------------------
Dim pDoit, pParent, var, debug1
pParent = Parameter("parent")
pDoit = CBool(evalVarAndOffset(Parameter("doit")))
var = "data-testid:= .*" & pParent &".*"
If pDoit = True Then
Browser("index:=0").Page("index:=0").WebElement(var).Click
If Browser("index:=0").Page("index:=0").WebElement(var).exist(1) Then
Browser("index:=0").Page("index:=0").WebElement(var).ChildItem("data-testid:=
add:b").Click
wait 1
End If
End If
SQS_ActionFinish
var is the data-testid of the parent-element.
There are a couple of things I see from reading the question (I didn't actually try to run the code so check to see if I'm right).
You're using data-testid as a test object property. I don't think this should work since UFT doesn't define this property. Try attribute/data-testid (further reading).
You don't need to use ChildItem you can nest the WebElement directly under the var element. You can use a WebElement as a container even though UFT doesn't do it by default. In fact ChildItem is a Table specific method and not applicable here, if you mean ChildObjects then the parameter should be a Description object and not a string with the description inline.
In var there's a space before the first .*, is that intentional?
To summarise my comments, try this:
Browser("index:=0").Page("index:=0").WebElement("attribute/data-testid:=.*"&pParent&".*").WebElement("attribute/data-testid:=add:b").Click

Kotlin Bundle.putString not explicitly adding "String" but instead is "String?"

val args = Bundle()
args.putString("type", details.type)
navigator.navigate(context!!, findNavController(), Destination.TYPE, args)
I am quite confused as to why in the receiving fragment when I go to access the arguments I have passed through it is responding with...
val type: String = arguments.getString("type")
The arguments.getString is all underlined red and says "Required String Found String?" But how when I called method "putString"?!?
It is resulting in text not being rendered in the new fragment and I assume this is a nullability issue.
It's a matter of knowledge that is available in the receiving Fragment.
The Fragment is not aware of how its arguments were created (or modified) so it has to assume the "type" key you're looking for might not be in the arguments Bundle. That's why it returns a nullable (String?) result (the null value would mean absent in arguments).
Your fragment might be created in many places in your app and its arguments might have been modified in many places. We have no way of tracking that.
There are different solutions for this problem, depending on your approach in other parts of the code and how "confident" you are in creating of your Fragment.
I would usually choose a solution in which I assume setting the type is mandatory. Therefore if the type is absent - I fail fast. That would mean the Fragment was misused.
val type: String = arguments!!.getString("type")!!
The code above will crash if either:
a) arguments weren't set, or
b) String with type wasn't put in the arguments Bundle.
You are right, that is a : null ability issue.
First you should be sure if you are expecting a value, so try adding "?" or "!!", i would recommend "?", or go with the block of if {} else
To read the string safely you can use:
val type: String = arguments?.getString("type").orEmpty()
The orEmpty call at the end ensures that a valid String is returned even if either arguments or getString() returns null.
The method signature for getString() returns a nullable String. This is because at compile time, the compiler can't know if the value exists in the bundle or not. You will have the same issue when retrieving anything from any Map.
If you know for certain that the value in the bundle or map should exist at the time you call getString(), you can use the !! operator. That's what it's there for. When you know something should always be there, it is appropriate to want an exception to be thrown (in this case KNPE) if it's not there so you can easily find any programming error during testing.
isEmpty() or ?.let aren't helpful in this particular case because they would just be masking a programming error and making it harder to discover or debug.

Can I pass an argument to the slot function when using QObject::connect?

Qt4.8.5
QObject::connect(button,SIGNAL(clicked()),label,SLOT(setText("dd"));
The Qt Creator tell me It's wrong . What's the problem ?
That you can't pass arguments in a connect() statement. You need a "trampoline" slot that sets the text of your label (or, in Qt 5, you might choose to use a lambda).
For instance, by using a subclass:
class MyLabel : public QLabel {
Q_OBJECT
public slots:
void setTextToFoo() { setText("foo"); }
};
// ...
connect(button,SIGNAL(clicked()),label,SLOT(setTextToFoo());
It depends what exactly you are trying to achieve, to be honest, the example code you provided is not very functional, is "dd" a particular static value you are using, or potentially some other string? Where does it come from, is it in the scope of the called, or is it sent by the caller, which is the usual practice when sending arguments to slots.
Either way, in order to make a connect statement the first requirement is for the arguments to match, clicked() has no arguments while setText() has one, so there is a mismatch. As of how to resolve that mismatch, the easiest way is to use simple wrappers, although you can use a QSignalMapper and as of Qt5, lambdas and std::bind.
For starters, you cannot specify the actual argument instance in the connect statement, even with arguments on both sides you only need to specify the types to help resolve overloads (it is terrible with the new connection syntax in Qt5), and not any actual identifiers or literals.
In case of the more usual scenario, where the data is send to the slot by the caller, the identifier or literal is specified in the emit signal(value) statement. Since you don't have clicked(const QString &) you need a wrapper slot that you connect to clicked() and emit with the value in that wrapper slot, or subclass the button and add your own overload of clicked(QString).
In case the value is in the scope of the called, then subclassing doesn't make much sense, all you need is the wrapper slot in the scope of the called object.
If you want more, you will have to use Qt 5, whose syntax is significantly more powerful.
If the question is whats wrong, just remember the parameter number must be the same for the Signal and the Slot. Asking a collegue and according the Peppe, setText(QString) wait for One parameter and the Clicked() is empty...A custom slot is to call the setText() method indirectly.
You can look that : http://qt-project.org/doc/qt-4.8/widgets-calculator.html
It uses the QWidget, an important part of Qt interfaces beside QML.

Simple application of delegates in c# to get started

I am trying to learn delegates in C# from this article
http://msdn.microsoft.com/en-us/library/aa288459(v=vs.71).aspx
I am able to understand the code a bit but i am not able to understand where and why would a developer want to use delegates. Can somebody give an easy scenario which can help me start with delegates?
Update
I read this statement everywhere, "The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked."
But why would i want compiler shouldn't know about function i pass? I can smell abstraction here but what's the use? Any real time scenario is required.
A good example of using delegates would be callbacks. Imagine you have a class DbSearcher. That class has the method Search(string q) and when you call this method it takes it 1 minute to return. You want to eventually display results of the search but you don't want to keep the user waiting for them to appear while being unable to do anything more. What you do is you change your method to, for example, Search(string q, Action displayResults) and fire it in a separate thread. displayResults here is a delegate which you will call inside the Search method once the search results are retrieved from the db.
Look, in windows forms there are classes like button, image, textbox etc... All of them have event handlers like button.click, textbox.texchange, ... which are delegates themselves.
and when you want to do something on button click you write function which is void and has two aguments: of object type and EventArgs. The one who wrote that button class didnot know what to do on button click but gave you delegate:
public delegate EventHandler Click;
where will be your defined methods like:
public void mymethod(object s, EventArgs e)
or every method tha is void and has that parameters
You can find so many example and code snippets over the web . Here is my example, think that your user is going to decide which operation he/she is going to do in the following,
Add two numbers
Subtract two numbers
Multiple two numbers
Divide two numbers.
But you have one common method to perform all this
Operation(some delgate method)
{
// do some operation
}
u you can pass the delegate at run time based on user selection.
This is just an example.
A delegate is basically a reference to a method.
You can for example have to different methods for changing a string:
public static string ChangeOne(string s) {
return s.TrimStart();
}
public static string ChangeTwo(string s) {
return s.TrimEnd();
}
Depending on some criteria, you can choose between them, and put the choice in a delegate:
Func<string, string> change;
if (DateTime.Today.DayOfWeek == DayOfWeek.Sunday) {
change = ChangeOne;
} else {
change = ChangeTwo;
}
Then you can use the delegate just a regular method. The code that uses it doesn't have to know what the method does, or why:
string x = " asdf ";
x = change(x);
Delegates are for example widely used for generic collections, where the library methods doesn't have to know anything about the objects in the collection. You just provide it with a delegate to a method that picks out the relevant information.
Here the Where method doesn't know anything about the objects in the list, it only gets a delegate to a method that determines if an object should be included in the result or not:
IEnumerable<obj> older = listOfObj.Where(o => o.Age >= 18);

How to Retrieve Method's Signature in Squeak

printThisMethodSig: aSomething
stack := thisContext stackOfSize: 2.
Transcript show: (stack at: 2); cr.
stack at: 2 returns the method context of the current method. It is possible to retrieve the compiled method of the current method using method message. I want to be able to print the whole signature of the method, for example: from:to:.
I looked at both MethodContext and CompiledMethod classes but could not find out how to do it.
Thank you.
You can use the selector message to retrieve the name of a CompiledMethod.

Resources