Tuesday, November 22, 2011

IDE Features
Menu Bar
The File menu allows you to create, open, and save test case and test suite files. The Edit menu allows copy, paste, delete, undo, and select all operations for editing the commands in your test case. The Options menu allows the changing of settings. You can set the timeout value for certain commands, add user-defined user extensions to the base set of Selenium commands, and specify the format (language) used when saving your test cases. The Help menu is the standard Firefox Help menu; only one item on this menu–UI-Element Documentation–pertains to Selenium-IDE.
Toolbar
The toolbar contains buttons for controlling the execution of your test cases, including a step feature for debugging your test cases. The right-most button, the one with the red-dot, is the record button.


Speed Control: controls how fast your test case runs.


Run All: Runs the entire test suite when a test suite with multiple test cases is loaded.

Run: Runs the currently selected test. When only a single test is loaded this button and the Run All button have the same effect.


Pause/Resume: Allows stopping and re-starting of a running test case.

Step: Allows you to “step” through a test case by running it one command at a time. Use for debugging test cases.

TestRunner Mode: Allows you to run the test case in a browser loaded with the Selenium-Core TestRunner. The TestRunner is not commonly used now and is likely to be deprecated. This button is for evaluating test cases for backwards compatibility with the TestRunner. Most users will probably not need this button.

Apply Rollup Rules: This advanced feature allows repetitive sequences of Selenium commands to be grouped into a single action. Detailed documentation on rollup rules can be found in the UI-Element Documentation on the Help menu.

Record: Records the user’s browser actions.
Test Case Pane
Your script is displayed in the test case pane. It has two tabs, one for displaying the command and their parameters in a readable “table” format.

Recording the first test case

This section walks through recording the first test case with Selenium IDE
• Make sure the Record button in the right end of the toolbar is switched on
• Open https://nightly.olat.unizh.ch/nightly/dmz/
• Enter 'administrator' and the corresponding password and click 'Login'
• This should result in something like this:


The first test case in Selenium IDE
• To rerun the test, click on one of the green Play buttons
A few things Gotchas here Currently, Selenium IDE sometimes has refresh problems and you don't see the recorded steps until you move the mouse into the command table
• Selenium sometimes has troubles catching keyboard input when Firefox does form-autocompletion.
• Sometimes Selenium records 'click' instead of 'clickAndWait' and rerunning fails because of this.
• Selenium-Recording is not always 100% automated - in fact there is quite a bit of manual effort involved and you can do it all manually in Selenium IDE as well. For example: you can easily type 'clickAndWait' in the command field and enter the target link in the target field yourself - instead of relying on the record mechanism
• You can set Breakpoints in Selenium IDE by right clicking on any line and selecting 'Toggle Breakpoint' [B]
• You can run single Selenium commands by double-clicking on a line
Given that you are on the right page, you can let Selenium visualize a UI-Element by clicking on the 'Find' button. It will let the element blink green for a while

Selenium Record and Playback
NOTE: Selenium IDE is used for recording the test case while Selenium RC executes the test. Since Selenium IDE supports only Mozilla Firefox browser, recording the test case cannot be performed in any other browser. For executing the tests Selenium RC supports most of the widely used browsers Internet Explorer, Firefox, Opera, Safari etc for the test case execution.
Check here for the complete list http://seleniumhq.org/about/platforms.html#browsers

Recoding with Selenium IDE
• Open Firefox Browser: View >Sidebar>select ‘Selenium’ ..Selenium IDE is displayed on the left side
• To record a test case (log into your Yahoo mail and logout), enter the url in the browser ‘http://www.mail.yahoo.com’, login using a username & password. Sign out
• All actions will be recorded in Selenium IDE screen. During recording, Selenium-IDE will automatically insert commands into your test case based on your actions. Typically, this will include:
-clicking a link - click or clickAndWait commands
-entering values - type command
-selecting options from a drop-down listbox - select command
-clicking checkboxes or radio buttons - click command



• The script has table view and source view. In the table view, select a command. Details of the command will be displayed.
• Click on source view- by default recoded in HTML format. The format can be changed in Options->Format.

Adding Verifications and Asserts in the Script
With Selenium-IDE recording, go to the browser displaying your test application and right click anywhere on the page. You will see a context menu showing verify and/or assert commands.
• Now, right-click the selected text. The context menu should give you a verifyTextPresent command and the suggested parameter should be the text itself.
• Try right-clicking an image, or a user control like a button or a checkbox. You may need to use ‘Show All Available Commands’ to see options other than verifyTextPresent. Once you select these other options, the more commonly used ones will show up on the primary context menu. For example, selecting verifyElementPresent for an image should later cause that command to be available on the primary context menu the next time you select an image and right-click.

Saving the test case

• In Selenium IDE click ‘Run’ button to execute the test in the browser to verify if the script is working as expected for re iteration
• Now File->Export As Java(TestNG) test case. (The other formats available are PHP, Python,C#,Ruby,Perl,Groovy).
• Savethe file as ‘yahoomail.java’ in the folder F:/selenium/projects/Yahoo/com/testscripts

Selenium Learning Lessons

Installing the Selenium IDE
Steps:-

1.Launch Mozilla Firefox
2.Go to google.co.in and type Selenium IDE and press enter
3.Select the Downloads url from search results
4.Click on the latest version of selenium IDE
5.Firefox will protect you from installing add-ons from unfamiliar locations, so you will need to click ‘Allow’ to proceed with the installation, as shown in the following screenshot.




When downloading from Firefox, you’ll be presented with the following window.






Select Install Now. The Firefox Add-ons window pops up, first showing a progress bar, and when the download is complete, displays the following.




Restart Firefox. After Firefox reboots you will find the Selenium-IDE listed under the Firefox Tools menu.




Opening the IDE
To run the Selenium-IDE, simply select it from the Firefox Tools menu. It opens as follows with an empty script-editing window and a menu for loading, or creating new test cases.




Configure the Olat Map file
We'll go into details about how the Olat Map file works later. Here's how to configure it in Selenium IDE
• Go to Options>Options...

Setting for the Olat Map file in Selenium IDE
• Configure the user-extensions.js file with one of the following paths:
o Copy the nightly generated user-extensions.js from http://nightly.olat.uzh.ch/nightly/raw/doc/user-extensions.js to a local file and configure that local file. Make sure to repeat this often to catch changes in the olat-ui-map!!!
o if you're doing modifications on the map file (see later), build it yourself and configure it, e.g.: C:\eclipse\workspace\seleniumtests\build\classes\user-extensions.js
• Enable 'Remmber base URL'
• Enable 'Record assertTitle automatically'
• Enable 'Record absolute URL'
• Enable 'Enable UI-Element' (important!)
• Restart Selenium IDE (not the whole browser, just Selenium IDE. Activates the UI-Elements)

Wednesday, December 16, 2009

GridView --Editing and Deleting



A more easy way of editing and deleting a record in a grid view can be done as shown below.
A record could be edited within the grid view correspondingly reflecting the change in database

Sql connection and grid Binding

public partial class _Default : System.Web.UI.Page

{
SqlConnection con = new SqlConnection(@"Data Source=KFJD-03843C5CB9\SQLEXPRESS;Initial Catalog=megha;Integrated Security=True");

public void gridbind()
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from neme", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
con.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gridbind();
}
}

Insertion:_-------------------

protected void btnsav_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into neme (name,age,quali) values ('" + tbname.Text + "','" + tbage.Text + "','"+tbquali.Text+"')", con);
cmd.ExecuteNonQuery();
Response.Write("inserted");
con.Close();
gridbind();

}



Grid view Row updating, Editing and row cancel editing event--------------

gridbind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow gr = GridView1.Rows[e.RowIndex];
Label lbl = (Label)gr.FindControl("lbchk");
TextBox tb = (TextBox)gr.FindControl("tblchk");
TextBox tb2=(TextBox)gr.FindControl("tblchk1");
TextBox tb3=(TextBox)gr.FindControl("tbqualiedit");
con.Open();
SqlCommand cmd = new SqlCommand("update neme set name='" + tb.Text + "',age='"+tb2.Text+"',quali='"+tb3.Text+"' where id='" + lbl.Text + "'", con);
cmd.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
gridbind();

}


protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
gridbind();

}


Deleting selected files-------------------------------

protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
gridbind();
}

protected void lnkdel_Click(object sender, EventArgs e)
{
foreach (GridViewRow gr in GridView1.Rows)
{

Label lbl = (Label)gr.FindControl("lbchk");
CheckBox ch = (CheckBox)gr.FindControl("chk");

if (ch.Checked)
{
con.Open();
SqlCommand cmd = new SqlCommand("delete from neme where id='" + lbl.Text + "'", con);
cmd.ExecuteNonQuery();
con.Close();
gridbind();

}

}
}

Thursday, December 10, 2009

Radio button and Checkbox samples in VB.NET


Display Button Code

Protected Sub btndisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btndisplay.Click
If (RadioButton.SelectedValue.ToString() = "Display") Then
If (chkMelody.Checked = True And chkclassical.Checked = True) Then
lblres.Text = chkMelody.Text & "and" & chkclassical.Text
Else

If (chkMelody.Checked = True) Then
lblres.Text = chkMelody.Text
Else
lblres.Text = chkclassical.Text


End If

End If
Else

lblres.Text = "Wrong Selection"

End If
End Sub

Adding items to listbox from textbox


Protected Sub btnadd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnadd.Click
If (tbitem.Text.ToString() = "") Then
Response.Write("No item to Add")
Else
listitem.Items.Add(tbitem.Text)
Response.Write("Item Added")

tbitem.Text = ""

End If

End Sub

Wednesday, December 9, 2009

C#.Net Windows Form Dialogs

OpenFileDialog


openFileDialog1.Filter = "Text Files*.txtWord documents*.doc";
openFileDialog1.FileName = "Select file";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
rtb1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
}


PrintDocument


private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
PrintDocument doc = new PrintDocument();
doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);
doc.Print();
}

void doc_PrintPage(object sender, PrintPageEventArgs e)
{
Font f = new Font("Arial", 18, FontStyle.Italic);
Font f2 = new Font("Tahoma", 14, FontStyle.Bold);
e.Graphics.DrawString("Document", f, Brushes.Brown, 25, 50);
e.Graphics.DrawString("'"+rtb1.Text+"'", f2, Brushes.Brown, 25, 50);
//throw new Exception("The method or operation is not implemented.");
}