Wednesday, December 17, 2014

Windows 8 apps opening problem

On my work PC i had this issue, domain account on windows 8, and whenever i tried to open any of windows 8 apps, it is opened and disappears and the window is not displayed.
When i searched i found lots of articles taking about windows apps issues, but all didn't help. I found helpful articles when i searched with the error i found in event viewer like:


Activation of app windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel failed with error: This app does not support the contract specified or is not installed. See the Microsoft-Windows-TWinUI/Operational log for additional information.

I found the solution in couple of articles

I can't open any Windows 8 apps including PC Settings and Store
Fix Windows 8.1 Cannot Launch “PC Settings” or “Store” Problem

Running the below commands solved the problem

powershell -ExecutionPolicy Unrestricted Add-AppxPackage -DisableDevelopmentMode -Register $Env:SystemRoot\camera\AppxManifest.xml
powershell -ExecutionPolicy Unrestricted Add-AppxPackage -DisableDevelopmentMode -Register $Env:SystemRoot\FileManager\AppxManifest.xml
powershell -ExecutionPolicy Unrestricted Add-AppxPackage -DisableDevelopmentMode -Register $Env:SystemRoot\ImmersiveControlPanel\AppxManifest.xml

Monday, October 20, 2014

Enabling remote desktop on remote computer

I went home and forgot to enable remote desktop on my PC at my office, luckily i found couple of articles that is talking about enabling remote desktop remotely.

I followed the steps from  here and did a restart for the remote machine, but it didn't work, then i figured that since i did it through registry, firewall rules wasn't updated to allow it, while if i enabled remote desktop connections through the UI, it is updated automatically.

I found another article that has the same steps plus updating the firewall to enable remote desktop connections with a command line that is executed remotely. Another article for opening the firewall for remote desktop connections from command line.

The only thing that i have done extra is that i started the elevated command prompt for "psexec", the normal one didn't do the job.

Brief of the steps:
1- From the registry, connect to the remote computer
2- Change the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\fDenyTSConnections from 1 to 0
3- Restart the remote machine by shutdown -m \\MachineName -r
4- Update the firewall rules on the remote machine by downloading psexec and running the below from elevated command prompt
psexec \\remote_machine_name cmd
Then after it connects
netsh advfirewall firewall set rule group=”remote desktop” new enable=Yes

Thursday, June 26, 2014

.NET C#: Running command line in CMD and waiting for it to finish

I had a script that i should call with command line interface, then other tasks that should be done after that.
I used the Process and ProcessStartInfo as below, but the problem i had is that the script was taking some time, and the program execution was failing after that since the script is not finished yet.

            using (Process process = new Process())
            {
                var startInfo = new ProcessStartInfo("cmd")
                {
                    RedirectStandardInput = true,
                    RedirectStandardOutput = true,
                    WindowStyle = ProcessWindowStyle.Normal,
                    UseShellExecute = false,
                    CreateNoWindow = false
                };

                process.StartInfo = startInfo;
                process.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);
                process.Start();
                process.StandardInput.Write("script"+ process.StandardInput.NewLine);
                process.Close();
            }

I wanted to make sure that the program execution waits till the script finishes.So instead of using Close method, i added WaitForExit, and i am manually sending exit command to the command line after the script finishes, like below

            using (Process process = new Process())
            {
                var startInfo = new ProcessStartInfo("cmd")
                {
                    RedirectStandardInput = true,
                    RedirectStandardOutput = true,
                    WindowStyle = ProcessWindowStyle.Normal,
                    UseShellExecute = false,
                    CreateNoWindow = false
                };

                process.StartInfo = startInfo;
                process.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);
                process.Start();
                process.StandardInput.Write("script"+ process.StandardInput.NewLine);
                process.StandardInput.Write("exit" + process.StandardInput.NewLine);
                process.WaitForExit();
            }

This worked for me and the program execution waited till the script finishes.

Wednesday, June 18, 2014

Clicking problems with IE and Selenium

We were facing couple of problems with selenium tests running on IE, when running the tests locally, we don't have these issues. After adding more logs to the code, i found that sometimes it is failing after sending the click event in different steps. 
Looking online for similar issue, i found that there are clicking issues with IE, as sometimes the element being clicked on will receive the focus, but the click will not be processed by the element.
https://code.google.com/p/selenium/wiki/InternetExplorerDriver#Browser_Focus

To workaround this, i am setting the focus manually to the browser using the below line of code

Driver.SwitchTo().Window(Driver.CurrentWindowHandle);

Sunday, December 22, 2013

tcl: dumping tablelist data

For the tablelist widget I created a function to dump the table content to a file

proc dumpTableListToFile { tree { file preview.txt } } { 
set rowCount [$tree size]
set file_writer [open $file w+]
for { set i 0 } { $i < $rowCount } { incr i } {
set rowData [$tree get $i]
puts $file_writer $rowData
}
close $file_writer
}


parameters:



tree, is the table widget, file is the file name, optional.

Monday, December 16, 2013

tcl: find widget recursively

I was doing some testing for multi container application, and same widget could exist in different containers and could have variable parent name, I created a function to find the widget recursively by the last portion of the widget name
The function I initially created
   1: proc findWidgetByName { wname {widget .mainwindow} } {    
   2:     set pattern "*.${wname}" 
   3:     #puts $widget    
   4:     set all "[winfo children $widget]" 
   5:     foreach child $all  { 
   6:         #puts "$child" 
   7:         if { [winfo viewable $child] && [string match $pattern $child] } { 
   8:                 #puts $child 
   9:                 return $child            
  10:         } else { 
  11:             return [findWidgetByName $wname $child]        
  12:         } 
  13:     } 
  14:     return 0 
  15: }

Testing the above function, it was taking the first child in each “for loop” and returning without checking other childs, with the help of my colleague, we changed it to working version

   1: proc findWidgetByName { wname {widget .mainwindow} } {    
   2:     set pattern "*.${wname}" 
   3:     #puts $widget    
   4:     set all "[winfo children $widget]" 
   5:     foreach child $all  { 
   6:         #puts "$child" 
   7:         if { [winfo viewable $child] && [string match $pattern $child] } { 
   8:                 #puts $child 
   9:                 return $child            
  10:         } else { 
  11:             set x [findWidgetByName $wname $child]        
  12:             if {  $x !=0 } { 
  13:             return $x ;            
  14:             } 
  15:         } 
  16:     } 
  17:     return 0 
  18: }

When using for loops with recursion we need to put some condition when to break the for loop execution
I have created also another version to find widgets by label, in case of buttons or labels

   1: proc findWidgetByLabel { label {widget .mainwindow} } {       
   2: set all "[winfo children $widget]"
   3:     foreach child $all  {
   4:         #puts "$child"
   5:         if {([winfo class $child]== "Label" || [winfo class $child]== "Button" ) && [winfo viewable $child] && [$child cget -text]==$label } {
   6:                 #puts $child
   7:                 return $child            
   8:         } else {
   9:             set x [findWidgetByLabel $label $child]        
  10:             if {  $x !=0 } {
  11:                 return $x ;            
  12:             }
  13:         }
  14:     }
  15:     return 0
  16: }

Same can be applied to find widget by any property

Friday, December 13, 2013

Extracting tcl treeview items

I wanted to validate treeview items after doing operations on them, like add, delete. I created 2 function to extract the items and dump into a file, next i was able to compare the extracted file with the expected values

#this function dumps the 1st level in the tree to a file
proc dumpTreeDataTags { file } {
global treeControl
    set file_writer [open $file  w+]
foreach id [$treeControl item children root] {
   set data [$treeControl item tag names $id]
   puts $file_writer $data
}
    close $file_writer
}

#this function dumps all the tree data, file is appended. File must be cleared before calling this function
proc dumpAllTreeDataTags { file { item root} } {
    global treeControl
foreach id [$treeControl item children $item] {
   set file_writer [open $file  a+]
   set data [$treeControl item tag names $id]
   puts $file_writer $data
   close $file_writer
   dumpAllTreeDataTags $file $id
}
}

Explaining the functions:
The first one, i am extracting the first level only, and saving to the file, the file is opened in write mode, and replaced every time the function is called.
The second function is using recursion to iterate starting from the root node, through the children, and then calling the function again for each children, and so on. File is opened in append mode, so that when called in recursion, the previous data written to the file is not lost

Sunday, November 10, 2013

TCL: invalid command name "else"

If you are used to traditional if-else and wrote "else" in separate line in TCL like below

if { ... } {
...
}
else {
...
}

You will get an error like me: invalid command name "else"

To get ride of this error, put the "else" and the "if" ending brackets in the same line

if { ... } {
...
} else {
...
}

Monday, August 5, 2013

.NET: Deserialize error while parsing the XML

I was running some Serialize and Deserialize code  online, on hackerrank , I was getting several XML parsing when calling Deserialize
The code I was using
string fileName = "file.txt";
System.Xml.Serialization.XmlSerializer s =
    new System.Xml.Serialization.XmlSerializer(typeof(myObject));

System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName, true);
s.Serialize(sw, myObject);
sw.Close();
I was getting the below error

Unhandled Exception: System.Xml.XmlException: XML declaration cannot appear in this state

I did some search and found people talking about encoding problems, and I found some articles guiding to change the encoding, using XmlWriter instead of StreamWriter, I changed my code to below to see if this will impact my error.

System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
settings.Encoding = new System.Text.UnicodeEncoding(false, false);
settings.Indent = true;

string fileName = "file.txt";
System.Xml.Serialization.XmlSerializer s = new System.Xml.Serialization.XmlSerializer(typeof(myObject));
System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(fileName, settings);
s.Serialize(xw, myObject);
xw.Close();
Error then changed, this gave me the below error

Unhandled Exception: System.Xml.XmlException: a name did not start with a legal character

Which means that the name was invalid, so I changed the encoding to be Ascii,  ASCIIEncoding

System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
settings.Encoding = new System.Text.ASCIIEncoding();
settings.Indent = true;
System.Xml.Serialization.XmlSerializer s = new System.Xml.Serialization.XmlSerializer(typeof(mybject));
System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create("filename", settings);
s.Serialize(xw, myObject);
file.Close();
The last code run successfully, and I was able to write and read the file

Monday, June 17, 2013

Selenium: Dealing with HTML loading modal panel

While playing back a test for a java rich faces application, the test was failing in the middle, debugging and playing back step by step, the test was passing with no issues. Looking more into the steps, there was a step that is causing ajax call, and after it there is a button click step, the one that was failing was the next one after the button click. When I checked the screen, there was a loading panel displayed during the ajax call, freezing all the screen, so I figured out that when this loading panel is displayed, selenium was able to find the button and click on it, but it is not actually clicked on the UI of the application, which cause that next step after to fail.

To resolve this, first I tried to look for something to make sure the button is clickable, I found something but for Java, and doesn’t exist for .NET

wait.until(elementToBeClickable(By.partialLinkText("SomeID")));

My test was on IE, and when I tried it with java, I had problems creating the selenium session with the selenium IE server.

Then I thought of something else, to identify any element change in the page that tells that the ajax call is done, then I can use this before the button click, to make sure it is clickable. I looked into the html page before, during and after the ajax call and compared. Before the call and when the loading panel was not visible, I found  hidden div with ID ajaxLoadingModalPanelContainer, it looked like below

<div id="ajaxLoadingModalPanelContainer" class="rich-modalpanel " style="position: absolute; z-index: 100; background-color: inherit; display: none;">

when the loading panel was visible, there was a div in the body like below (same as above, but the display style is gone)

<div id="ajaxLoadingModalPanelContainer" class="rich-modalpanel " style="position: absolute; z-index: 100; background-color: inherit;">

After the ajax call, the loading panel disappears and it changes back to have “display:none”

<div id="ajaxLoadingModalPanelContainer" class="rich-modalpanel " style="position: absolute; z-index: 100; background-color: inherit; display: none;">

I then created a function to wait for the ajaxLoadingModalPanelContainer div to be displayed, then to wait until it is hidden again like below

public void WaitForModalPanel()
{
string element_xpath = ".//*[@id='ajaxLoadingModalPanelContainer' and not(contains(@style,'display: none'))]";
WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 2, 0));
wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(element_xpath)));
element_xpath = ".//*[@id='ajaxLoadingModalPanelContainer' and contains(@style,'DISPLAY: none')]";
wait.Until(ExpectedConditions.ElementExists(By.XPath(element_xpath)));
}


Calling the above function before the button click, the button click was also clicked on the UI and the test was passing successfully