RSpec test uploaded xml file that fills out dynamic form - ruby

I am writing an automation test suite using RSpec, capybara, selenium web driver, and poltergeist. I do not have access to the codebase of the web app itself, only the test suite.
What happens is the client uploads an xml file, pieces of that xml file populate a form. The form is also dynamic, so fields can be added dependent on the contents of the xml file.
My mission is to write a test that ensures that the values of the xml file match what is being populated within the form.
Any help would be greatly appreciated. Below is a sample of one of the xml files I am attempting to test.
<?xml version="1.0" encoding="UTF-8"?>
<LOAN_APPLICATION>
<_DATA_INFORMATION>
<DATA_VERSION _Name="Date" _Number="20140926"/>
<DATA_VERSION _Name="1003" _Number="3.20"/>
</_DATA_INFORMATION>
<ADDITIONAL_CASE_DATA>
<TRANSMITTAL_DATA BelowMarketSubordinateFinancingIndicator="N" BuydownRatePercent="0.000" />
</ADDITIONAL_CASE_DATA>
<ASSET _CashOrMarketValueAmount="10000.00" />
<ASSET _AccountIdentifier="123456"/>
<ASSET _AccountIdentifier="1234567" _CashOrMarketValueAmount="100000.00" />
<ASSET _AccountIdentifier="6465456" _CashOrMarketValueAmount="50000.00" />
<InterviewersEmployerPostalCode="200121234" InterviewersTelephoneNumber="2023333333" ApplicationTakenMethodType="FaceToFace" InterviewerApplicationSignedDate="20111011" InterviewersEmployerName="ABC Mortgage" InterviewersName="John Done"/>
<CONTACT_POINT _Type="Email" _Value="Jimmy.Johns#abc.com"/>
</BORROWER>
</LOAN_APPLICATION>

John, you could create a fixture that reproduces an XML file like the one you pasted. Then you run your services, methods etc against it, and expect (or not) to parse back the contents of the fixture. You could also test another fixtures with invalid fields to ensure your app has contingencies to break down gracefully if there are any invalid fields.

Related

Extending Visual Studio 2017 XML editor

I'm trying to improve our workflow with some XML-configuration files we use in a Visual Studio Solution. I figured I'll start with explaining what I'm trying to accomplish and then explain some of my ideas that I've tried for several hours without success.
The Problem
I'm working with a system where the data model is configured in a database, the models are also stored on disk using xml-files, these are then synced during startup of the app. Here's part of the stuff that are synced:
Data Types
All data types lives in one XML configuration file per data type and each has some properties like Name and Key. All data types are configured in the same folder, example: /config/dataTypes
Example
textString.config
<?xml version="1.0" encoding="UTF-8" ?>
<DataType Key="a45c9a94-09d7-4df9-85e6-d6930abc6c12" Name="Textstring">
textArea.config
<?xml version="1.0" encoding="UTF-8" ?>
<DataType Key="b104788f-4e2f-4592-9387-8b3861bd8046" Name="Textarea">
Entity Types
Think of these as models with X number of properties, each property is configured and connected to a Data Type.
Example
customer.config
<?xml version="1.0" encoding="UTF-8" ?>
<Entity>
<Properties>
<Property Name="Firstname" TypeKey="a45c9a94-09d7-4df9-85e6-d6930abc6c12" />
<Property Name="Lastname" TypeKey="a45c9a94-09d7-4df9-85e6-d6930abc6c12" />
<Property Name="Description" TypeKey="b104788f-4e2f-4592-9387-8b3861bd8046" />
</Properties>
</Entity>
My end goal is to provide intellisense when editing a Entity Type so that I'll get all the Data Types as suggestions when entering the "TypeKey" property of the Property element. Preferably showing the Name of the data type in the dropdown list and when choosing it adding the guid as value for the TypeKey-property. I would also like to show the Data Types name when hovering the GUID with the mouse (or in some other way).
As you can imagen during the process with a project new data types can be added so the intellisense needs to be dynamic based on the files in the data types-folder.
I should also mention that these configuration files also can be edited from a UI in the application and I don't have control over how they are serialized, hence - there is no XML namespace in the files, they look like in the examples above.
We also have multiple different VS-solutions with different setups of Data Types and Entity Types. So we need individual intellisense in each project.
What I've tried
My first idea was to create a VS-extension that creates a dynamic XML Schema XSD-file based on the files in the data types folder. The VS would then pick up and use the XSD for XML-files in the Project, turns out that this only works with a namespace configured (remember, I can't add namespaces since I don't control the external app).
To get around this it worked to manually add the schema-file to the XML file while editing the file. (Like this: https://learn.microsoft.com/en-us/visualstudio/xml-tools/how-to-select-the-xml-schemas-to-use?view=vs-2019). The problem with this is that it needs to be done for each xml-file and the setting is not stored.
I then started to play with the VS extension possibilities to try to automatically configure this Schema to a XML-file that is opened. Turns out I had a really hard time to get the "configuration object" that is pushed to the Properties Browser when the XML file is opened. I managed to get a event-handler setup that was triggered when the XML files as getting "focus" but I was stucked trying getting the properties from the Properties Browser.
I also tried another approach with a custom "code completion"-extension but it made the UI feel very "cluttered" while editing.
After spending about 10 hours playing around with this I feel I don't really have a good path to a solution as my experience with VS-extensions is not that extensive.
I would love to get some feedback and ideas on how to approach this problem, since the XSD is different from each project if I go down the "dynamic" path we can't use the global VS settings since each project has different data types hence needs different allowed values for the TypeKey property.
One approach that I'm thinking about is to use a generic XSD (allowing all values for the TypeKey) in the Global Schema Cache for Visual Studio and create a "code completion"-feature for just the TypeKeys.
Any thoughts and pointers in the right direction would be very much appreciated.

How to read an XML file using Testcomplete?

I have an XML file of the following format:
<a>Test</a>
<Book>
<Title>ABC</Title>
<Price>123</Price>
<Author>Pete</Author>
</Book>
Is there anyway to read the contents using TC9 (jscript)? The xml file that i am using doesnot have a namespace.It is saved as .XML file but cannot be opened using web browser.It is basically used by us to store Logs of our app hence can be viewed via Notepad or Notepad++ .
Thanks !
You can find detailed information on how to work with XML files from a TestComplete script in the Working With XML Files From Scripts help topic.
The only concern I see is that the XML file you showed us does not have a root node. It must have a root node in order to make standard XML parsers work with it.

Common settings file for multiple projects in a solution

Visual Studio project structure - https://www.box.com/s/np59x20f939n3z1g5dvc
I have multiple projects A, B, etc. that have load tests (which in turn call respective web tests) and a settings file separately for each one of them. I am using these settings files to store the info about web servers.
[Settings.xml]
<?xml version="1.0" encoding="utf-8" ?>
<AppSettings>
<WebServer>www.abc.com</WebServer>
<Proxy></Proxy>
</AppSettings>
I am adding this xml file as a data source in the web test as shown here https://www.box.com/s/53vy0ryvye53m76abuun
Project C has a load test that calls upon web tests from other projects (I am only referring to the projects A, B, etc. here). The setting file for project C looks like this.
<?xml version="1.0" encoding="utf-8" ?>
<AppSettings>
<WebServer>www.SomeOtherWebsite.com</WebServer>
<Proxy></Proxy>
</AppSettings>
I want this settings file to be used for running the Loadtest-C i.e. this settings file has to override the individual settings file from each project.
I want to run LoadTest-C sometimes and LoadTest-A or LoadTest-B sometimes. So, I don’t want to change the individual settings files everytime.
Is there a way I can achieve this?
I found using xml files to be the simpler way. But, please do suggest me if there is a better way.
I have searched online and the only thing I found relevant was this - common Settings.settings file for entire solution. I have a lot of projects similar to A, B, etc. and I don’t want to change the links in each and every project as suggested in the answer there.
[I have never tried coded web tests. So I am not sure if that approach works.]
[and i am relatively new to performance testing]
I have found a solution for this. Instead of using the Settings.xml file, I am adding the entries in that xml file as context parameters to the load test and eliminating the use of data source in individual web tests. So when I run the web test, the parameter it has for web server name is being supplied by the context parameter in the load test.
This might not be the best solution, but this seems to work for me.

Session handling into two different XSLT files

I have two XSLT files and I want to create session in one xslt file, then modify it in another XSLT file.
This is my first file:
<session:createcontext name="user_context"/>
<session:setxml context="user_context" path="/">
<NAME>HELLOWORLD</NAME>
</session:setxml>
and this is my second file:
<session:setxml context="user_context" path="/">
<NAME>HELLOINDIA</NAME>
</session:setxml>
Is this correct?
The code is not able to update the attribute "NAME" in session, and I am getting still "HELLOWORLD".
Environment: This implementation is running on Cocoon 2.2 with a Tomcat application.
In Cocoon, also same problem with the following scenario:
I have created session in XMAP (Cocoon config file), and I am accessing the same session in one pipeline's transform XSLT implementation. Here I have changed the session's an one attribute and I want to access the same attribute of same session in again xmap file.

Packaging Visual Studio LoadTest Solution

I have a VS 2010 Load test solution that contains quite a web tests and a bunch of Load tests. All of the web tests in this solution are data driven and use a SQL DB as the data source. Also, all of the data sources are set to random access method.
Now, whenever I change the data source or copy this solution to a different machine to test another deployment, I have to manually change the data source for all the web tests. The moment I change the data source, the access method gets reset to "sequential" which is the default setting. Now, I will have to change the access method also manually.
So, Is there a way I can package the VS Load Test solution so that the data source and access methods can be specified as parameters to the deployment package?
Note: Only the data source name changes but not the SQL DB schema for the data driven web tests.
The DataSourceAttribute can get all of it's properties from the configurations file of the application.
Here is a page that tells you how to use configuration files to place the connection string.
Walkthrough: Using a Configuration File to Define a Data Source
As you can see you may place the connection string in the app.config file, in the section <microsoft.visualstudio.qualitytools>:
<microsoft.visualstudio.testtools>
<dataSources>
<add name="MyJetDataSource" connectionString="MyJetConn" dataTableName="MyDataTable" dataAccessMethod="Sequential"/>
<add name="MyExcelDataSource" connectionString="MyExcelConn" dataTableName="Sheet1$" dataAccessMethod="Sequential"/>
</dataSources>
</microsoft.visualstudio.testtools>
In code usage of attribute:
[DataSource("MyJetDataSource")]
Reference:
The following links are just for reference:
How to: Create a Data-Driven Unit Test : creating data-sriven tests
Working with Load Tests : understanding load tests
DataSourceAttribute Class : docs for the attribute
DataSourceAttribute Constructor (String) : ctor that allows external connection string
DataSourceAttribute.DataSourceSettingName Property
Covert the web tests into coded web tests. In the code you will see the data binding code. Whenever you change the data source you can simply use find and replace all for data source name.
I don't think there is way to include this in deployment package.

Resources