CSS selectors and selenium (webdriver)

When I started automation with selenium, I started using xpath, because that was the way to go. Till, when I moved companies, there was this talk of other QA engineers relying on CSS for locating elements from the DOM. I have recently started using CSS locators for various reasons. You can read about it here

I have been basing a lot of my locators on these very cool links

1. Are you ready to use CSS with selenium?
2. Multiple classes and ID’s, CSS- trips and tricks.
3. CSS selectors demystified from Sauceio 
4. Multiple classes and CSS by Maxdesign
5. Can I use this ?  Search
6. Css Rosetta stone and cookbook.
7. And my favorite of all, convert your Xpath to CSS using this link here.[cssify]

Some examples:-

  1. Spaces in classnames: So if you have a class name like this ul class=”A B”, you can do a ul.A.B
  2. Lists can be tricky: Here’s a pointer:
	<li class="shrUPGrid">
           <ul id="sfly_5" class=" shrSG shrSGSelect">
<ul>
	<li style="background-image: <span class=;">url(https://sphotos-a.xx.fbcdn.net.jpg)"></li>
</ul>
<ul>
	<li style="background-image: <span class=;">url(https://sphotos-a.xx.fbcdn.net.jpg)"></li>
</ul>

You can find the Li by

 findElement(By.cssSelector("li.shrUPGrid > ul > li:nth-of-type(""
							+ pictureIndex + ")")).click(); 

where pictureindex is the index of the li

If I am sounding all cryptic please don’t hesitate to drop me a line.

Advertisements

Because “Eclipse” is sorta lame that way.“Import cannot be resolved”

I synched up with depot OUTSIDE eclipse, and then restarted eclipse and bhoom *scream 32 errors. I did this a few times, and a few more and I still saw those damn errors. I almost swore off my co-workers, till. … I did what any self-sufficient coder does. I googled . And this is what I found. Voila problem solved. Cleaning the project and refreshing it seems to have fixed the problem.

Thank you Sherif Mansour

 

Installing Selenium 2.0, maven,testng and eclipse.

I think I did struggle a bit to have this installed, and by trial and error I finally got it working on my mac. Here is what worked for me, if while installing you come across any problems please feel free to leave me a comment. Check if java is installed by typing java -version, if java does exist no error is displayed. Else install java before proceeding.

1. Start out by installing eclipse.( I have Indigo installed)

2. Launch eclipse, now within eclipse go to help->install new software and plug-in http://m2eclipse.sonatype.org/sites/m2e in the URL and follow the process to install maven.

3. Similarly install testng with  http://beust.com/eclipse

4. Now click on File->new->java project.

If you see a warning like

Description Resource Path Location Type
Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment. another project Build path JRE System Library Problem then to fix it , right click on the java library , build path and remove it. RIght click on the project->build path->configure build path ->add library->JRE system library->next, and pick the default java library

5. Right click on the project ->maven ->enable dependency. Observe that maven dependencies library and bin/source folders are created.

 5. Right click on the pom.xml file that is present and open with a text editor, replace with

<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://maven.apache.org/POM/4.0.0"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>MySel20Proj</groupId>
        <artifactId>MySel20Proj</artifactId>
        <version>1.0</version>
        <dependencies>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>2.14.0</version>
            </dependency>
        </dependencies>
</project>

make sure that the version is the latest as displayed here

6. Right click on the project and go to maven->update dependencies.

7. Click on File->new->source folder. Create structure /src/test/java.

8. Create new package (example) and class (google) paste the following test example:

package example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

public class google {
public static void main(String[] args) {
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new FirefoxDriver();

// And now use this to visit Google
driver.get("http://www.google.com");
// Alternatively the same thing can be done like this
// driver.navigate().to("http://www.google.com");

// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));

// Enter something to search for
element.sendKeys("Cheese!");

// Now submit the form. WebDriver will find the form for us from the element
element.submit();

// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());

// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
(new WebDriverWait(driver, 10)).until(new ExpectedCondition() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
});

// Should see: "cheese! - Google Search"
System.out.println("Page title is: " + driver.getTitle());

//Close the browser
driver.quit();
}
}

9. Now select project and click the play button.

10. VIOLA!

I have added testng functionality to the project but have not utilized it yet. I referred to jc webconcepts and the selenium site to help me with the installation. So thanks!

This is what my view looks like

 

Agile process.

I moved to  small-medium sized company from a large one. And have learnt some lessons in the past month or so. The company I joined was primarily water fall, but now we are moving to be more agile. The team that I work with, has been agile for a few years now, and well function as their own little unit.

At the big company, in my team things were already in place, well most of it. There were tweaks done to teams, for example, there was no formal walk through of the requirement with the QA, there was no code overview of the dev with the QA, the dev and QA mostly worked with, on demand. As in when the QA asked for information, it was provided.There were no test case reviews. What was definitely there was adherence to feature complete, code complete and site complete dates. The dates became stringent as the product evolved, that is  code and site complete was important, even if it meant that the feature complete dates were missed.There was weight-age given to high priority bugs.

This team has around 5-6 developers including the manager, who is very hands on. Yes the manager codes, and manages. When I say manage- I mean manages the projects, assigns tasks. But I also see that he does not manage people- or maybe he does- but he treats them like adults, and the developers behave like adults. They finish up tasks assigned to them. If they need help, they raise up their hands and ask for help.I like the team, most of the communication flows through the manager- but, the product and the QA are free to communicate with them directly. But the manager is always informed when a fix has a problem, or if the dev is stumped for a solution. The manager is the most experienced dev on the team- hence he also behaves as the architect.

The product managers are by far the best ever I have worked with. The are on top of it. The tool followed here is Rally, which means each and every use case has been transformed to user stories, with presentations and images- for the QA to view. The QA is however not involved in the requirements, this comes from the product.marketing team. The test cases are written for each user story, sent for review – to the product manager and the developer who is coding the user story- not the lead, not the manager. I love it that the developer and mainly the product manager takes time to review it- it usually goes through several cycles before its perfected. So far since there are two qa’s on the team, its feels awesome that as the code is being developed, the test cases are being developed, and when the code is finished, the QA is aware what the functionality is, and is ready to start testing them.

The product manager gives the QA a list of user stories that the QA would need to write up at the start of the sprint, and is expected to finish up the testcases and test if possible at teh end of the sprints.

What I like about the team, and find it a challenge, is that the product manager is so knowledgeble, finding bugs before the QA does. It challenges me, to get really picky, and to watch out for bugs. In conclusion I think I would not be too wrong if I said that how a agile process works depends on how good a product/project manager is.

OK coming to what I don;t like- when we initially started testing, I was told that they prefer that we communicate the issues before converting them to bugs. I was not comfortabel with that, but now that I see how the team works, I think its nice- saves us time and the developers are very forth coming in telling us how much of coding is left, anf that ultimately its pointless fo rus to file those bugs. Miracle of miracles, they seem to be doing alot of unit testing and self testing- which makes it harder for us to find bugs.

I also dno’t liek it that the process is fluid, no one talks about feature complte dates. no one talked about code compelte. Its very fluid- I have not yeat released a product with this team, so I’ll hold on to my negativity and see how it flows.

LIke I mentioned earlier we use Rally, I think its a handy tool and gives a good overview of user story generation to progress in test executions, its also possible to file bugs via rally. We havent experimented with that yet.

Finally, I think I understadn what agile process means. its means fludity in the process, its about people on the team coming together, and expressing what works and doesn’t work for them, and each member of the team is a player- everyone has to be actively involved- it assumes your team is mature, and dedicated to the work they are into.

Also the daily scrum is really agile, we meet in a white walled room, with a glass wall- and a telephone hung on to the wall. No furniture what so ever, we stand around the room and tell people what we worked on. 10 minutes tops. No computer, no presentation – nothing. I like it- some hate it. They think its pointless. Coming from primarily an agile process,  I love it- I know what the devs were up to- and plan on working- and I can voice by blocks – so everyone on the team is aware of it.

Interview notes- part 2

I wish I had blogged this earlier, before they fade off from my memory- but here is what I can remember. The company is medium sized. As usual, cannot mention the name of the company here.

1. Interview 1:recruiter: American:Female

The brief interview was very casual, she complimented on my perfume, and I think that set the tone of the interview for me. It being casual, and it relaxed me quite  a bit. She asked me

  • What was I looking for in terms of a career.
  • How my search was going.
  • Why I was leaving the previous company.
  • Explained me things about benefits.

2. Interviewer 2: chinese: development manager: male

asked me if I knew how to code in java script and html.

Asked me tons of resume stuff, mainly based on the process I followed.

  • My interaction with the developers.
  • My experience with the agile process.
  • What I liked about agile and what I didnt like about it.
  • What did I do when requirements were not available.
  • how did I handle difficult devs.
  • How much automation did I do?
  • What were stuff I would automate Vs not automate
  • What did I like about my previous company
  • what didn’t I like about it.
  • How did I handle cases where QA had to step in and say a release wasn’t happening.
  • How long were the agile process, how was the process followed from start to finish.
  • Did I have experience with offshore teams, and how did I intereact with them.
  • What problems did I face with the offshore teams.
  • How did I come up with test plans and testcases.
  • Were there review processes involved.  (these are some I remember 😛 )

Interview 3:(2 qa leads, one on call, one in person) – american male and female

  • What was the process followed.
  • What was my interaction with the devs
  • How did I interact with offshore teams.
  • What are my special interests.(outside work)
  • did I lead any projects.
  • How much did I automate, how did it work
  • In addition to that I asked them a lot of question, which I plan to post in another post which will perhaps go by the title ” I asked them this at the interview, is that ok 😛 “
  • They asked me why I would like to join company XYZ
  • What were some of the issues I came across when i dealt with offshore teams.

Interrview 4: The hiring manager: american : male

  • Why am I looking for a new job
  • What am I looking for in a job
  • Have I worked on automation
  • What have I done when there was a last minute bug found.
  • How do I handle developer relationship.
  • How did the agile process work for me?
  • Have I worked with the social aspect of a site
  • If given a choice between working for ecommerce vs social, which and why would I prefer it.
  • What would I prefer to work on, automation or manual
  • Have I played a lead role
  • Have I worked with off shore teams.
  • How much documents were required by the qa.
  • At what point did I htink a qa was necessary in a project.
  • how big was the qa team.
  • If each qa handled a particualar project, how did the qa’s interact, if any.
  • What did I like and dislike about manual and automation testing.
  • Why do I like to be a QA
  • Describe the agile process followed.
  • Gosh so many questions that I hardly remember any now.

Interview 6: Dev lead: american:female

  • Working relationship with the dev.
  • What am I looking for in a job.
  • Experience with agile.
  • Experience with offshore teams.
  • Describe my projects.
  • Manual testing vs automation testing, which one do I prefer.
  • What problems have I come across with offshore teams

Interview 7: QA manager, american male.

  • Relationship with the devs how I worked with them.
  • Experience with automation
  • Agile process that was followed.
  • lead experiecen
  • Automation experience
  • offshore experience

(Hell now they all begin to sound the same)

Interview 8: Development manager : american: male

  • relationshi with the dev
  • interaction with product managers
  • Who set priority and severity
  • agile process followed.
  • offshore team experience
  • What did the test plan and the test cases contain
  • When no requirements, how did I know what to test.
  • What is usually contained in a bug report.

Whew you would think? Wait on for round 2!!

Round 2:

Interview 1: Product manger: chinese american.

1. mainly interaction with the product manager.

2. Experience with offshore teams.

3. Lack of documentation, how do I handle it?

4. How do I come up with test plans and testcases?

5. what is my relationship with developers.

6. How do I handle the flow with the offshore teams?. Who handles the execution and development of testcases?

7. What do I like about QA.

8. Why am I interested in XYZ company.

Iterview 2: developer : american

blah pretty much the same question.

Interview 3: product manager;

pretty much the same questions.

As you can see, after a while it felt like I was repeating myself, and got quite boring. i would pause inbetween and say ” did I just mention this”. I was dry and thirty after 6 hors of talks- mainly repeating my sentences. After a while, expecially the second round, it was easy to see what they wanted in a QA, and round 2 was basically used to address the role they expected off me.

What I liked about the interview:

I didn’t have to market myself persay, it was mainly them getting to know me and my working style, and me getting to know theirs-most were pretty honest when it came to anwering my questions.

What  I didn’t like.

I think when a team decides to interview a candidate, its good to discuss on what the team is planning to touch upon, to

1. Explore the candidate a bit more.

2. remove the monotony of the whole  process.

3. make it more efficient.

But it also felt like the focus of the company is not necessarily techinical skills, but more of the personality match between the employees, in which case it does become necessary for the key people on the team to meet the candiate. I was surprised that there was more emphasis on process than on technical skills. Hardly any technical questions at all. but, having said that, the role does not need a technical person as such, but more of a communication, test, lead kinda person.

I am tired just typing this out- at the end of the interview i was left feeling like i repeated myself a lot. I need a break before I type the post”what did I ask, and show i have”post. Night folks. or morning, whatever the case may  be.

 

 

 

 

 

 

 

 

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();
}
}