WordPress database error: [INSERT, UPDATE command denied to user '51213-2'@'10.10.20.113' for table 'wp_options']
INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES ('_transient_doing_cron', '1714706587.0879609584808349609375', 'yes') ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)


Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372
{"id":936,"date":"2012-01-10T20:03:04","date_gmt":"2012-01-10T19:03:04","guid":{"rendered":"http:\/\/www.jonathanantoine.com\/?p=936"},"modified":"2012-01-10T20:04:22","modified_gmt":"2012-01-10T19:04:22","slug":"coded-ui-tests-property-readonly-cannot-be-retrieved-due-to-the-current-state-of-edit","status":"publish","type":"post","link":"http:\/\/www.jonathanantoine.com\/2012\/01\/10\/coded-ui-tests-property-readonly-cannot-be-retrieved-due-to-the-current-state-of-edit\/","title":{"rendered":"Coded UI Tests : Property “ReadOnly” cannot be retrieved due to the current state of Edit"},"content":{"rendered":"

\"\"<\/p>\n

Did you ever encounter this error while trying to retrieve a property value from an AutomationElement ? I did !<\/p>\n

Don’t worry, there is always a work-around, and I’ve found one. <\/p>\n

In this post, we’ll dig a little more into this issue and give a little example of the “Coded UI Tests” fun \ud83d\ude42<\/p>\n

<\/p>\n

The issue<\/h3>\n

Let’s create a little demo application wich contains only one control : a RichTextBox set as readonly.
\n[xml] <RichTextBox IsReadOnly="True" Margin="3" \/>[\/xml]
\n\"\"<\/a><\/p>\n

It may be interesting in a coded ui test to verify that the RichTextBox is really read only. <\/strong>Doing so seems pretty easy with Visual Studio :<\/p>\n

    \n
  1. Target the element using the coded ui test recorder;<\/li>\n
  2. In the code, get ReadOnly property value from the WpfEdit element;<\/li>\n
  3. In the code, Assert that the value is equal to ‘True’.<\/li>\n<\/ol>\n

    [csharp][TestMethod]
    \npublic void CodedUITestMethod1()
    \n{
    \n \/\/The target richTextBlock is of WpfEdit type
    \n WpfEdit uIItemEdit = UIMap.UIPropertyXXXcannotberWindow.UIItemEdit;<\/p>\n

    \/\/Assert it is really readonly
    \n Assert.IsTrue(uIItemEdit.ReadOnly);
    \n}[\/csharp]<\/p>\n

    By running this code, you will be disappointed to get this exception : “Property “ReadOnly” cannot be retrieved due to the current state of Edit” !<\/strong> I try to google this error but nothing is what I found \ud83d\ude41 !<\/p>\n

    How I solved it !<\/h3>\n

    I struggled a lot with the API and I found out that the read only property is also available via an another way<\/strong>.<\/p>\n

    First of all, you have to add the UIAutomationClient.dll assembly as a reference.<\/p>\n

    The solution is to get the native element linked to the WpfEdit which is of AutomationElement type. With it I can retrieve the the TextPattern which is supported by the RichTextBox automation peer. <\/p>\n

    This pattern can be use to select the whole text in the RichTextbox. Then you can retrieve the selection with the same pattern and ask for the IsReadOnly attribute value<\/strong>.<\/p>\n

    Pretty easy to find no ? (I am just kidding here :-s) !<\/p>\n

    The resulting, commented, code is here :
    \n[csharp]
    \n public static bool IsReadOnly(this WpfEdit richText)
    \n {
    \n if (richText == null) throw new ArgumentNullException("richText");<\/p>\n

    \/\/We are in WPF so NativeElement is of AutomationElement type.
    \n var element = richText.NativeElement as AutomationElement;<\/p>\n

    \/\/Retrieve the TextPattern,
    \n var pattern = element.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
    \n if (pattern == null)
    \n throw
    \n new InvalidOperationException("Cannot retrieve the info from the control");<\/p>\n

    \/\/use the pattern to select the whole RichTextBox
    \n pattern.DocumentRange.Select();<\/p>\n

    \/\/ use the pattern to get the selection
    \n var selection = pattern.GetSelection();<\/p>\n

    if (selection.Any())
    \n {
    \n \/\/Retrieve the value of the IsReadOnly attribute
    \n var attValue = selection[0]
    \n .GetAttributeValue(TextPattern.IsReadOnlyAttribute);
    \n if (attValue == null)
    \n throw
    \n new InvalidOperationException("Cannot retrieve the info from the control");<\/p>\n

    \/\/This is a boolean my dear
    \n return bool.Parse(attValue.ToString());
    \n }<\/p>\n

    throw
    \n new InvalidOperationException("Cannot retrieve the info from the control");
    \n }
    \n[\/csharp]<\/p>\n

    If you are struggling with the same kind of issue, please share it with us in the comment. You may also find intersting the list of available attributes for the TextPattern : http:\/\/msdn.microsoft.com\/en-us\/library\/ms608656.aspx<\/a><\/strong><\/p>\n

    A demo solution is available on my DropBox folder as usual<\/a>. <\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"

    Did you ever encounter this error while trying to retrieve a property value from an AutomationElement ? I did ! Don’t worry, there is always a work-around, and I’ve found one. In this post, we’ll…<\/p>\n","protected":false},"author":3,"featured_media":964,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[27],"tags":[],"_links":{"self":[{"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/posts\/936"}],"collection":[{"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/comments?post=936"}],"version-history":[{"count":30,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/posts\/936\/revisions"}],"predecessor-version":[{"id":969,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/posts\/936\/revisions\/969"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/media\/964"}],"wp:attachment":[{"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/media?parent=936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/categories?post=936"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/tags?post=936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}