I already have this kind of error, and I still don't know why. What am I doing wrong?
I need to assert true if I get a text in the page source.
So here is my method:
public boolean AssertSearch() {
return driver.getPageSource().contains("Item found");
}
And here is my assert:
assertTrue(buscarnok.validabuscaNOK());
And I keep receiving the message "Assertion Error". I don't know why. If I change the "return driver.getPageSource().contains("Item found");"to driver.findelement(by.id("someID")).isdisplayed();it works fine, so why isn't it working with getpagesource?
If the text you are looking for is not initially in the page or if it is hidden, it may not find it.
Try something like this:
String bodyText = driver.findElement(By.tagName("body")).getText();
Assert.assertTrue("Item Found", bodyText.contains(text));
You can narrow down the search by selecting a different tag name or even a div by its class or id
Related
I have set some error code and message in a JSON file in my project which looks like (not original code for safety):
{
"ERROR":"Limit is £100."
}
When I set this message to be thrown as exception when testing from Postman, instead of showing Limit is £100., it shows like Limit is ?100.
So, I'm worried why £ gets converted to ?. Then, I tried to replace this ? with £ by using below code:
String message = fetchErrorMessage("ERROR", ***some parameters***);
if (message != null) {
message = message.contains("�")
? message.replaceAll("�", "£")
: message;
}
Note: I checked with � instead of ? because when I was debugging the code and hover over the message to check whether it contains the £ symbol or not, I found that it was having a weird looking square block (check screenshot below). So, I copy-paste it and got to know it's a question mark symbol inside a black diamond.
Now, with above piece of code change, the message is coming properly in Postman but soon I realized that when I deployed the code in UAT environment, it still shows ?.
So, any workaround how to fix it?
There is a specific character that shows up wrong when UTF-8 is set from the client(SoapUI) in the header content-type: application/json;charset=UTF-8.
For more details Check this link
I'm trying to make dialog that will display an error message whenever I make wrong move in my scrabble game. So in Problem.java, I make it like this
class Problem
{
Problem(String s)
{
message = s;
}
}
So I write code to display the warning like this :
void displayProblem(Problem p)
{
JOptionPane.showMessageDialog(this,p, "WARNING!",JOptionPane.WARNING_MESSAGE);
}
I expect error message when I don't put tile something like this :
"no tiles placed"
just like what's in the code but it ended up like this :
What's wrong with my code anyway?
You either need to pass p.message to the dialog or override Problem's toString() method and return message there. What you're seeing is the output of standard toString(), i.e. class name + instance id.
Btw, you posted a lot of irrelevant code, which might make a lot of people want to either close the question or prevent them from trying to answer. When asking questions you should try and boil it down to the relevant parts, which in your case would be how you display the dialog and what the parameters look like. For more information, have a look here: https://stackoverflow.com/help/how-to-ask
I am trying to make a script for page, all I need is just simple java script, if there is a text on the page in example - no found the macros should hit the button find work. The macros must hit the button find work in 1 second interval.
Sorry for my english
This is an example how you could make JavaScript script for iMacros. The main part is CONTENT=EVENT:MOUSEOVER since that part hovers over a page element. If element is present it will return true else it will return false. Try it out.
var macroTest;
macroTest ="CODE:";
macroTest +="TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:TestForm ATTR=NAME:C9&&VALUE:ON CONTENT=EVENT:MOUSEOVER"+"\n";
if(iimPlay(macroTest)>0)
{
alert("Checkbox found");
}
else
{
alert("Checkbox not found");
}
I'm updating a Selenium program I wrote a while back and part of it has stopped working. I want to go through a whole series of links on a page, click on each, making sure that some expected text is present. But sometimes a log-in page (https://library.med.nyu.edu/sso/ezproxy_form.php) appears before the desired page, in which case I need to log in before checking the page. The problem is, no matter what string I put in to check whether I've landed on the log in page, Selenium concludes it's not present and skips logging in, obviously causing everything else to fail. See below--I'm not sure that was actually the problem. It seems to be instead that it's rushing through the "if we need to sign in" code without actually signing in, then obviously failing the main part of the test because it's not on the right page.
Here's the code--does anyone see my mistake?
for (int i = 0; i < Resources.size(); i++) {
try {
selenium.open("/");
selenium.click("link=" + Resources.get(i).link);
selenium.waitForPageToLoad("100000");
if (selenium.isTextPresent("Please sign in to access NYUHSL e-resources")) {
selenium.type("sso_user", kid);
selenium.type("sso_pass", password);
selenium.click("name=SignIn");
selenium.waitForPageToLoad("100000");
}
if (!selenium.isTextPresent(Resources.get(i).text)) {
outfile.println(Resources.get(i).name + " failed");
}
} catch (Exception e) {
outfile.println(Resources.get(i).name + " could not be found--link removed?");
}
}
Does the login page have a page title? If yes, try validating the page title using selenium.getTitle() method to check if you are headed to login page. If not, proceed clicking on the link without logging in.
I think page title validation can help resolve this issue
Try putting:
selenium.setSpeed("1000");
Right after the selenium.open this will inject 1 second delay (1000ms) between selenium commands. You should make it a standard practice to add this, especially if you're not running headless browsers.
Also you might consider using, since you know the url you are expecting to be on if on the login page, the selenium command getLocation. This will return the absolute URL of the current page. Might be more effective than trying to look for elements that can change at any time within the page.
So to use getLocation in your code above:
if (selenium.getLocation() == "your reference url"){
do your login stuff here
}
Again this is just a sample to illustrate what I'm saying. Hope it helps you out.
I have a TableViewer with an ICellModifier which seems to work fine. I set an ICellEditorValidator on one of the cell editors, though, and I can't get it to behave the way I would like. Here's my abbreviated code:
cellEditors[1] = new TextCellEditor(table);
cellEditors[1].setValidator(new ICellEditorValidator() {
public String isValid(Object value) {
try {
Integer.parseInt((String) value);
return null;
} catch(NumberFormatException e) {
return "Not a valid integer";
}
}
});
It mostly works fine. However, there are two issues:
The modify method of the cell
modifier receives a null as the new
value if the validator returns an
error. I can code to handle this,
but it doesn't seem right. Null
could be a valid value, for example,
if the user's picking a background
color and they picked transparent.
(This is a general issue, not specific to this example.)
The validator's error message is
never displayed to the user. This
is the big problem. I could also
add an ICellEditorListener and
display a dialog from the
applyEditorValue method if the
last value was invalid. Is this the
"proper" way to do it?
By the way, for reasons beyond my control, I'm limited to the Eclipse 3.0 framework.
you can add a listener to your Editor:
cellEditors[1].addListener(
public void applyEditorValue() {
page.setErrorMessage(null);
}
public void cancelEditor() {
page.setErrorMessage(null);
}
public void editorValueChanged(boolean oldValidState,
boolean newValidState) {
page.setErrorMessage(editor.getErrorMessage());
}
With page being your current FormPage, this will display the errorMessage to the user.
Regarding the second issue, the string the validator's method isValid returns becomes the error message for the CellEditor owning that validator. You can retrieve that message with CellEditor.getErrorMessage.
It appears to me that the easiest way to show the error message is through a ICellEditorListener, as Sven suggests above. Maybe the tricky thing about this listener is that the cell editor is not passed as a parameter to any of its methods, so the assumption is that the listener knows which cell editor is talking to it.
If you want the dialog, the preference page or whatever object to implement the ICellEditorListener interface you have to be sure it knows the cell editor being edited.
However, if it's the cell editor itself which implements the interface it should have a way to properly carry the error message over into the dialog, the preference page or whatever. That's the currentForm page Scott is looking for.
One last thing worth noticing if you're using EditingSupport is that the value passed into the EditingSupport.setValue method is null when ICellEditorValidator.isValue returns an error message. Don't forget to check it out.