Locating UI Elements–which to use

To locate an element we can use

the element’s ID

the element’s name attribute

an XPath statement

by a links text

document object model (DOM)

In practice, you will discover

id and name are often the easiest and sure way.

xpath are often brittle. for example you have 3 tables displayed but sometimes there are no data and the table isn’t rendered, your xpath locating the second table will not always return the intented one.

css are the way to go in conjunction of id and name !

locating links in an internationalized application is sometimes hard… try to use partial href.

Coded UI with Action Based Test Automation

A good video which gives a great overview of using Coded UI along with Action based test automation.

Automated JS testing - 2

Now that we are here - Lets look at some interchangeable frameworks for JS testing and also see how we can translate the unit testing to an end to end testing

Example of JS unit testing framework - Used to test jQuery, JQuery UI and jQuery Mobile . QUnit can be used easily and also it can be used to test any generic js code itself . A Sample test is written below. You can use the cookbook to enhance your knowledge further 

test(“a test example”, function(){

ok( true, “this test passes”);

var value = “hello"

equal (value, “hello”, “We expect value to be hello”);

});

My top metrics

Having seen the product side and the service side of the industry and in my view, these are the top metrics that i keep track of. Definitely builds to my dashboard

Metrics

 

Automated Web Testing using Java Script - 1

I think, i have used this way to often and pleasantly surprised when i hear ppl mention - What? You can use JS for automation? Some even think i am crazy. But that’s ok. What purpose does it solve for me anyways!

Here, i intend to start a series of my experience and rants on using JS for automation . Before that, for the benefit of folks, let me list why JS for Testing ? 

  • It is Free 
  • It is open source
  • It is modular
  • It has an active and vibrant community
  • If the client and servers use JS - why not tests?

Append a text file in selenium

Here is a little code I wrote for appending a text file in selenium

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Pattern;

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

    @Test
    public void testUntitled() throws Exception {
        selenium.open("www.google.com");
        String filepath = "D:/FindMeHere2.txt" ;
        FileWriter somenewfile = CreateTxtFile(filepath);
       
        AppendTextToFile(filepath, "here is how i would append the text");
       
    }

/*    @After
    public void tearDown() throws Exception {
        selenium.stop();
    }*/
   
        public FileWriter CreateTxtFile(String fpath) throws IOException {
        System.out.println("Inside the Create Text File method :::: ");
        //String fpath = "d:/mynewtextfile.txt";
        FileWriter mynewfile = new FileWriter(fpath, false);
        //FileOutputStream fout = new FileOutputStream(fpath);
        mynewfile.write("This is a new text file , that i wrote  into ");
        mynewfile.close();
        return mynewfile ;
       
    }
       
        public void AppendTextToFile(String filepath, String testtext) throws IOException {
            System.out.println("Inside the Append Text  to File method :::: ");
        //FileOutputStream fout = new FileOutputStream(fpath);
              FileWriter fstream = new FileWriter(filepath,true);
              BufferedWriter out = new BufferedWriter(fstream);
              out.newLine();
              out.write(testtext);
              //Close the output stream
              out.close();
           
        }
}

Hope this helps

www.CodeNirvana.in

Powered by Blogger.

Translate

Total Pageviews

Copyright © T R I A G E D T E S T E R