Sunday, January 29, 2012

Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.

I was facing the above error when I was trying to connect to a shared folder, googled it a lot, with no luck, as there are lots of results but are not related. I was able to access this resource before and then suddenly I was receiving this error

“Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again”

until I found this post here http://travisepperson.blogspot.com/2007/01/windows-network-folder-specified-is.html

I tried the solution in and it worked

I opened command prompt “cmd”

I entered “net use” command, a list was displayed for me, one of them was on the same server of the shared resource I am trying to access

I entered “net use /delete [resource name]”

image

Then I was able to access the resource normally

Sunday, January 22, 2012

Visual Studio Web Test: Generating Random unique parameters at runtime

I had a scenario that requires several fields to be unique, and I wanted to have a web test for this scenario. I had the problem of generating these unique parameters to be unique

The first naïve solution I used is to create these unique values using excel and then saving in csv file. Then in my scenario, I set the parameter to a data source from this csv file. But this required me every time I run the scenario to remove the values that are used

Second trial for me, I converted the recorded web test to a coded test, this allowed me to to change the parameters programmatically and also gave me lots of flexibility on the test, on the other hand I lost the usability and flexibility of the web test designer, where I can record more to these test, extract parameters easily, etc..

In the coded test, I was looking for the request that has the parameters that needs to be unique, then I created a function to create a 10 digits random number and returns this as string, like below

public string generateRandomId()
{
    Random rand = new Random();
    string[] random = new string[10];
    for (int i = 0; i < 10; i++)
    {
        random[i] = rand.Next(0, 9).ToString();
    }
    return string.Join("",random);
}

Then at the request parameter setting, I changed from

request8Body.FormPostParameters.Add("Form1:referenceNumberText", "12341212323");

to

request8Body.FormPostParameters.Add("Form1:referenceNumberText", generateRandomId());

Third trial which is the best as believe, I created a web test plugin to set a context parameter at the beginning of the test

First I created a context parameter, by doing right click on the web test, then selecting Add Context Parameter

image

Then I renamed this parameter to RandomText

image

Then following the instructions here, http://msdn.microsoft.com/en-US/library/ms243191(v=vs.80).aspx  I created a new project in my solution, and added a new class, called it WebTestPlugin.cs

Added reference to Microsoft.VisualStudio.QualityTools.WebTestFramework and added the following line at the top

using Microsoft.VisualStudio.TestTools.WebTesting;

Then Changed the class name and inherited from WebTestPlugin, the code looked like below

public class webTestPlugin : WebTestPlugin
{
    string randomTxt;
    public override void PreWebTest(object sender, PreWebTestEventArgs e)
    {
        randomTxt = generateRandomId();
        e.WebTest.Context["RandomText"] = randomTxt;
        base.PreWebTest(sender, e);
    }

public string generateRandomId()
{
    Random rand = new Random();
    string[] random = new string[10];
    for (int i = 0; i < 10; i++)
    {
        random[i] = rand.Next(0, 9).ToString();
    }
    return string.Join("",random);
}

}

Then I went to my web test project, added a reference to my plugin project

image

Then added the plugin to my web test

image

by doing the above, I had the flexibility of web test designer, and the flexibility of writing my own code in the web test

Monday, January 16, 2012

Visual Studio Web Test: Excluding resources that are failing the test

I had a recorded scenario that when running back, one resource was giving 404 error, and because of that the test was failing

this resource was not important, it was just a css file, I looked on how to exclude such non-important resources from the test, I found some useful information here http://blogs.msdn.com/b/densto/archive/2007/06/27/webtestrequest-dependentrequests-collection.aspx

so first I converted my test to web coded test, then I looked for the request that was causing the problem, then I added this line before the yeld command for the request

request4.PostRequest += new EventHandler<PostRequestEventArgs>(request4_PostRequest);

Then added the request4_PostRequest implementation at the end

void request4_PostRequest(object sender, PostRequestEventArgs e)
{
    List<WebTestRequest> remove = new List<WebTestRequest>();
    foreach (WebTestRequest dependent in e.Request.DependentRequests)
    {
        if (dependent.Url.EndsWith("template.css"))
        {
            remove.Add(dependent);
        }
    }

    foreach (WebTestRequest dependent in remove)
    {
        e.Request.DependentRequests.Remove(dependent);
    }
}

Doing the above, I am able to run the test and getting pass as a final result

Another easier way I found later from Ed Glas post http://blogs.msdn.com/b/edglas/archive/2008/08/06/masking-a-404-error-in-a-dependent-request.aspx

This way can be done on the recorded scenario directly without converting to coded test

Sunday, January 15, 2012

Visual Studio Web test, creating extraction rule

I was creating a web test for a flow, with several forms, I had an ID that I wanted to use later in other requests, that wasn’t detected by the Visual studio parameter automatic linking.

The easiest way to do that

1- I did a run for the recorded scenario

2- I searched for the request that was displaying the ID on the screen

3- I went to the Response tab, where I can see the response html

image

4- I looked for the ID that I need to extract

5- Select the text that you want to extract, then do a right click and select Add Extraction Rule

image

After doing so, the web test will be opened and a confirmation will be displayed showing the rule name

image

image

 

If the required text is at the beginning of the line, you might need to add “\n” at the end of the “Starts with”

Tuesday, December 20, 2011

Getting Combinations in c++

we had programming exercise and I needed to put a function to return K combinations from N numbers starting from 1
So for example of N = 10, K = 3
I would have combinations starting from
1,2,3 - 1,2,4 – 1,2,5 – 1,2,6 – … and so on  till 8,9,10
I found some function to do this in c# here
http://stackoverflow.com/questions/548402/list-all-possible-combinations-of-k-integers-between-1-n-n-choose-k
I took the same algorithm and wrote it in c++ using vectors
below is the 2 functions I used, getCombinations will return the combinations vector
vector<vector<int> > getCombinations(int n, int k)
{
    // define variales
    vector<vector<int> > combincations;
    vector<int> row;
    for(int i=0;i<k; i++)
    {
        row.push_back(0);
    }
    row[0] = 1;
    // call the iterate function
    iterate(0,combincations,row,n,k);
    return combincations;
}
void iterate(int i, vector<vector<int> > &c, vector<int> &row, int n, int k )
{
    /// i represents the current index in the row vector that is used to fill the c matrix with combinations
    // set the i term to previous term +1
    if(i>0)
    {
        row[i] = row[i-1] +1;
    }
    //for loop to increment the current cell in the row till it reachs n-k+i+1
    // we are using n-k+i because we want to reach different values depending on the index
    // for example in N = 10, k = 3, first cell will increase till 8, second till 9, third till 10
    // so the last combination is 8,9,10
    for(;row[i] <= (n - k + i + 1);row[i]++)
    {
        // if this is not the last index, call iterate with next index
        // else fill in the combinations matrix
        if (i < k - 1)
        {
            iterate(i + 1, c, row, n, k);
        }
        else
        {
            vector<int> combination = row; //copying the row content
            c.push_back(combination); // adding the row to combinations vector
        }
    }
}

Wednesday, December 7, 2011

testlink: setting up MySQL Daily backup job

We wanted to keep our data safe, so we started taking backups using phpmyadmin, and because of forgetting sometimes, we thought of automating the backup

After doing some search, using the information from this page http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

I created a batch file, called DailyBackup.bat for example

and wrote the below in the batch file

@ECHO OFF
for /f "tokens=1-4 delims=/ " %%a in ('date/t') do (
set dw=%%a
set mm=%%b
set dd=%%c
set yy=%%d
)

SET bkupdir="path to backup folder"
SET mysqldir="C:\Program Files (x86)\EasyPHP5.3.0\mysql"
SET dbname=testlink

SET dbuser=username

SET password=password

set zip="C:\Program Files (x86)\GnuWin32\bin\gzip.exe"
@ECHO Beginning backup of %dbname%...

%mysqldir%\bin\mysqldump -B %dbname% -u %dbuser% –p%password% | %zip% > %bkupdir%\dbBkup_%dbname%_%dd%%mm%%dw%.sql.gzip

The above batch file needs gzip to be installed

Then I created a scheduled task that runs daily and executes the above batch file

Monday, November 21, 2011

Upgrading testlink, changed test case formatting in exported document when exporting test cases

We had testlink 1.8.4 and we upgraded to 1.9.3, one of the differences we noted is that 1.9.3 test cases now have steps and when doing export for test cases, the test cases in the exported document looked different that we had exported before. we already exported one document with all test cases from 1.8.4 and did lots of changes. and we wanted to have 1.9.3 exported test cases looks the same

I started looking into the code, and found it in file \lib\functions\print.inc.php

    if ($tcInfo[$key] != '')
    {
        $code .= '<tr>' .
                 '<td><span class="label">' . $labels['step_number'] .':</span></td>' .
                 '<td><span class="label">' . $labels['step_actions'] .':</span></td>' .
                 '<td><span class="label">' . $labels['expected_results'] .':</span></td></tr>';
       
        $loop2do = count($tcInfo[$key]);
        for($ydx=0 ; $ydx < $loop2do; $ydx++)
        {
            $code .= '<tr>' .
                     '<td width="5">' .  $tcInfo[$key][$ydx]['step_number'] . '</td>' .
                     '<td>' .  $tcInfo[$key][$ydx]['actions'] . '</td>' .
                     '<td>' .  $tcInfo[$key][$ydx]['expected_results'] . '</td>' .
                     '</tr>';
        }

 

The above code created a table with a column for step number, column for step actions, column for step results, then there is a loop to create rows for each step. We wanted to get ride of step number column and have just one row for with one cell for step details, and another row for expected results, I have changed the code to be like below

    if ($tcInfo[$key] != '')
    {
        $loop2do = count($tcInfo[$key]);
        for($ydx=0 ; $ydx < $loop2do; $ydx++)
        {
            $code .= '<tr><td colspan="' .  $cfg['tableColspan'] . '"><span class="label">' . $labels['step_actions'] . ':</span><br />' .   $tcInfo[$key][$ydx]['actions'] . '</td></tr>' .
                     '<tr><td colspan="' .  $cfg['tableColspan'] . '"><span class="label">' . $labels['expected_results'] . ':</span><br />' .  $tcInfo[$key][$ydx]['expected_results'] . '</td></tr>';
        }

    }

This worked out great, now it looks exactly like test cases we had before

Testlink: Timeout Exception in reports after setting up integration with Bug tracking system

We are using testlink and already did setup for integration with bug tracking system that we are using, trac. While doing testing after this step we found out that some reports are not working and it is giving timeout exception

after digging into the code looking for why this is happening, I found out that there is some loop that is calling the bug tracking system for each bug attached to test case.

The function that is called to get the bug is called get_bugs_for_exec, found in exec.inc.php file

This function is not causing any problem when opening the test cases, it is listing the bugs and getting the bug data from bug tracking system without any problems

To workaround the error I am getting in the reports, I have created another function called get_bugs_for_exec_reports with the same implementation but instead of calling the bug interface to get bug details, I just commented this part and only displayed the bug number, this will be enough for the reports, then in reports files, I changed instead of calling get_bugs_for_exec, I am calling get_bugs_for_exec_reports

files where I have done this change

\lib\functions\results.class.php

\lib\results\resultsByStatus.php

\lib\results\resultsBugs.php

Function:

function get_bugs_for_exec_report(&$db,&$bug_interface,$execution_id)
{
    $tables['execution_bugs'] = DB_TABLE_PREFIX . 'execution_bugs';
    $tables['executions'] = DB_TABLE_PREFIX . 'executions';
    $tables['builds'] = DB_TABLE_PREFIX . 'builds';
   
    $bug_list=array();
    $sql = "SELECT execution_id,bug_id,builds.name AS build_name " .
        "FROM {$tables['execution_bugs']}, {$tables['executions']} executions, " .
        " {$tables['builds']} builds ".
        "WHERE execution_id={$execution_id} " .
        "AND   execution_id=executions.id " .
        "AND   executions.build_id=builds.id " .
        "ORDER BY builds.name,bug_id";
    $map = $db->get_recordset($sql);
   
    // BUGID 3440 - added is_object() check
    if( !is_null($map) && is_object($bug_interface))
    {     
        foreach($map as $elem)
        {
            $bug_list[$elem['bug_id']]['link_to_bts'] = $elem['bug_id'];#$bug_interface->buildViewBugLink($elem['bug_id'],GET_BUG_SUMMARY);
            $bug_list[$elem['bug_id']]['build_name'] = $elem['build_name'];
        }
    }   
    return($bug_list);
}

Wednesday, November 16, 2011

Disabling Symantec endpoint protection, Fixing copying to external drives problem

lately Symantec endpoint protection was installed in our company, it worked fine for my colleagues, but for me I wasn’t able to copy anything to external devices
so I started looking on how to disable it
I have tried lots of solutions and all didn't work
I tried normal uninstall, it required admin credentials, and the IT admin was on vacation ;)
I have tried Clean Whip tool, it didn’t uninstall endoint
I have tried disabling the services, I remember the services names, EAFRCliManager, Removel Storage Mgmt Service, Removal storage service
all methods didn’t work
Finally I started looking into the registry trying to find anything related
I was looking for hidden start up services and I found 2 services, named GeFilter, Geprotection
I have tried to change the startup type for these services, I wasn’t able to. I wasn’t able to do any changes for these services, I have tried lots of tricks to have full control over this keys to change them, none has worked.
I have noticed there is a key inside of them that is named VolumeInformation{SomeGuid}, I started looking with this Guid, and appeared that this guid is for my C drive
I wasn’t able to rename any of the keys before, but after my changes to have full control, I was able to, so I have renamed this key, removing the Guid part. then I restarted my PC
After restart still I wasn’t able to change values inside these services keys, also unable to delete. since I was able to rename, I tried renaming the services name, I was able to. after renaming, I tried deleting, I was able to
Finally I deleted both services, I look for other locations for the 2 words, GeFilter, GeProtection, deleted them all
Then I restarted my PC one more time, and voila, I was able to copy to external hard drives
To have full control over registry keys you can find more details here
http://www.mydigitallife.info/grant-read-write-full-control-permissions-on-registry-keys-fix-cannot-import-and-access-denied-error-in-regedit/