Skip to content

Commit 8c17625

Browse files
authored
Merge pull request #855 from seleniumbase/support-for-protractor-migration
Add support for migrating from Protractor to SeleniumBase
2 parents f781e98 + 94bba05 commit 8c17625

File tree

7 files changed

+157
-0
lines changed

7 files changed

+157
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## Support for migrating from Protractor to SeleniumBase
2+
3+
🔵 The Protractor/Angular tests from [github.com/angular/protractor/tree/master/example](https://github.com/angular/protractor/tree/master/example) have been migrated to SeleniumBase and placed in this directory.
4+
5+
✅ Here's a test run with ``pytest`` using ``--reuse-session`` mode and Chromium ``--guest`` mode:
6+
7+
```bash
8+
$ pytest --rs -v --guest
9+
# ======================== test session starts ======================== #
10+
platform darwin -- Python 3.9.2, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
11+
metadata: {'Python': '3.9.2', 'Platform': 'macOS-10.14.6-x86_64-i386-64bit', 'Packages': {'pytest': '6.2.3', 'py': '1.10.0', 'pluggy': '0.13.1'}, 'Plugins': {'html': '2.0.1', 'rerunfailures': '9.1.1', 'xdist': '2.2.1', 'metadata': '1.11.0', 'ordering': '0.6', 'forked': '1.3.0', 'seleniumbase': '1.59.6'}}
12+
rootdir: /Users/michael/github/SeleniumBase/examples, configfile: pytest.ini
13+
plugins: html-2.0.1, rerunfailures-9.1.1, xdist-2.2.1, metadata-1.11.0, ordering-0.6, forked-1.3.0, seleniumbase-1.59.6
14+
collected 4 items
15+
16+
example_test.py::AngularJSHomePageTests::test_greet_user PASSED
17+
example_test.py::AngularJSHomePageTests::test_todo_list PASSED
18+
input_test.py::AngularMaterialInputTests::test_invalid_input PASSED
19+
mat_paginator_test.py::AngularMaterialPaginatorTests::test_pagination PASSED
20+
21+
# ======================== 4 passed in 10.16s ======================== #
22+
```
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
describe('angularjs homepage', function() {
2+
it('should greet the named user', function() {
3+
browser.get('http://www.angularjs.org');
4+
5+
element(by.model('yourName')).sendKeys('Julie');
6+
7+
var greeting = element(by.binding('yourName'));
8+
9+
expect(greeting.getText()).toEqual('Hello Julie!');
10+
});
11+
12+
describe('todo list', function() {
13+
var todoList;
14+
15+
beforeEach(function() {
16+
browser.get('http://www.angularjs.org');
17+
18+
todoList = element.all(by.repeater('todo in todoList.todos'));
19+
});
20+
21+
it('should list todos', function() {
22+
expect(todoList.count()).toEqual(2);
23+
expect(todoList.get(1).getText()).toEqual('build an AngularJS app');
24+
});
25+
26+
it('should add a todo', function() {
27+
var addTodo = element(by.model('todoList.todoText'));
28+
var addButton = element(by.css('[value="add"]'));
29+
30+
addTodo.sendKeys('write a protractor test');
31+
addButton.click();
32+
33+
expect(todoList.count()).toEqual(3);
34+
expect(todoList.get(2).getText()).toEqual('write a protractor test');
35+
});
36+
});
37+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from seleniumbase import BaseCase
2+
3+
4+
class AngularJSHomePageTests(BaseCase):
5+
6+
def test_greet_user(self):
7+
self.open("http://www.angularjs.org")
8+
self.type('[ng-model="yourName"]', "Julie")
9+
self.assert_text("Hello Julie!", "h1.ng-binding")
10+
11+
def test_todo_list(self):
12+
self.open("http://www.angularjs.org")
13+
todo_selector = '[ng-repeat="todo in todoList.todos"]'
14+
# Verify that the todos are listed
15+
todos = self.find_visible_elements(todo_selector)
16+
self.assert_equal(len(todos), 2)
17+
self.assert_equal(todos[1].text, "build an AngularJS app")
18+
# Verify adding a new todo
19+
self.type('[ng-model="todoList.todoText"]', "write a protractor test")
20+
self.click('[value="add"]')
21+
todos = self.find_visible_elements(todo_selector)
22+
self.assert_equal(len(todos), 3)
23+
self.assert_equal(todos[2].text, "write a protractor test")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
describe('angular-material input component page', function() {
2+
const EC = protractor.ExpectedConditions;
3+
4+
it('Should change input component value', async() => {
5+
await browser.get('https://material.angular.io/components/input/examples');
6+
7+
await browser.wait(EC.elementToBeClickable($('.mat-button-wrapper > .mat-icon')), 5000);
8+
9+
const emailInputField = $$('#mat-input-1').get(1);
10+
11+
await emailInputField.sendKeys('invalid');
12+
13+
expect($('mat-error').isPresent()).toBe(true);
14+
});
15+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from seleniumbase import BaseCase
2+
3+
4+
class AngularMaterialInputTests(BaseCase):
5+
6+
def test_invalid_input(self):
7+
# Test that there's an error for an invalid input
8+
self.open("https://material.angular.io/components/input/examples")
9+
self.assert_element(".mat-button-wrapper > .mat-icon")
10+
self.type("#mat-input-1", "invalid")
11+
self.assert_element("mat-error")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
describe('angular-material paginator component page', () => {
2+
const EC = protractor.ExpectedConditions;
3+
4+
beforeAll(async() => {
5+
await browser.get('https://material.angular.io/components/paginator/examples');
6+
7+
await browser.wait(EC.elementToBeClickable($('.mat-button-wrapper > .mat-icon')), 5000);
8+
});
9+
10+
it('Should navigate to next page', async() => {
11+
await $('button[aria-label=\'Next page\']').click();
12+
13+
await expect($('.mat-paginator-range-label').getAttribute('innerText')).toEqual('11 – 20 of 100');
14+
});
15+
16+
it('Should navigate to previous page', async() => {
17+
await $('button[aria-label=\'Previous page\']').click();
18+
19+
await expect($('.mat-paginator-range-label').getAttribute('innerText')).toEqual('1 – 10 of 100');
20+
});
21+
22+
it('Should change list length to 5 items per page', async() => {
23+
await $('mat-select > div').click();
24+
25+
const fiveItemsOption = $$('mat-option > .mat-option-text').first();
26+
27+
await fiveItemsOption.click();
28+
29+
await expect($('.mat-paginator-range-label').getAttribute('innerText')).toEqual('1 – 5 of 100');
30+
});
31+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from seleniumbase import BaseCase
2+
3+
4+
class AngularMaterialPaginatorTests(BaseCase):
5+
6+
def test_pagination(self):
7+
self.open("https://material.angular.io/components/paginator/examples")
8+
self.assert_element(".mat-button-wrapper > .mat-icon")
9+
# Verify navigation to the next page
10+
self.click('button[aria-label="Next page"]')
11+
self.assert_text("11 – 20 of 100", ".mat-paginator-range-label")
12+
# Verify navigation to the previous page
13+
self.click('button[aria-label="Previous page"]')
14+
self.assert_text("1 – 10 of 100", ".mat-paginator-range-label")
15+
# Verify changed list length to 5 items per page
16+
self.click("mat-select > div")
17+
self.click("mat-option > .mat-option-text")
18+
self.assert_text("1 – 5 of 100", ".mat-paginator-range-label")

0 commit comments

Comments
 (0)