Completed
Push — texteditor-ui-tests-01 ( edb786 )
by Phil
65:32 queued 42:45
created

TextEditorPage::findTextFileEditField()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
/**
3
* ownCloud
4
*
5
* @author Phillip Davis
6
* @copyright 2017 Phillip Davis [email protected]
7
*
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
* License as published by the Free Software Foundation; either
11
* version 3 of the License, or any later version.
12
*
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
*
18
* You should have received a copy of the GNU Affero General Public
19
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
*
21
*/
22
23
namespace Page;
24
25
use Behat\Behat\Tester\Exception\PendingException;
26
use SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException;
27
28
class TextEditorPage extends FilesPage
29
{
30
	protected $newTextFileButtonXpath = './/div[contains(@class, "newFileMenu")]//a[@data-templatename="New text file.txt"]';
31
	protected $newTextFileNameInputLabel = 'New text file.txt';
32
	protected $textFileEditXpath = "//textarea[contains(@class,'ace_text-input')]";
33
34
	/**
35
	 * create a text file with the given name.
36
	 * If name is not given the default is used.
37
	 *
38
	 * @param string $name
39
	 */
40
	public function createTextFile($name = null)
41
	{
42
		$this->find("xpath", $this->newFileFolderButtonXpath)->click();
43
		$this->find("xpath", $this->newTextFileButtonXpath)->click();
44
		if (strlen($name)) {
45
			try {
46
				$this->fillField($this->newTextFileNameInputLabel, $name . "\n");
47
			} catch (\WebDriver\Exception\NoSuchElement $e) {
0 ignored issues
show
Bug introduced by
The class WebDriver\Exception\NoSuchElement does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
48
				//this seems to be a bug in MinkSelenium2Driver. Used to work fine in 1.3.1 but now throws this exception
49
				//actually all that we need does happen, so we just don't do anything
50
			}
51
		} else {
52
			// TODO: Handle keeping the default "New text file.txt" name, and just pressing enter
53
			throw new PendingException();
54
		}
55
	}
56
57
	/**
58
	 * finds the textarea field to use for editing a text file
59
	 *
60
	 * @throws ElementNotFoundException
61
	 * @return \Behat\Mink\Element\NodeElement
62
	 */
63
	public function findTextFileEditField() {
64
		$textField = $this->find(
65
			"xpath", $this->textFileEditXpath
66
		);
67
		if ($textField === null) {
68
			throw new ElementNotFoundException("could not find textarea field");
69
		}
70
		return $textField;
71
	}
72
73
	/**
74
	 * type text into the text area
75
	 *
76
	 * @param string $text
77
	 * @return void
78
	 */
79
	public function typeIntoTextFile($text) {
80
		$textField = $this->findTextFileEditField();
81
		$textField->setValue($text);
82
	}
83
84
	public function waitTillEditorIsLoaded($timeout_msec = STANDARDUIWAITTIMEOUTMILLISEC)
85
	{
86
		$this->waitTillElementIsNotNull($this->textFileEditXpath, $timeout_msec);
87
	}
88
89
}