Create an alert's message out of < 2 R.string.id texts - java

I'm creating an alert which should display a variable inside its display message.
So I've created a R.string.dialog_message1 and a R.string.dialog_message2 to put before and then this variable. This is what I achieved:
builder.setMessage(R.string.dialog_message1 + lastOnes + R.string.dialog_message2)
.setTitle(R.string.dialog_title );
I get no errors until I get to the runtime process.
It displays:
"Submit query" instead that my own mixed message, any ideas?

Your code should look like:
builder.setMessage(getString(R.string.dialog_message1) + lastOnes + getString(R.string.dialog_message2)).setTitle(getString(R.string.dialog_title));

Your R.string.stringname1 calls are returning the String resource ids, not the Strings themselves. This example from Android will show you how to properly use String resources.

Related

ArchUnit class link in violation messages

I've noticed that using standard ArchConditions display messages in the following format:
Class <full_class_path> does not <some_rule> in (<class_link>)
However, this is not the case for custom conditions that add violation messages to the event like:
events.add(SimpleConditionEvent.violated(item, item.getName() + " some message"));
With this, no link to the violating class is appended to the message automatically. I wonder what the first argument (correspondingObject) is actually used for then.
Is this a bug in the framework or am I missing something? Having these links are really useful. I've tried using the JavaDoc #link notation in the message string to no avail.
Most of the domain classes like JavaClass, JavaMember or JavaAccess implement the interface HasSourceCodeLocation, which contains the method getSourceCodeLocation to obtain the location in the source code. The returned object SourceCodeLocation can then be used to output the location via the toString method.
For example
events.add(SimpleConditionEvent.violated(item, item.getDescription() + " is violated in " + item.getSourceCodeLocation()));
would return
Class <org.example.Dummy> is violated in (Dummy.java:0)

How to convert raw html to something I can test with Selenium?

My team has created a CMS. When it's API is called by the client (using POST - with parameters), it responds with raw HTML, which is then injected into the client's page.
I am assigned to create automated testing specifically for the HTML (not the client page). On my computer I can save the HTML in a file and open with a browser to test it out locally.
To get the test to run on a build server or through Sauce Labs, I am trying to figure out a way to render the HTML so I can have my test framework grab a screenshot to be compared. My test framework is Java/Junit using Selenium bindings, and I use Applitools for screenshot comparison.
I looked into PhantomJS but got a bit lost in the JS world (I am much more comfortable with Java). Also it appears that these artifacts are quite dated in Maven. If this is suggested, I would really appreciate an example.
I have found topics related to posting to the http endpoint using the Junit approach (leveraging Rest Assured), but I am stuck on what to do with the HTML response and how to plug that into a Selenium test. Please, can anyone offer guidance or suggest a tool to do this?
You could use the data scheme to load the html:
driver.get("data:text/html;charset=utf-8," + URLEncoder.encode(pageHtml, "UTF-8"));
Though you may be limited by the length and it won't load the resources present in a separate folder.
Another way would be to execute the requests directly in the page and to then rewrite the whole page with the result.
Something like:
// set domain
driver.get("https://stackoverflow.com");
// navigate some HTML from a request
navigate(driver, "POST", "/search", "q=abcd");
public void navigate(driver, method, path, body) {
String JS_NAVIGATE_REQUEST =
"(function(method, path, body, callback){ " +
" var xhr = new XMLHttpRequest(); " +
" xhr.open(method, path, true); " +
" xhr.onloadend = function(){ " +
" document.write(xhr.responseText); " +
" document.close(); " +
" callback(); " +
" }; " +
" document.write(''); " +
" xhr.send(body); " +
"}).apply(window, arguments); " ;
((JavascriptExecutor)driver).executeAsyncScript(JS_NAVIGATE_REQUEST, method, path, body);
}
I would save the HTML into a file and use IE to display that file.
You can use badboy tool to capture the screenshots of the HTML files saved locally but this is not including selenium integration. It is just to have the baseline screenshots from the HTML saved locally.
Save all the responses in HTML with some predefined naming convention like SS_1,SS_2.
Open badboy and pass the path of 1 file in the browsing pane (at upper right) or use "Request" from tools (Drag & Drop) and provide the path of first file saved locally.
Put snapshot tool below it and configure to save snapshots.
Add variables ${iterator} and provide values
Double click on "Request" and change the file name suffix from SS_1 to ${iterator}
Now, configure step to run for each value of variables by double clicking on the step and selecting the second radio button (For each value of variable) .
Reference tool - Badboy

UFT/QTP: Count child objects in Java Internal Frame

I need to compare a string with all values of my text fields that are inside in a Java Internal Frame.
I already tried to use this code:
Dim getElement
Set getElement = Description.Create
getElement("class description").value = "text box"
'I tried different class names: "OracleTextField", "JavaEdit"
'getElement("micclass").value = "OracleTextField"
'getElement("micclass").value = "JavaEdit"
Set obj = Browser("xxxx").JavaApplet("Main").JavaInternalFrame("yyyy").ChildObjects(getElement)
total = obj.Count
' For loop goes here
total returns 0 all the time.
Can you tell me what I'm doing wrong?
If you need something more let me know.
I tried the following line and it works. Now i have total number of text fields available in Java internal frame.
getElement("to_class").value = "JavaEdit"
Following QTP documentation didn't help, but if you check your object properties inside your Object Repository you'll find all properties of each object. Instead of "micclass" try to use your property name. Mine was "to_class" with value "JavaEdit".
QTP Documentation explains why we should use "micclass" and differences between "micclass" and "Class Name". However none of them worked for me. I used "to_class" property and it works fine!
I'm working with UFT v12.02

Error message doesn't display correctly

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

Android Webview - Change Input Text

I've set up my webview properly and I execute my Javascript in the onPageFinished method.
The problem is that whenever I try to change the value of my input, no matter what I do, I end up with the entire webview being replaced by the value of the input that I'm trying to replace.
view.loadUrl("javascript:document.forms[0].elements['password'].value = 'test';");
Any ideas?
PS. This code in the same place works perfectly.
view.loadUrl("javascript:checkForm()");
This executes the checks and submits the form. I get a popup "Please enter a value" after running this.
I have also tried document.getElementsByName("password")[0].value = 'test'; Same result.
RESOLVED: It was the emulator causing the problem. I tested directly on my phone with USB debugging switched on and it works perfectly.
Your first line of code works for me using id or name attributes:
view.loadUrl("javascript:document.forms[0].elements['password'].value = 'test';");
the second line, works with getElementById but doesn't with getElementByName:
view.loadUrl("javascript:document.getElementByName('password').value = 'test';");
So, that's not the problem. Maybe if you post the rest of the code.
You try to change the view, so you need to use:
.dispatchEvent(new Event('input')) ",null).
Try this:
view.evaluateJavascript("javascript: " +
"var password= document.getElementById('password'); " +
"password.value = 'test'; " +
"password.dispatchEvent(new Event('input')) ",null);

Categories

Resources