Completed
Push — ui-tests-structure ( 9a3cd3...c02912 )
by Phil
36:00 queued 10:59
created

TextEditorPage::waitTillEditorIsLoaded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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 SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException;
26
27
class TextEditorPage extends FilesPage
28
{
29
	protected $newTextFileButtonXpath = './/div[contains(@class, "newFileMenu")]//a[@data-templatename="New text file.txt"]';
30
	protected $newTextFileNameInputLabel = 'New text file.txt';
31
	protected $textFileEditXpath = "//textarea[contains(@class,'ace_text-input')]";
32
33
	/**
34
	 * create a text file with the given name.
35
	 * If name is not given the default is used.
36
	 *
37
	 * @param string $name
38
	 */
39
	public function createTextFile($name = null)
40
	{
41
		$this->find("xpath", $this->newFileFolderButtonXpath)->click();
42
		$this->find("xpath", $this->newTextFileButtonXpath)->click();
43
		if ($name !== null) {
44
			try {
45
				$this->fillField($this->newTextFileNameInputLabel, $name . "\n");
46
			} 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...
47
				//this seems to be a bug in MinkSelenium2Driver. Used to work fine in 1.3.1 but now throws this exception
48
				//actually all that we need does happen, so we just don't do anything
49
			}
50
		}
51
	}
52
53
	/**
54
	 * finds the textarea field to use for editing a text file
55
	 *
56
	 * @throws ElementNotFoundException
57
	 * @return \Behat\Mink\Element\NodeElement
58
	 */
59
	public function findTextFileEditField() {
60
		$textField = $this->find(
61
			"xpath", $this->textFileEditXpath
62
		);
63
		if ($textField === null) {
64
			throw new ElementNotFoundException("could not find textarea field");
65
		}
66
		return $textField;
67
	}
68
69
	/**
70
	 * type text into the text area
71
	 *
72
	 * @param string $text
73
	 * @return void
74
	 */
75
	public function typeIntoTextFile($text) {
76
		$textField = $this->findTextFileEditField();
77
		$textField->setValue($text);
78
	}
79
80
	public function waitTillEditorIsLoaded($timeout_msec = STANDARDUIWAITTIMEOUTMILLISEC)
81
	{
82
		$this->waitTillElementIsNotNull($this->textFileEditXpath, $timeout_msec);
83
	}
84
85
}