Skip to content

Commit

Permalink
Merge branch '2.0' of github.com:Modelizer/Laravel-Selenium into 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Modelizer committed Apr 4, 2018
2 parents ceb2402 + 38864a6 commit 3dfcd00
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
24 changes: 15 additions & 9 deletions src/Services/InteractWithPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protected function scroll($amount)
*
* @param $value
* @param $element
*
* @return $this
*/
protected function select($value, $element)
Expand Down Expand Up @@ -110,12 +111,12 @@ protected function seePageIs($path)

public function getTextByTag($tag)
{
return $this->wd->findElement(WebDriverBy::tagName($tag))->getText();
return $this->wd->findElement(WebDriverBy::tagName($tag))->getText();
}

/**
* Type a value into a form input by that input name.
* Note: Type is an alias of typeBySelectorType
* Note: Type is an alias of typeBySelectorType.
*
* @param $value
* @param $name
Expand Down Expand Up @@ -144,8 +145,9 @@ public function type($value, $name, $clear = false)
* @param $name - value to use for the selector $type
* @param bool $clear - Whether or not to clear the input first on say an edit form
*
* @return $this
* @throws CannotFindElement
*
* @return $this
*/
private function typeBySelectorType($type, $value, $name, $clear = false)
{
Expand Down Expand Up @@ -270,28 +272,32 @@ protected function click($textOrId)
* If xpath is provided, will attempt to find by that first.
*
* @param null $name
* @return \Facebook\WebDriver\Remote\RemoteWebElement
*
* @throws CannotFindElement
*
* @return \Facebook\WebDriver\Remote\RemoteWebElement
*/
protected function findElement($name)
{

try {
return $this->wd->findElement(WebDriverBy::id($name));
} catch (\Exception $e) { }
} catch (\Exception $e) {
}

try {
return $this->wd->findElement(WebDriverBy::name($name));
} catch (\Exception $e) { }
} catch (\Exception $e) {
}

try {
return $this->wd->findElement(WebDriverBy::cssSelector($name));
} catch (\Exception $e) { }
} catch (\Exception $e) {
}

try {
return $this->wd->findElement(WebDriverBy::xpath($name));
} catch (\Exception $e) { }
} catch (\Exception $e) {
}

throw new CannotFindElement('Cannot find element: '.$value.' isn\'t visible on the page');
}
Expand Down
14 changes: 7 additions & 7 deletions tests/feature/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class FormTest extends SeleniumTestCase
{
/** @test */
function it_should_fill_input_fields()
public function it_should_fill_input_fields()
{
$this->visit()
->click('Form')
Expand All @@ -18,7 +18,7 @@ function it_should_fill_input_fields()
}

/** @test */
function it_should_type_information()
public function it_should_type_information()
{
$formInfo = [
'firstName' => 'Mohammed',
Expand All @@ -33,23 +33,23 @@ function it_should_type_information()
}

/** @test */
function it_should_type_email_by_name()
public function it_should_type_email_by_name()
{
$this->visit()
->click('Form')
->type('[email protected]', 'inputEmail-name');
}

/** @test */
function it_should_type_email_by_id()
public function it_should_type_email_by_id()
{
$this->visit()
->click('Form')
->typeById('[email protected]', 'inputEmail');
}

/** @test */
function it_should_type_by_css_selector()
public function it_should_type_by_css_selector()
{
$this->visit()
->click('Form')
Expand All @@ -58,7 +58,7 @@ function it_should_type_by_css_selector()
}

/** @test */
function it_should_type_information_and_press_a_button()
public function it_should_type_information_and_press_a_button()
{
$formInfo = [
'firstName' => 'Mohammed',
Expand All @@ -75,7 +75,7 @@ function it_should_type_information_and_press_a_button()
}

/** @test */
function it_should_submit_form()
public function it_should_submit_form()
{
$formInfo = [
'firstName' => 'Mohammed',
Expand Down
12 changes: 6 additions & 6 deletions tests/feature/InteractionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@
class InteractionTest extends SeleniumTestCase
{
/** @test */
function it_should_visit_page()
public function it_should_visit_page()
{
$this->visit();
}

/** @test */
function it_should_see_page_url()
public function it_should_see_page_url()
{
$this->visit('/about')
->seePageIs('/about');
}

/** @test */
function it_should_see_text_on_page()
public function it_should_see_text_on_page()
{
$this->visit()
->see('Laravel Selenium Test Helper');
}

/** @test */
function check_text_not_exists_on_page()
public function check_text_not_exists_on_page()
{
$this->visit()
->notSee('Bootstrap');
}

/** @test */
function it_should_click_link()
public function it_should_click_link()
{
$this->visit()
->click('Contact Us')
->see('Contact Us');
}

/** @test */
function it_should_scroll()
public function it_should_scroll()
{
$this->visit()
->click('About')
Expand Down

0 comments on commit 3dfcd00

Please sign in to comment.