if { ... } {
...
}
else {
...
}
To get ride of this error, put the "else" and the "if" ending brackets in the same line
if { ... } {
...
} else {
...
}
Here in this blog i am writing notes related to my work, sometimes i need to review something i did before, or i need to do it one more time. Also it might be helpful for anyone looking for an answer for situations similar to the ones i faced before
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();
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();
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();
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
While developing a selenium test and running it on IE, I was trying to locate an element on the page with xpath, selenium couldn’t find the element, I was getting exception: “NoSuchElementException: Unable to find element with xpath == ……”
I thought at the beginning that there is something wrong with my xpath string, and I kept looking into this for a while. I have installed FirePath plugin for Firefox to verify my xpath, and my xpath was working find, xpath could locate element
Finally I spotted something on selenium documentation under section “IE and Style Attributes” that says that if you are trying to locate an element with the style attribute, it might not work in internet explorer as IE interpret the style parameters in upper case differently that other browsers, so locating with style and lowercase will success in Firefox, Chrome, etc… but will fail in IE
looking back to my xpath, my element xpath was ".//*[@id='ajaxLoadingModalPanelContainer' and contains(@style,'display: none')]"
Changing it to ".//*[@id='ajaxLoadingModalPanelContainer' and contains(@style,DISPLAY: none')]" my test was able to find the element successfully
List<int> list= new List<int>();
int index = list.BinarySearch(i);
if (index < 0)
list.Insert(~index, i);
else
list.Insert(index, i);
public class DuplicateKeyComparer<TKey>:IComparer<TKey> where TKey : IComparable
{
public int Compare(TKey x, TKey y)
{
int result = x.CompareTo(y);
if (result == 0)
return 1; // Handle equality as being greater
return result;
}
}
From Firefox, record new selenium test, for example for Google search
Export the test to C# web drive
This is how it looks like after export
Open visual studio, create new test project
By default the file UnitTest1.cs is created
Create a new cs file, name it for example GoogleSearch
Copy the code from the cs file generated by selenium and paste it in the file GoogleSearch.cs
Add reference in the project to Selenium .Net WebDriver, WebDriver.dll and WebDriver.Support.dl
Now the references added, you can see that the editor recognizes the selenium name spaces
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
Find and replace “TestFixture” to “TestClass”, “SetUp” to “TestInitialize()”, “Test” to “TestMethod”, “TearDown” to “TestCleanup()”
To run with Chrome, download chromedriver.exe from https://code.google.com/p/chromedriver/downloads/list, place it in the bin folder
Change the driver in the code to Chrome then run the test
driver = new OpenQA.Selenium.Chrome.ChromeDriver();
Running the test, chrome will open, and Google search page will be displayed, displaying search results then closed
This was a step by step example on running selenium test from visual studio
I was doing testing on some records, and to be able to run the test again, the status of the record must be set to specific value
To be able to do that, I thought of doing this by trigger on the DB, but unfortunately, I was working on the client DB and I didn’t have access to create triggers
So I thought of doing that from jmeter, and it worked perfectly
First I added JDBC Connection Configuration as in the image below
Configured this as below
Variable Name: conn
(Variable name should be any name, that will be used later)
Database URL: jdbc:db2://127.0.0.1:50000/QAT_MOI_DB1T;
(Database URL is the JDBC URL for the database)
JDBC Driver class: com.ibm.db2.jcc.DB2Driver
(Make sure to place the drivers in the lib directory inside jmeter directory. you will need to restart your jmeter to for them to work correctly, in my case I was working with DB2 database, so I copied the files db2jcc.jar and db2jcc_license_cisuz.jar to the lib directory)
Username: user
Password: password
Then I added JDBC PostProcessor at the first request in the script
Configured it,
Variable Name: conn
(variable name is same as above in the configuration element)
Query Type: update statement
Query: update records set status=1 where id=${id};
I was able to insert parameters in the query same way I do in the requests
By this way I was able to reset the data before every cycle
You can also add JDBC PostProcessor at the last request, to do some other post processing
I have been using jmeter for a while with spring webflow application, I have some experience with it now that I would to share
Studying the recording of spring webflow application, I noticed the following
There are requests that doesn’t have anything inside, that are followed by requests with execution parameter as in the images below
Request without any parameters, let’s call them initial requests
Request with the “execution” parameter, let’s call them execution requests
Or it could be request with execution parameter in the query string, and the view state parameter, execution in query requests
To be able to replay the scenario, with multiple iterations, and multiple users, the execution parameters and view state needs to be parameterized, to be extracted and used in next requests to maintain the execution flow correctly
I found out by trials and from the results from the results tree, that initial requests are followed by sub samples that contains the execution parameter for the consequences request
Also found out that new execution is generated at the end of execution in query requests
But there was a difference in the extraction of the execution parameter in that case, it comes in the body
So for my scenario, in order to work correctly, I added 2 types of extraction rules
One after initial requests, that checks the sub sample URL only with the below settings
Apply To: Sub-samples only
Response Field to Check: URL
Regular Expression: execution=(.+?)$
Another one at the end of each request with execution in the query string, with the below settings
Apply To: Main sample only
Response Field to Check: Body
Regular Expression: execution=([^"]+)"
Then in consecutive requests, replace the execution parameter with the extracted parameter, in my case here I named it ${e3s2}
I had a WCF client for a web service, it was working fine from my machine, when I deployed my application to other machines, I was getting the below exception
System.MissingMethodException: Method not found: 'Void System.ServiceModel.Channels.SecurityBindingElement.set_AllowInsecureTransport(Boolean)'.
When I searched online I found out that this could happen when .NET framework is not installed. I tried installing .NET framework 3.5 SP1 on these machines, but it was always failing since this machines OS is windows 7, and I was getting error that I should use “Turn windows features on or off” to install .NET framework 3.5, which was already installed by this way
I searched more, and I found out that there is hot fix for WCF that adds AllowInsecureTransport property to the SecurityBindingElement class, and i was using this on my WCF client
I found couple of updates for .NET framework 3.5 SP1, non of them installed successfully, there were errors in setup, either product not found, or things like this
Finally I found one that I was able to install from the link below
http://support.microsoft.com/kb/976462/en-us
I downloaded the x86 file Windows6.1-KB976462-v2-x86.msu from https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=23806 , installed it on the machines, then the application worked without any exceptions
While executing sql command in IBM db2 control center editor, I was getting error
SQL0332N Character conversion from the source code page "" to the target code page "" is not supported. SQLSTATE=57017
Searching for this, I found that I need t change the code page of the client to be the same as the table I am selecting from
To do this:
Open a command prompt
Go to C:\Program Files\IBM\SQLLIB\BIN\ or just make sure it exists in the windows %PATH%
Type db2set db2codepage=1208 then press enter
In my case the target codepage was 1208, it needs to be checked first before setting it