Project

General

Profile

action #102131

Updated by oorlov almost 3 years ago

## Motivation 
 There is regex used to parse the content of YRichText in [verify_module_selection.pm](https://github.com/os-autoinst/os-autoinst-distri-opensuse/blob/50427972586cbed7e5f9eea2bae27a34770048bf/tests/installation/module_selection/verify_module_selection.pm#L26) test module (In  
 `$testapi::distri->get_module_selection()->get_selected_modules()` function). The Page where it is used: https://github.com/os-autoinst/os-autoinst-distri-opensuse/blob/50427972586cbed7e5f9eea2bae27a34770048bf/lib/Installation/ModuleSelection/ModuleSelectionPage.pm#L44 

 The regex solution works, but we found out more elegant and easy to read solution: to parse the DOM with [Mojo::DOM](https://docs.mojolicious.org/Mojo/DOM) and then find the elements of the parsed DOM with XPATH. 

 ## Task 
 encrypt_lvm_reuse_existing is used in 'activate_encrypted_volume' and 'activate_encrypted_volume+import_users' (all qemu) 
 https://openqa.suse.de/tests/overview?arch=&flavor=&machine=&test=&modules=encrypt_lvm_reuse_existing&module_re=&distri=sle&version=15-SP4&build=79.1&groupid=129# 

 Instead of using regex, we should read the screen in a way more realiable, we can read content in Suggested Partitioning and parse it with [Mojo::DOM](https://docs.mojolicious.org/Mojo/DOM) (afir we might need to put the content of text inside some <div> or other structure for the library to work) 
 ``` 
 { 
     "class" : "YRichText", 
     "hstretch" : true, 
     "id" : "summary", 
     "text" : "<p>Initial layout proposed with the default Guided Setup settings.</p><p>Changes to partitioning:</p><p><ul><li><b>Delete btrfs on /dev/system/root (14.72 GiB)<br>Delete logical volume root (14.72 GiB) on volume group system</b></li><li><b>Delete swap on /dev/system/swap (1.45 GiB)<br>Delete logical volume swap (1.45 GiB) on volume group system</b></li><li><b>Delete xfs on /dev/system/home (6.81 GiB)<br>Delete logical volume home (6.81 GiB) on volume group system</b></li><li><b>Delete volume group system (22.98 GiB)</b></li><li><b>Delete partition /dev/vda2 (22.99 GiB)</b></li><li>Create partition /dev/vda2 (14.72 GiB) for / with btrfs</li><li>Create partition /dev/vda3 (6.82 GiB) for /home with xfs</li><li>Create partition /dev/vda4 (1.45 GiB) for swap</li><li>27 subvolume actions (<a href=\"actions_presenter--subvolumes\">see details</a>)</li></ul></p>", 
     "vstretch" : true 
   } 
 ``` 

 **AC1**: Creation of new test module to parse the summary. 
 **AC2**: Merge test suites activate_encrypted_volume activate_encrypted_volume+import_users 

 ## Additional info 
 We discussed this solution some time ago in one ont of the threads in Slack: https://suse.slack.com/archives/C02CLB2LB7Z/p1635507962072800 

 For    we found out the following: 

 So, after investigation of YRichText widget on Module Selection Page the page we found out several issues that require to be resolved in order to use Mojo:DOM: 
 1. It has `&nbsp;` and `\n` the text body written as strings, so in case we would like to parse the xml, we need to get rid of them; 
 2. It does not have root tag, only a list of <p>    is there, so parser will complain with parser error : `Extra content at the end of the document`. 
 So, we can use xml_utils, but in this case we need to sanitize and adjust the xml that comes from YRichText. Something like that: 

 ```perl 
 my $xml = get_text();       # get html text 
 $xml =~ s/&nbsp;//ig;       # remove all &nbsp; 
 $xml =~ s/\n//ig;           # remove all \n 
 $xml = "<div>$xml</div>"; # add root tag 
 my @nodes = map { $_->to_literal() } find_nodes(xpc => get_xpc($xml), xpath => '//a/@href'); 
 ```

Back