Showing posts with label Sample. Show all posts
Showing posts with label Sample. Show all posts

3/06/2012

Add more configuration items to the configs.csv

By default, SelDotNet only get default setting values for


  • Language
  • Browser
  • Base Url
  • Timeout
  • Connection String
  • Auto Capture Screenshot
  • Default Username
  • Default Password

If you want to get more settings from configs.csv file, please follow these following steps.
  1. Add as many property/value as to the configs.csv file.
    Example: Project Name, SelDotNet Implementation
  2. In the Entry Point Class that inherits from BaseTest Project, Override the virtual method
        const string PROJECT_NAME ="Project Name";
        protected override void DoLoadCustomConfigs(Configuration conf)
        {
            Engine.Configs.AddProperty(
                PROJECT_NAME, 
                conf.GetProperty(PROJECT_NAME)
                );
        } 
    
  3. Later, everytime you want to get this value, just  call
        Engine.Configs.GetProperty(TheProject.PROJECT_NAME);
    

Flexible selecting item for listbox and radio group

For listbox and radio group, SelDotNet has implemented some useful methods, such as:
SelectByValue(value);
SelectByIndex(index);
SelectByText(text);
SelectFirstItem();
SelectLastItem();
AutoSelect();
Actually, it is not the most useful. Since, sometime you have to write much code like this.

if (testcase==AUTOSELECT_JOBTITLE)
jobTitle = Listbox("JobTitle").AutoSelect();
else
jobTitle = Listbox("JobTitle").SelectByText(aJobTitle);
to avoid this much waste of time, SelDotNet provide an alternative solution. By that, you just assign to jobTitle one of these value:
Listbox.FIRST_ITEM
Listbox.LAST_ITEM
Listbox.RANDOM_ITEM
Listbox.SELECT_NOTHING
Listbox.ITEM_INDEX + anumber

Example
void MakeTestData(TestCase testcase){
    MemberInfo member = MemberInfo.MakeStandardTestData();
    switch(testcase){

    case: EMPTY_JOBTILE:
         member.JobTitle =  Listbox.SELECT_NOTHING; 
    break;
    }
}

void SubmitData(MemberInfo member){
     ...
     //We dont need branching here
      Listbox("JobTitle Listbox").SelectByText(member.JobTitle);
      ...
}

3/05/2012

A New Approach with SelDotNet

As mentioned in the earliest version of SelDotNet, user is suggested to create a page class for each page under test. Obviously, this approach is clearly and easy to maintain.

TRADITIONAL APPROACH

class LoginPage : BasePage{
   public LoginPage(IWebDriver browser):base(browser){
      LoadMap(" mapping file");
   }
   public void Action1(){}
   public void Action2(){}
   public void CheckTheResult(){}
}

class TFxxx_LoginTest: BaseTestFixture{

    [Test]
    public void ATest(){
       LoginPage page = new LoginPage( StartBrowser());
       page.Action1();
       page.Action2();
       page.CheckTheResult();
       page.Close();                   
   }
}
However, SelDotNet also supports an alternative approach, that is like the QTP's style. The script should be like this
class TFxxx_LoginTest: BaseTestFixture{
   
   ProjectBasePage page= null;

   public override void  DoFixtureSetUp()
        {            
            page =  new ProjectBasePage(StartBrowser());
            page.LoadMap("A gui map file");
        }

   [Test]
    public void ATest(){
       page.Editbox("Username").Set("username");               
       page.Editbox("Password").SetSecure("@#$%^&*()_");
       page.Button("Submit").Click();
       page.AssertContainText("Welcome to the system");
   }
}
With this new approach, we don't need to create a class for every page under test. Depending on your situation, then you should select an appropriated approach. Good luck!

2/22/2012

Make Test Data Secured

/// Loads test db:
        /// 1. Gets query string from sheet "AdminLogin"
        /// 2. Executes that query
        /// 3. Return the db
        private string[][] TestData_AdminLogin()
        {
            string sql="select top 2 username, password from tblAdmin";
            //Make the column #2 as secured data
            return MakeSecureTestData(LoadTestData_ExecSQL(sql),1);//0-based column.
        }        

        /// 
        /// Action: Login as admin        
        /// Condition: correct username, newPassword        
        /// Expected: show admin menu after logged
        /// Post-condition: logout and close browser
        /// 
        /// 

correct username
        /// 

correct newPassword
        [TestCaseSource("TestData_AdminLogin")] 
        public void TC01_AdminLogin_WithCorrectCredential_ShowAdminMenu(string username, string password)
        {                   
            homePage.SubmitLoginForm(username, password,true);
            homePage.Dispose();
            AdminBasePage adminPage = new AdminBasePage(homePage.GetBrowser());
            adminPage.AssertIsLoaded();
            adminPage.Logout();
            adminPage.Close();
        }