I'm working on Fitnesse Test Project with C# and Slim.
I'm trying to pass Url address as a parameter to the ColumnFixture.
Url address should be the same for all test cases so I decided to use !define keyword to define my url. In Fitnesse test I have:
!define webServiceUrl {http://mytestserver.address.svc}
|!-MyNamespace.SearchClientFixture-! |
|webServiceUrl |contactPhoneNumber|contactId?|identificationResult?|
|${webServiceUrl}|922222222 |0 |notfound |
|${webServiceUrl}| |0 |notfound |
${webServiceUrl} is rendered as HTML anchor tag and the value passed to my ColumnFixture class is also HTML anchor markup
http://mytestserver.address.svc
I tried to escape HTML with !<text>! and !- fitnesse tags but it doesn't work.
My questions are:
1. How to escape HTML in my case?
2. How to pass single value to ColumnFixture shared among all test cases? Is it possible to send value to the SetUp method?
Did you try putting the ! before the first line in the table. That is supposed to turn off wiki rendering for the whole table.
!|MyNamespace.SearchClientFixture |
|webServiceUrl |contactPhoneNumber|contactId?|identificationResult?|
|${webServiceUrl}|922222222 |0 |notfound |
|${webServiceUrl}| |0 |notfound |
This has worked for me and all of my projects. Only trouble is when you want actual wiki markup in the table (such as !today).
Related
I have a table in which I save an ID and a rule like:
| ID | Rule |
|------|--------------------------------------|
| 1 | firstname[0]+'.'+lastname+'#'+domain |
| 2 | firstname+'_'+lastname+'#'+domain |
| 3 | lastname[0]+firstname+'#'+domain |
My problem is: How can I get and analyze/execute that rule in my code? Because the cell is taken as a string and I don't know how to apply that rule to my variables or my code.
I was thinking about String.Format, but I don't know how to split a string taking just the first character with it.
If you could give me an advice or any better way to do this, I'd appreciate that because I'm completely lost.
If that is C#, you could construct a LINQ Expression out of the parse tree from for example ANTLR, or if the format is very simple, regex.
You have to make these steps:
Evaluate the incoming string using ANTLR. You could start off with the C# grammar;
Build an expression from it;
Run the expression giving the firstname, domain, etc. parameters.
Not sure that would do the trick, but you might want to look at CSharpCodeProvier. Never used it, but according to the examples, it seems to be capable of compiling code entered in a textbox.
The thing is that this solution generates an exe file that will be stored in your project folder. Even if you delete them after a successful compiling, that might not be the best option.
I'm doing an basic CSV import/export in C#. Most of it is really simple and basic, we just have one speciality.
In values we import/export, we have some specials values, which are not ASCII values. To ease the work of our end users, the customer decided to convert some values in some other values and do the opposite when importing.
Some examples
Value in our application | ValueS that must be accepted on parsing
-----------------------------------------------------------------------
³ | 3, ^3, **3
μ | u
₃ | 3
⁹ | 9
° | deg
φ | phi
To export, it's easy, we replace the matching character by the first on the second column.
But for the parsing, it's more complicated, and I don't see an easy way to get all the possible values to import?
One example:
H³ 3° (asd)₃
Would be exported as
H3 3deg (asd)3
So to parse this correctly, I've to get all the possibilities:
H3 3deg (asd)3 //This may be a real values
H³ 3deg (asd)3
H₃ 3deg (asd)3
H3 ³deg (asd)3
....
What would be the good way of doing this?
I doubt it's possible with such an encoding. All H3 values are equally likely unless there is a rule that differentiates them. This makes parsing more difficult, not less.
What you are trying to do though looks a lot like what has already been done with tools like Latex or even Word. You should probably use the encodings used by Latex since they've already done the work of encoding symbols to human readable and editable keywords that can be parsed easily, eg: use ^ for power, _ for indices, \degree for degrees, etc.
In fact, even Word allows these same keywords nowadays in the Math editor, allowing you to type \sum and get ∑, or \oint for ∮
You should probably tag the fields that contain substitutions, eg by surrounding them in multiple braces, so that users can use the keywords in their own text.
I think you need to exclude ambiguous mappings. E.g.:
³ | ^3, **3
₃ | 3
⁹ | ^9, **9
or
³ | 3, ^3, **3
₃ | _3
⁹ | 9
ASCII has 7 Bits for each character. Now you want to use chars which are implemented in the space of 8 Bits (UTF8 for example).
Now you lose information by converting your UTF8 character to ASCII but you want get back the full information.
To manage this, you need a mask, which helps to recognize the right character.
You could use special characters as your mask. So you don't reinvent the wheel and others can find the documentation all over the internet for your interface.
But if you make ³ => 3, you lose information (3 superscript => 3; where is the superscript and how you should guess the right choice?)
I just starting to work with SpecFlow and really like the tool. However I am running across some issues in relation to example data inputs into the Scenario Outlines.
Just wondering if what I am facing is normal or whether there is a trick to it.
I am using C# Visual Studio 2013 and writing an MVC App using the underscore style of step definition. I have also tried the regular expression style but still get similar issues.
So the issue is I am providing username, password etc as parameters and including sample data in my Examples. It appears that the following occurs: -
I have to put "" around the parameters when 1st generating the scenario, otherwise it does not get picked up as a parameter at all. However when passing data in from the examples I get a "/" at the end of the data passed in. When I go back to the scenario I then remove the "" around the parameter. This is a little frustrating but if that is the best way to handle it I can live with that. Just wondering if anyone has any advice on this point.
The next issue is related to the data itself. It appears if I have any characters such as # or & etc in my data, then it splits that data at that point and feeds it to the next parameter so I get incorrect data being fed through.
I have included my code below - if anyone has any suggestions or resources to look at that would be appreciated.
Feature File
Feature: AccountRegistration
In order to use Mojito services in my organisation
As a guest user
I want to create an account with administration privelages
Scenario Outline: Register with valid details
Given I am on the registration page
And I have completed the form with <email> <organisation> <password> and <passwordConfirmation>
When I have clicked on the register button
Then I will be logged in as <username>
And my account will be assigned the role of <role>
Examples:
| email | organisation | password | passwordConfirmation | username | role |
| usernamea | Bytes | password1 | password1 | usernamea | Admin |
| usernameb | Bytes | password2 | password2 | usernameb | Admin |
| usernamec | Bytes | password3 | password3 | usernamec | Admin |
| usernamed | Bytes | password4 | password4 | usernamed | Admin |
| usernamee | Bytes | password5 | password5 | usernamee | Admin |
Scenario Outline: Register with invalid details
Given I am on the registration page
And I have completed the form with <email> <organisation> <password> and <passwordConfirmation>
When I have clicked on the register button
Then I will get an error message
Examples:
| email | organisation | password | passwordConfirmation |
| Jonesa#mojito.com | Bytes | 1LTIuta&Sc | wrongpassword |
| Jonesb#mojito.com | Bytes | 1LTIuta&Sc | 1LTIuta&Sc |
| Jonesc#mojito.com | No Organisation | 1LTIuta&Sc | 1LTIuta&Sc |
Steps Generated File
[Binding]
public class AccountRegistrationSteps
{
[Given]
public void Given_I_am_on_the_registration_page()
{
ScenarioContext.Current.Pending();
}
[Given]
public void Given_I_have_completed_the_form_with_usernamea_Bytes_password_P0_and_password_P1(int p0, int p1)
{
ScenarioContext.Current.Pending();
}
[Given]
public void Given_I_have_completed_the_form_with_Jonesa_mojito_com_Bytes_P0_LTIuta_Sc_and_wrongpassword(int p0)
{
ScenarioContext.Current.Pending();
}
[When]
public void When_I_have_clicked_on_the_register_button()
{
ScenarioContext.Current.Pending();
}
[Then]
public void Then_I_will_be_logged_in_as_usernamea()
{
ScenarioContext.Current.Pending();
}
[Then]
public void Then_my_account_will_be_assigned_the_role_of_Admin()
{
ScenarioContext.Current.Pending();
}
[Then]
public void Then_I_will_get_an_error_message()
{
ScenarioContext.Current.Pending();
}
}
SpecFlow does handle string parameters by default, the problem is that you left control up to SpecFlow in determining at runtime what your values are.
When you ran "Generate Step Definitions," you selected "Method name - underscores" in the Style dropdown. This left interpreting the input parameters up to SpecFlow, which will create what are called 'greedy' regular expressions to identify the parameter values. This means that it would include the comma as part of the value.
Had you selected "Regular expressions in attributes," (or refactored your code a touch and decorated your attributes by hand) your step could look like this:
[Given(#"I have completed the form with (.*), (.*), (.*), and (.*)")]
public void Given_I_have_completed_the_form_with(string email, string org, string pwd, string conf)
{
//do stuff here
}
This creates a more 'parsimonious' expression that tells SpecFlow to accept strings of any length, up to but not including any trailing commas. Single quotes around the regular expressions would make it even more explicit:
[Given(#"I have completed the form with '(.*)', '(.*)', '(.*)', and '(.*)'")]
Managing the regular expressions yourself can create headaches, but it really exposes the full power of SpecFlow if you do so.
RESOLVED - It was not an issue with the use of characters such as # or &. It was actually using commas in my Given Statement. I found if I used 'and' it works. So to get it working the statement had to be written as below: -
SOLUTION
Write statement as
Given I have completed the form with <email> and <organisation> and <password> and <passwordConfirmation>
Modify statement to put single quotes around paramaters that need to be strings
Given I have completed the form with '<email>' and '<organisation>' and '<password>' and '<passwordConfirmation>'
Generation Step Definitions and then change statement back to exclude single quotes
Given I have completed the form with <email> and <organisation> and <password> and <passwordConfirmation>
A bit of mucking around but it gets the correct results. Hopefully in the future SpecFlow will be updated to handle paramaters as strings as default.
For future reference, if Cater's answer doesn't do the job. I had the following problem
Give I have a <typeOfDay> day
When Im asked how I am
Then I will say <feeling>
Example:
|typeOfDay|feeeling|
|good |happy |
|bad |sad |
You'll notice that "feeling" in the Then statement won't be able to find a corresponding value because of a typo. This causes SpecFlow to throw the "Input string not in a correct format" error. Which in my case took an embarrassingly long time to find.
Something else to check :)
I have the following two examples of html-
User: <a style="color:#333" href="http://foo.com/word"></a> blue elephant ·
User: <a style="color:#333" href="http://foo.com/word">#<b>word</b></a> blue elephant ·
I am trying to parse this using C# to put into a csv file and it is working to an extent however, when the html contains the '#' symbol in it, it will either leave the csv cell blank or not include the word with '#' before it. The main part I am trying to get is #word blue elephant however this is bringing back a blank cell, whereas the first html example brings back blue elephant as desired.
I am using the following technique to do this-
string[] comm = System.Text.RegularExpressions.Regex.Split(content[1], "<a");
How can I alter this to work for the second html example?
You want to use a proper HTML parser like the one in HTML agility pack in this situation (and save yourself from invoking the wrath of Cthulhu)
Some examples of how to use it
Getting started
Easily extracting links from a snippet of html with HtmlAgilityPack
I am trying to create a postage label that is populated dynamically in C#.
What I thought I could do was create the label in Excel so I could get the layout perfect, then use OpenXML to replace the fields. i.e. I have fields called things like XXAddressLine1XX, where I want to edit the XML and replace that text with the actual Address Line 1 from the database.
Has anyone actually done something similar to this before and could post some code up that I could try? I've used OpenXML to do this with word documents before, but I can't seem to find the XML data for the Excel document when using OpenXML in c# so am struggling to make progress.
Either that, or are there any better methods I could try to accomplish this?
Every now and then, there's a programming problem that is best solved with a non-programming solution. Businesses have had the need for printing mailing labels en masse for a long time, and in recent decades programs like Microsoft Word make this really simple via the "mail merge" feature. See http://office.microsoft.com/en-us/word-help/demo-use-mail-merge-to-format-and-print-mailing-labels-HA001190394.aspx for an example.
Word's mail merge will allow you to connect to a variety of data sources. The given example uses an Excel spreadsheet, but you can also use Access or SQL Databases, etc.
The purely academic answer is: it's possible. I wrote a set of template parsing classes that search through a PowerPoint presentation replacing tags from a mark-up language I invented with charts and dynamic text objects fetched from a database. The trickiest part of the string replacement bit was handling tags that occurred across Run elements inside a Paragraph element. This occurs usually if you use special characters such as '{' or spaces in your tags. I was able to solve it by storing the text of the entire TextBody element in a gigantic character array (in your case it would be the contents of a Cell element), storing a list of extents that enumerated where in the character array each Run element began and ended, and then walking the character array while paying attention to the Run boundaries appropriately. Mind that if your tag spans across multiple Run elements you'd need to remove any extras and snip content across boundaries before you inserted the replacement Run. Unfortunately I cannot post any code because the work was done for a company, but that's the general idea of how to achieve it. I was not able to handle any newline cases (i.e. a tag occurs with a newline in it) because that would require writing a cross Paragraph indexer, which was beyond the scope of what I wanted to achieve. That could be done as well, but it would be significantly more difficult I think.
The Powershell script extension PSExcel have an search and replace feature:
PSExcel: https://github.com/RamblingCookieMonster/PSExcel
Import-Module d:\psexcel\trunk\PSExcel\PSExcel
# Get commands in the module
Get-Command -Module PSExcel
# Get help for a command
Get-Help Import-XLSX -Full
# Modify the path of the Excel file to your local svn ceck-out
Get-ChildItem "C:\tmp\Source" -Filter *.xlsx | Foreach-Object{
$fileName = $_.FullName
# Open an existing XLSX to search and set cells within
$Excel = New-Excel -Path $_.FullName
$Workbook = $Excel | Get-Workbook
#$Excel | Get-Worksheet
$Worksheet = $Workbook | Get-Worksheet -Name "Sheet1"
#Search for any cells like 'Chris'. Set them all to Chris2
$Worksheet | Search-CellValue {$_ -like 'Chris'} -As Passthru | Set-CellValue -Value "Chris2"
#Save your changes and close the ExcelPackage
$Excel | Save-Excel -Close
}