RTE and selenium -uploading image.

I have been spending some quite times trying to upload an image using the YUI RTE. The problems with the upload, is that when the upload button is clicked it calls the native system file uploader (in my case linux) . And this makes selenium access limited. and unapproachable.

I had couple of issues with the RTE which was solved with more of  “google.com” and “meet the dead end-trace back and use another route” method 🙂

Problem: clicking on the upload button would not trigger the file upload overlay.

Solution: Instead of using the click method use the mousedown.

Problem: Inconsistency with speed.

Soution: Not too happy with this, but adjusting the setspeed to slower resolved the problem- this can be problematic when you are trying to figur eout how to run the script on environments that have varied perfomance, not to forget the VM‘s and OS‘s they will be run on.

Problem: How does one pick the file using th enative file selector menu if selenum does not recognize it?

Solution: You can’t. either try and mess with autoit (for IE) or directly type in your file path.

Here is the code: I have again used http://shine.yahoo.com. Please run the test after logging in. I ran it via the IDE so I could control speed using the little bar on the top left. When it comes to running it on the RC, I will need to find the speed it is optimal to run at. Enjoy. As always feel free to comment/email me if you have any suggestions or if you would like to share any nifty tricks.


package com.example.tests;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.<a class="zem_slink" title="Test cricket" rel="wikipedia" href="http://en.wikipedia.org/wiki/Test_cricket">Test</a>;
import java.util.regex.Pattern;

public class test extends SeleneseTestCase {
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.yahoo.com/");
selenium.start();
}

@Test
public void testTest() throws Exception {
selenium.open("http://shine.yahoo.com/write");
selenium.waitForPageToLoad("");
selenium.mouseDown("xpath=//*[@id=\"yui-gen8\"][@title=\"Image Options\"]");
selenium.focus("xpath=//input[@id=\"insertimage_upload\"]");
selenium.type("xpath=//input[@id=\"insertimage_upload\"]", "<em><strong><enteryourimagefilepathere></strong></em>");
selenium.click("xpath=//*[@id=\"insertimage_upload_btn\"]");
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (selenium.isElementPresent("xpath=/html/body/div/div[2]/div/form/div/div[2]/p")) break; } catch (Exception e) {}
Thread.sleep(1000);
}

selenium.click("xpath=//*[@id=\"imageDone\"]");
}

@After
public void tearDown() throws Exception {
selenium.stop();
}
}

A quick and neat definition for TDP/UDP and HTTP/FTP

For those confusing times, I thought this was a pretty neat way of actually describing it.

TCP/IP is a big chapter and one that can’t be analyzed in a few paragraphs. To help you get the big picture, we’ll keep things simple and focus on the details you need, to ensure you get a proper understanding.

The term “TCP/IP” stands for Transmission Control Protocol / Internet Protocol and refers to a number of protocols. The “IP” part of the term, which stands for Internet Protocol, is used by TCP and UDP, to transport them from one network to another. Think of IP as a sort of high-way that allows other protocols to get on and find their way to other computers. TCP and UDP are the “trucks” on the highway, and the “load” they are carrying are protocols such as HTTP, File Transfer Protocol (FTP) and more.

As you can understand, TCP and UDP are transport

This and more can be learnt from here.

Whats the difference between http and https?

In many ways, https is identical to http, because it follows the same basic protocols. The http or https client, such as a Web browser, establishes a connection to a server on a standard port. When a server receives a request, it returns a status and a message, which may contain the requested information or indicate an error if part of the process malfunctioned. Both systems use the same Uniform Resource Identifier (URI) scheme, so that resources can be universally identified. Use of https in a URI scheme rather than http indicates that an encrypted connection is desired.

There are some primary differences between http and https, however, beginning with the default port, which is 80 for http and 443 for https. Https works by transmitting normal http interactions through an encrypted system, so that in theory, the information cannot be accessed by any party other than the client and end server. There are two common types of encryption layers: Transport Layer Security (TLS) and Secure Sockets Layer (SSL), both of which encode the data records being exchanged.

When using an https connection, the server responds to the initial connection by offering a list of encryption methods it supports. In response, the client selects a connection method, and the client and server exchange certificates to authenticate their identities. After this is done, both parties exchange the encrypted information after ensuring that both are using the same key, and the connection is closed. In order to host https connections, a server must have a public key certificate, which embeds key information with a verification of the key owner’s identity. Most certificates are verified by a third party so that clients are assured that the key is secure.

This and more information can be found here.

IP address, in perl – the simple not so effective way.

What pattern could be used to match an IP address such as 192.168.53.124, where each part of
the address is a number from 0 to 255?

I first tried working on this using regex and then abandoning it. The problem was not the “format” of the ip address persay, but more of the limitation of it having to be less that 255.  Not too thrilled with it, and exploring the regex way, which I shall update (if I dont loose interest) sometime .. let me know if you have any thoughts on the regex version of it.


#! /usr/bin/perl -w
use strict;

print " Hey you, enter a sentence or a word\n";

my $line=<STDIN>;

my @splitline;

chomp $line;

print "line is $line";

@splitline=split(/\./,$line);

if(scalar(@splitline)==4){
 if($splitline[1]<=255){
 if($splitline[2]<=255){
 if($splitline[3]<=255){
 if($splitline[4]<=255){
 print ("Yayy!, you have a valid address\n");
 }
 else{
 print ("Not a valid address beep beep \n");
 }
 }
 else{
 print("Not a valid address beep beep \n");
 }
 }
 else{
 print("Not a valid address beep beep \n");
 }
 }
 else{
 print("Not a valid address beep beep \n");
 }
}
else{
 print ("yikees you don't even have the correct format");

couple of take aways:

1. Formating of the if’s

2. Length of the array can be found by forcing it as a scalar, also by saying $t=$#array

3. the length inbuilt function only acts on scalars.

Perl string manipulations when specified as a scalar.

When one defines a scalar variable, and then assigns a string type to it, it can get confusing.At least in my mind, its one huge blob of data ,so how does one say for example calculate the number of characters in it?, or manipulate it?. My first instinct was to compare $_ with the any character in a foreach. as in


foreach ($somestring){

if($_  ne undefined){

....do something;

}

}

Till I printed out the data and realised that $_ will see the string(scalar) variable as one blob of data.

Here is a tiny easy breezy program:

Create a scalar variable containing the string “The quick brown fox jumps over the lazy dog”.Print out the length of this string, and then using substr, print out the fourth word (fox).   Update this to Replace the word “fox” in the above string with “kitten”.


#! usr/bin/perl -w

use strict;

my $sentence="The quick brown fox jumps over the lazy dog";

my $length=0;

$length=length($sentence);
 print "The total number of characters in $sentence is $length \n";

substr ($sentence,15,4)=" kitten";

print " $sentence

There is a handy length inbuilt function to do the trick, and strings can easily be manipulated using the format here:

However a point to note is that if you try and substitute substr ($sentence,15,4)=” kitten”; with $somestring=substr($sentence,15,4,”kitten”) didn’t seem to work. I don’t know why, perl version I am using?. Let me know if you know why, else I’ll update this post once I figure it out 🙂

Happy coding.

Basic client server communication (web based)

1. Browser is launched with site address.

2. Request is made to the server via a router.

3. This communication happens via a protocol (examaple TCP/IP,http)

4. Server looks for requested paths and resolves it with appropriate response.

Types of methods:

1. GET: The form data is encoded within a URL in a browser.

2. POST: The form data appears within the message body. Its usually used to update, post data, or example buy a product.

3.PUT :Uploads a resource to the server. Example uploading files to the web server.

 

Response codes:

404: File not found.

307: redirect

403: permission denied.

200:ok all is well.

 

Fibonacci series in Java

Well, its one thing to claim you know the OOPS Java concepts and entirely different when you start to code with it. I started off with a mess of code and finally thanks to certain code gurus, I could arrange it into OOPS concept and get it working. Most of the Java recursive fibonacci series out there, don’t print the series, but print the last and final number. So here you go. Enjoy. Its kinda basic. But there’s where I start.

Env: Eclipse IDE
Language: Java


package Fibonacci;

public class fibonacciCalculations {

int [] fib;
int size = 0;
public fibonacciCalculations(int k) {
fib = new int [k+1];
size = k+1;
}

void printSeries()
{
for (int i =0;i
System.out.println(fib[i] + "  ");
}
}
public int calculateFibonacci(int k)
{
if(k==0 || k ==1){
fib[k] = k;
}
else  {
fib[k]=calculateFibonacci(k-1)+calculateFibonacci(k-2);

}
return fib[k];

}

}

Save the above within package Fibonacci and name the file fibonacciCalculations


package Fibonacci;

public class callFibonacci{
public static void main(String args[]){
int n = 1;
fibonacciCalculations newFibonacci=new fibonacciCalculations(n);
newFibonacci.calculateFibonacci(n);
newFibonacci.printSeries();

}
}

Save the above within package Fibonacci and name the file callFibonacci

Interview-notes- part I

Lots of Notes

Image by Spyderella via Flickr

I am out there looking for new opportunities, this time around my criteria is different. I want lesser commute, more flexibility, a promise to myself to be more of a hands on technical person, people and the environment, in that- how people interact with each other.Hopefully looking for a company that will be my base for at least 3 years. Having said that, my past gig has been at a large company. And I have been spoilt.

I cannot mention the company name here, but lets just say that it is a start-up mode 500 employee firm. The pace feels like start up, they have agile method of development, low dividers instead of cubes,glass walled conference rooms, very little privacy, party lights adorn the walls with red and white furniture. In terms of interview time, I met 6 people in 5 hours. The interviews, at least 1 was made to stress me out, and very fast passed- apparently to give me a feel of what it is like to work there- that was my best most enjoyable round.What I did like about each of the interviewers, is that they had all read my resume, and come prepared. What I didn’t like about some one of the interviewers is them going over the board about the company. When I see that, I see aggression, and I do not want an aggressive car salesman kinda manager-at least not for engineering,atleast not when I am interacting with my potential manager- who I will count on to cover my back when the time comes.

1. Interviwer1: The newb:Automation QA: Indian lady:

Must be as experienced as me, with little to no exp of interviewing. Text book interview.

  • Details on my resume.
  • Dug into automation aspect of it.
  • How does client communicate with the server. Browser-TCP/IP (or some protocol- request sent)-server- server-response. She wanted to know how the browser knows how to contact the server. (very vague) but then after some tries, I said router. And thats what she wanted to hear.
  • Asked what is Java?. I guess she was looking for a textbook answer?.  I was vague, she asked if it was OOPS. I said yes and then started rambling about the characteristics of OOPS>
  • what is polymorphism.
  • What is encapsulation
  • What is the difference between overriding and overloading.
  • What is inheritance
  • What is multiple inheritance- how do you implement it in Java.

2. Interviewer 2: Hard nosed manager:Development manager: Indian lady

Came in to make me happy, are you cold, do you want something- Then came the, I expect my team to be nimble, smart, agile, else you don’t work -attitude- turned me off. I know she was setting her expectations. And yes. nothing wrong with that. But I am a different personality. I am a chill person,and this didn’t go well with me.

  • Talked about her team, what she expected.
  • Asked a general overview of my resume.
  • A container can hold 3 liters of water and another 5 liters, and you have unlimited suppy of water. How will you calculate 4 liters of water.

Interviewer 3(OH MY FAVORITE).-manager, hands on,the guy who builds tools.

Friendly, to the point, spoke very fast in multi-threads, apologized for it. But told me he was trying to stress me out- to give me a sense of the pace they worked at. I loved it.I loved his style of interviewing. If I do interview people I am so going to base it on this guy.Told me, he and his team always asks practical questions- I was begining to freak out.

  • He started off with what is your fav db, your web server, your browser. Drew them as boxes on the board. Asked me how they are connected.
  • Said the project he is working at, has a auto complete feature on it- type first three letters, and the cities matching it pops up. So he types in SAN, and say san diego, san-francisco pops up. But in this case it doesn’t how will I go about figuring it out.EXCELLENT QUESTION. In one shot, he managed to test how much I knew about technology, without necessarily knowing the terms for it- but also how I would trouble shoot it.
  • I started off with the db, using select statment, to senting a get requiest, to coming to the UI.
  • Asked me ttake his laptop and fire up firebug and told me how I would go about testing javascript.
  • Took his laptop back, taught me python in a very short time. Including classes and inherited classes: asked me questions on that. Then reversed it ans asked me to teach him python. It was overall an awesome inteview. I really dont kow what he was looking for, but I felt i was solving something- like I would at my day job, instead of trying to market or sell myself.

Interviewer 4: Very morose, classic dev types 😛 . American.

  • Asked me to code Fibonacci with java,
  • Asked me XML
  • Said there is a carrier, flight number, arrival airport, departure airport, to come up with classes. Ehh, isn;t this more like  a dev question?

Interviwer 5:UI developer: american, friendly.

  • resume stuff
  • Discussion on how things were done at my current job, and how they do it there.
  • Discussion on how I communicate with the developers.

Interviewer 6:Director of UI development: chinese-american, friendly- but you could tell he was testing you.

  • Resume details
  • What do I look for in a UI- how do i test it.
  • I chatted with him about their latests kick ass product, and that gave him a high, obviously he was proud of it- spent 15 mins showing me that 😀 . Went over the 1/2 hour limit and tokok 45 minutes instead.
  • Details on automation testing. Also told me my resume was light, but that it was ok!

Overall, I spoke to 6 people, I enjoyed talking to 3 of them. I like interviews that try and test your “day to day- things you would use at your job” skills, thanwhat I perhaps memorized sitting in a class. Its ok if you are not a guru at oops concepts (for a qa) maybe for a dev its highly important. If you have  rough idea of what it is, and you have the capacity to understand what the other person is talking about, its good enough.

Well IMHO a good QA

1. Communicates well. Asks questions.

2. Is analytical.

3. Has the thirst to know more about the product, so he/she can test it better.

4. Passion for breaking stuff.

5. Understands code, and has the ability to research and build on something.