blob: e465454ad3789017dc87051ab53c79e3a9adf302 [file] [log] [blame]
<!DOCTYPE html>
<head>
<title>RCPTT Blog</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://www.eclipse.org/rcptt/shared/css/bootstrap.min.css">
<link rel="stylesheet" href="https://www.eclipse.org/rcptt/shared/css/main.css">
<link rel="stylesheet" href="https://www.eclipse.org/rcptt/shared/css/prism.css">
<link rel="icon" href="https://www.eclipse.org/rcptt/shared/img/favicon.ico">
<link rel="alternate" type="application/atom+xml" href="https://www.eclipse.org/rcptt/blog/atom.xml" title="RCP Testing Tool Blog"/>
<script src="https://www.eclipse.org/rcptt/shared/js/jquery.min.js"></script>
<script src="https://www.eclipse.org/rcptt/shared/js/bootstrap.min.js"></script>
<script src="https://www.eclipse.org/rcptt/shared/js/prism.js"></script>
<script src="https://www.eclipse.org/rcptt/shared/js/ecl.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-39589807-5', 'eclipse.org');
ga('send', 'pageview');
</script>
</head>
<body>
<div id="before-footer">
<header>
<nav class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="https://www.eclipse.org/rcptt/blog"><span class="navbar-brand">RCPTT Blog</span></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li >
<a href="https://www.eclipse.org/rcptt/blog/">Latest Entries</a>
</li>
<li >
<a href="https://www.eclipse.org/rcptt/blog/categories">Categories</a>
</li>
<li >
<a href="https://www.eclipse.org/rcptt/blog/tags">Tags</a>
</li>
<li>
<a href="http://eclipse.org/rcptt">Back to RCPTT Main Site</a>
</li>
<li>
<a href="http://eclipse.org">Eclipse.org</a>
</li>
</ul>
</div>
</nav>
</header>
<section class="content">
<div class="container">
<article>
<header>
<h2>Reading File and Clipboard Content</h2>
<small>Aug, 12, 2015 by Ulyana Skorokhodova</small> </header>
<div>
<h3>Reading file content</h3>
Until recently there was a few ways to get a file content:<br>
<ul>
<li>Opening file editor in GUI and getting it's <i>text</i> property
<li>Using <a href="https://ci.eclipse.org/rcptt/job/master/lastSuccessfulBuild/artifact/releng/doc/target/doc/ecl/index.html#read-csv-file"><b>read-csv-file</b></a> and <a href="https://ci.eclipse.org/rcptt/job/master/lastSuccessfulBuild/artifact/releng/doc/target/doc/ecl/index.html#read-lines"><b>read-lines</b></a> commands</li>
</ul>
Both ways have obvious restrictions making their usage not very user-friendly, so we decided to implement a new <a href="https://ci.eclipse.org/rcptt/job/master/lastSuccessfulBuild/artifact/releng/doc/target/doc/ecl/index.html#read-file"><b>read-file</b></a> ECL command to get a file content.<br><!-- break -->
It takes a file <i><b>uri</b></i> as an argument and returns a String content of a file:
<pre ><code class="language-ecl">&#x200b;read-file -uri "file:/Users/Ulik_MacAir/MyProject/File.txt" | log
</code></pre>
You can use either absolute or relative uri (use workspace:/ to point to your AUT workspace):
<pre ><code class="language-ecl">&#x200b;read-file -uri "workspace:/MyProject/File.txt" | log
</code></pre>
Usually you need to get a file content for further verifications. Lat's say we need to compare a content of two files. <br>
So here what our test will look like:
<pre ><code class="language-ecl">&#x200b;read-file -uri "workspace:/MyProject/File.txt" | equals [read-file -uri "workspace:/MyProject/Copy.txt"] | verify-true
</code></pre>
<br>
<div class="panel panel-warning">
<div class="panel-heading">
What may go wrong?
</div>
<div class="panel-body">
<i><b>Failed to read</b> /MyProject/Unexisting.txt at read-file (/ReadFile/Test.test:3)</i> - means that there is <b>no such file</b>. <br>
<i><b>Failed to resolve</b> /MyProject/Copy.txt at read-file (/ReadFile/Test.test:3)</i> - means that file uri is in <b>wrong format</b>. Most likely you forgot to add <b>file:/</b> to a file path.
</div>
</div>
<h3>Operating with a Clipboard</h3>
Clipboard is always used to check a correct work of Copy/Paste actions. <br>
RCPTT can now operate with a clipboard directly using <b><a href="https://ci.eclipse.org/rcptt/job/master/lastSuccessfulBuild/artifact/releng/doc/target/doc/ecl/index.html#to-clipboard">to-clipboard</a></b> and <b><a href="https://ci.eclipse.org/rcptt/job/master/lastSuccessfulBuild/artifact/releng/doc/target/doc/ecl/index.html#from-clipboard">from-clipboard</a></b> commands.<br>
So if you need to paste something you don't need to do coping actions before. You can do like:
<pre ><code class="language-ecl">&#x200b;to-clipboard MyClipboardContent
with [get-editor "File.txt" | get-text-viewer] {
get-menu Paste | click
}
</code></pre>
Likewise, if you need to check that copying works correctly, you don't need to do pasting afterwards. You may simply check a clipboard content right from ECL script:
<pre ><code class="language-ecl">&#x200b;get-view "Test Explorer" | get-tree | select MyProject | get-menu Copy | click
from-clipboard | equals MyProject | verify-true
</code></pre>
<br>
<div class="panel panel-info">
<div class="panel-heading">
Information
</div>
<div class="panel-body">
If you need to put a big text into a clipboard it may be more convenient to use ECL Script Context for this purpose (just to make your test script more readable and laconic).
Please note that Workbench Context clears clipboard, so make sure that your ECL Script Context goes after a Workbench one.
</div>
</div>
</div>
<p class="categories">
Categories:
<a href="https://www.eclipse.org/rcptt/blog/categories/howtos">howtos</a>, <a href="https://www.eclipse.org/rcptt/blog/categories/ecl">ecl</a> </p>
<nav class="article">
<ul>
<li>Next: <a class="next" href="https://www.eclipse.org/rcptt/blog/2016/08/05/2_1_0-released.html" title="RCPTT 2.1.0 (Neon) Released"><span class="title">RCPTT 2.1.0 (Neon) Released</span></a></li>
<li>Previous: <a class="previous" href="https://www.eclipse.org/rcptt/blog/2015/06/26/2_0-released.html" title="RCPTT 2.0.0 (Mars) Released"><span class="title">RCPTT 2.0.0 (Mars) Released</span></a></li>
</ul>
</nav>
<p><a href="https://www.eclipse.org/forums/index.php/t/1069320/">Discuss</a> this article on forum.</p>
</article>
</div>
</section>
<script src="https://www.eclipse.org/rcptt/shared/js/main.js"></script>
</body>