Programmatically created AWS EC2 Instances not showing up in browser - java

This might be a only-for-me problem. I am using eclipse with AWS plugin to tryout AWS EC2 Instances. The instances are successfully launched through program, I get the list of running Instances' ids.
The problem is i launched three instances and they are not showing up in the running instances in the browser, although it shows in the eclipse console:
#5 Describe Current Instances
You have 3 Amazon EC2 instances
i-801cc37a running
i-fb1ec101 running
i-bc1cc346 shutting-down
This is the code I am using to create AWS Instance:
final String imageId = "ami-76f0061f";
int maxInstance = 1, minInstance = 1;
RunInstancesRequest rireq = new RunInstancesRequest(imageId, minInstance, maxInstance);
RunInstancesResult rires = ec2.runInstances(rireq);
List<Instance> insres = rires.getReservation().getInstances();
String createdInstanceId = null;
for(Instance ins: insres) {
createdInstanceId = ins.getInstanceId();
System.out.println("New Instance has been created: " + ins.getInstanceId());
}
( There was a problem I was facing; The ImageId was given to me by my professor which is not present in the list of images in the aws.amazon website for my region. However, only this works. I got two Ids from the website for my region, but they ended up with InvalidAMIID.NotFound error. I even tried the solution here. This might be relevant to not showing up in browser as the ImageId is not in my region... )
Can anyone please tell me where am I going wrong? Or is this pretty normal. If it is normal, is there anyway to make the 'programmatic' instances to show up in browser. If the ImageIds are the problem can I please know how to fix it? I assure that the region in eclipse and aws website are same: oregon(us-west-2).
Thank you

Change the region in your console. Based on your screenshot it is set to "Oregon". Change it to "N. Virginia" and you should be all set.

Related

Service Reference for android?

I have a service which I need to access from an android app. The goal is simply to send a number value from a textbox and get a result string back.
I know it is possible to do so in VB using a Service Reference, which I have done. Here is the sample code :
Private Async Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim service As New ServiceReference2.Service1Client(ServiceReference2.Service1Client.EndpointConfiguration.BasicHttpBinding_IService1)
Try
lblReturn.Text = Await service.GetDataAsync(CInt(txtValueSent.Text))
Catch ex As Exception
lblReturn.Text = ex.Message
If Not ex.InnerException.Message Is Nothing Then
lblReturn.Text = lblReturn.Text + ex.InnerException.Message
End If
End Try
End Sub
After research I can't seem to find any way to have a quick and simple result like it is possible to with Visual Studio using Android Studio
Are there any tools available which work in a similar way ?
If not which process would be recommanded to achieve the same result ?
Are there any usefull links which could help enlighten me?

Java jface calling browser from an relative location

I have encountered a small problem that I need some help on. The issue is that I wish to call a browser window which calls a html page. The html file opens in 3 different browsers so the code for that should be correct. The actual problem is that it brings up a page can't be displayed error message
Here is the code that gets the location
package org.error;
public class BrowserLocation {
private String test1 = "org\\error\\PatientNumberError.html";
public BrowserLocation() {
}
public String patientNumberAddress() {
return test1;
}
}
and here is the code that creates the browser component and calls the location of the html file.
Browser browser = new Browser(container, SWT.NONE);
browser.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_BLUE));
browser.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
browser.setUrl(browserLocation.patientNumberAddress());
browser.setBounds(25, 25, 315, 180);
Would it be possible to find the error of my ways?
setUrl require a URL so you need something like:
browser.setUrl(new File(path).toURI().toURL().toString());
Sorry for not getting back to you earlier.
Someone that I know who is a senior Java programmer told me the problem that I was having was a case of absolute address versus relative address.
The reason for this is that if I was reading and writing to a file, then I would be able to use a relative address. However If I'm interacting with a server which is the case here as eventually It could go on-line (If I had the money) it would need to be an absolute address.
As I am still learning Java programming this was a very specific and important lesson to learn. I hope this would help anybody else who has had this issue.

Trying to check web content on android during Robotium test

My application is service running on background and making changes to network traffic. I want to make a test with Robotium calling for web source and checking the the page.
Here is my code for calling for web content:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
Log.d(TAG, "Looking for text ["+expected+"] at address ["+url+"]");
getSolo().getCurrentActivity().startActivity(i);
getSolo().waitForWebElement(By.textContent(expected), timeout, false);
Here are few things i have tried but with no result
bool foundContent = getSolo().waitForText(expected));
foundContent = foundContent | getSolo().getCurrentWebElements().size() > 0;
foundContent = foundContent | getSolo().getWebElement(By.tagName("div"), 0));
It is enough for me when the test checks "Yeah the page contain word porn" or "Nope the page contain word porn" but if its possible I would be glad if have access also to whole page code in string if its possible.
My first question here so i hope its OK
Thank you for help in advance!
P.S.: I read that solo object have method waitForWebElement returning bool (false when the content is not present till timeout) in 4.0 but in code (using 4.0 jar Robotium) and in other reference there is only a void. Is it something that they are still working on?

html5 local database access with selenium

I been asked to make a selenium test that checks the local database of html5 and verify that the information in there matches what's being displayed on the screen. This is for a mobile application that can be used on chrome I have everything working as far as selenium working with chrome.Now I am just stuck on trying to find a method that can be used for with selenium that will access the local database storage. There's a interface in selenium html5 packages that DatabaseStorage however I can not figure out how that works or how to use it. The test cases are being written in Java. Thank you all for any help you can provide on this.
I have tried to create a new object of the database storage. which dident work i tried creating a new object of result set also tried doing implements database storage. in the API for database storage it says it a interface but it dose not list a constructor. i not sure how to access a method when there's no constructor for the interface.
// Database Storage
private ResultSet executeQuery(String statement, String... param) {
String databaseName = "'HTML5', '1.0',"
+" 'Offline document storage', 100*1024";
return ((DatabaseStorage) driver).executeSQL(databaseName, statement, (Object[]) param);
}
see Selenium's HTML5 test for more details.

How to deal with file uploading in test automation using selenium or webdriver

I think that everybody who uses Webdriver for test automation must be aware of its great advantages for web development.
But there is a huge issue if file uploading is part of your web flow. It stops being test automation. The security restriction of browsers (invoking file selection) practically makes it impossible to automate tests.
Afaik the only option is to have Webdriver click the file upload button, sleep the thread, have developer/tester manually select the file, and then do the rest of the web flow.
How to deal with this, is there a workaround for it? Because it really can't be done like this. It wouldn't make sense.
This is the only case I know of when browser security restrictions do not apply:
<script language=javascript>
function window.onload(){
document.all.attachment.focus();
var WshShell=new ActiveXObject("WScript.Shell")
WshShell.sendKeys("D:\MyFile.doc")
}
</script>
Webdriver can handle this quite easily in IE and Firefox. Its a simple case of finding the element and typing into it.
driver = webdriver.Firefox()
element = driver.find_element_by_id("fileUpload")
element.send_keys("myfile.txt")
The above example is in Python but you get the idea
Using AWT Robots is one option, if you're using Java, which you are. But it's not a good option, it is not very dependable, and not clean at all. Look here
I use HttpClient and run a few tests outside of Selenium. That's more dependable and cleaner.
See the code below. You'll need more exception handling and conditionals to get it to suit your job.
HttpClient c = new HttpClient();
String url = "http://" + cargoHost + ":" + cargoPort + contextPath + "/j_security_check";
PostMethod post = new PostMethod(url);
post.setParameter("j_username", username);
post.setParameter("j_password", password);
c.executeMethod(post);
url = "http://" + cargoHost + ":" + cargoPort + contextPath + "/myurl.html";
MultipartPostMethod mPost = new MultipartPostMethod(url);
String fileNameWithPath = this.getClass().getClassLoader().getResource(filename).getPath();
File f1 = new File(fileNameWithPath);
mPost.addParameter(elementName, f1);
mPost.addParameter("action", "upload");
mPost.addParameter("ajax", "true");
c.executeMethod(mPost);
mPost.getResponseBodyAsString();
The suggestion of typing into the text box works only if the textbox is enabled.
Quite a few applications force you to go through the file system file browser for obvious reasons.
What do you do then?
I don't think the WebDriver mavens thought of just presenting keys into the KeyBoard buffer (this used to be a "no brainer" in earlier automation days)
===
After several days of little sleep, head banging and hair pulling I was able to get some of the Robot-based solution suggested here (and elsewhere).
The problem i encountered was that the dialog text box that was populated with the correct file path and name could not respond to the KeyPress/Release Events of terminating the file name with VK_ENTER as in:
private final static int Enter = KeyEvent.VK_ENTER;
keyboard.keyPress(Enter);
keyboard.keyRelease(Enter);
What happens is that the file path and file name are typed in correctly but the dialog remains opened - against my constant hoping and praying that the key emulation will terminate it and get processed by the app under testing.
Does anyone know how to get this robot to behave a bit better?
Just thought I'd provide an FYI to author's original post of using ActiveX. Another workaround would be to integrate with desktop GUI automation tools to do the job. For example, google "Selenium AutoIt". For a more cross-platform solution, consider tools like Sikuli over AutoIt.
This of course, is not considering WebDriver's support for uploads on IE & Firefox via SendKeys, or considering for other browsers where that method doesn't work.
After banging my head on this problem for far too many hours, I wanted to share with the community that Firefox 7.0.1 seems to have an issue with the FirefoxDriver sendKeys() implementation noted above (at least I couldn't get it to work on my Windows 7 x64 box), I haven't found a workaround, but updating to Firefox 8.0.1 seems to have fixed the problem. For those of you wondering, it's also possible to use Selenium RC to solve this problem (though you need to account for all of your target operating systems and the native key presses required to interact with their file selection dialogs). Hopefully the issues I had to work around save other people some time, in summary:
https://gist.github.com/1511360
If you have your are using a grid, you could make the folder of the testfiles open for sharing.
This way you could select the upload input field and set its value to \\pc-name\myTestFiles
If you're not, you should go with local files on each system.

Categories