2

I want to extract VIEWSTATE value and EVENTVALIDATION value, but I havent. How to extract two string(viewstate and eventvalidation) from this text?

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="DAwNEAIAAA4BBQAOAQ0QAgAADgEFAQ4BDRACAAAOAQUTDgENEAIAAA4BBQUOAQ0QAhAMDA8DAQlEYXRhQm91bm=" />


 <!--
        <div class="FullWidth FooterMa
            <div class="container_24 clearf
                <div class="grid_14 clearfix eisk-info alpha suffix
                    <p class="grid_14 branding-x2 alpha" title="" style="text-align:rig

                    <p style="text-align:rig

                </
            </
        </
    -->

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="GwABAAAA/////wEAAAAAAAAADwEAAAACAAAACAZFC0eJh7q7CwA=" />
    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
Ashraf Alam
  • 3,500
  • 32
  • 31
Tester
  • 531
  • 1
  • 4
  • 9
  • Regex isn't the tool you're looking for. It can't parse HTML correctly:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags#answer-1732454 You want to look at Xpath ans HTML parser. What language are you using, what is the context here? – Robin Jan 21 '14 at 10:18
  • I try to test a .NET application with jmeter and I must correlation :/ So I must extracted this value from text. I can do only one value but two string I couldn't. for ex: only eventvalidation value: __EVENTVALIDATION" value="(.*?)" – Tester Jan 21 '14 at 10:26

4 Answers4

2

Try those regexes:

<input.*id="__(?:VIEWSTATE|EVENTVALIDATION)"\s+value="([^"]+)"\s+/>

Demo

http://regex101.com/r/iZ4kQ7

Stephan
  • 41,764
  • 65
  • 238
  • 329
  • I want to get to only one expression. I can extract only viewstate or eventvalidation. But I want to extract two substring from one regex. – Tester Jan 21 '14 at 11:33
2

It's not a good idea to parse HTML with regular expressions, especially multiline ones as slight markup change will cause all your efforts loss. You could try using XPath Extractor Post Processor instead as follows:

  • Reference Name: test
  • XPath Query : //input[@id='_VIEWSTATE']/@value | //input[@id='_EVENTVALIDATION']/@value

You should be able to refer VIEWSTATE as ${test_1} and EVENTVALIDATION as ${test_2} JMeter Variables.

A combination of Debug Sampler with View Results Tree Listener is very handy for seeing JMeter Properties and Variables and can be used for debugging regular expressions and other extractors.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
0

I had the same problem but I devided them into 2 separate variables, using the Regular Expresion Extractor:

For EVENTVALIDATION:

Reference Name: eventValidation
Regular Expression: name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="(.+?)"
Template: $1$
Match No.(0 for Random): 1

For VIEWSTATE:

Reference Name: viewState
Regular Expression: name="__VIEWSTATE" id="__VIEWSTATE" value="(.+?)"
Template: $1$
Match No.(0 for Random): 1

Use them with ${viewState} and ${eventValidation}.

Shai Alon
  • 969
  • 13
  • 21
0

The first regular expression extractor will grab the page’s VIEWSTATE element and store it in the JMeter viewState variable. Add a new Regular Expression Extractor in JMeter by:

  • Right click on your Thread Group
  • Choose Add -> Post Processors -> Regular Expression Extractor

Configure as follows:

  • Reference Name: viewState
  • Regular Expression: name="__VIEWSTATE" id="__VIEWSTATE" value="(.+?)"
  • Template: $1$
  • Math No: 1
  • Default Value: ERROR

View State Extractor

The regex extractor that stores the EVENTVALIDATION element in the eventValidation variable. Again:

  • Right click on your Thread Group
  • Choose Add -> Post Processors -> Regular Expression Extractor

Configure as follows:

  • Reference Name: eventValidation
  • Regular Expression: name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="(.+?)"
  • Template: $1$
  • Math No: 1
  • Default Value: ERROR

Extract Event Validation

Now that we have extracted the viewState and eventValidation values, we need to include them when we POST to our application. In my run, this only happened on the login page.

  • Select your login page POST in the Test Plan’s Recording Controller,
  • Set the __VIEWSTATE parameter to ${viewState},
  • Set the __EVENTVALIDATION parameter to ${eventValidation}.

Injecting variables inside login request

You will need to perform this operation on all requests which have those query/post parameters.

Jerome L
  • 607
  • 5
  • 11