-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
924 lines (811 loc) · 27.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
<!DOCTYPE html>
<html>
<head>
<title>Protractor styleguide</title>
<link rel="stylesheet" href="node_modules/reveal.js/css/reveal.css">
<link rel="stylesheet" href="node_modules/reveal.js/css/theme/simple.css">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="node_modules/reveal.js/lib/css/zenburn.css">
<link rel="stylesheet" href="styles/slides.css">
</head>
<body>
<!-- lib scripts -->
<script src="node_modules/reveal.js/lib/js/head.min.js"></script>
<script src="node_modules/reveal.js/js/reveal.js"></script>
<div class="reveal">
<div class="slides">
<!-- INTRO -->
<section>
<div class="title">
<img src="images/protractor-logo.png">
<h1>Protractor styleguide</h1>
</div>
<div class="speaker">
<img class="avatar" src="images/carmen-profile.jpg">
<p>@CarmenPopoviciu</p>
</div>
<div class="speaker">
<img class="avatar" src="images/andres-profile.jpg">
<p>@andresdom</p>
</div>
</section>
<section>
<div>
<img class="avatar-full" src="images/carmen-profile.jpg">
</div>
</section>
<section data-background="images/sparkles.gif">
<p>@CarmenPopoviciu</p>
</section>
<section>
// TODO add image from work
</section>
<section>
//TODO add image with one cake
</section>
<section>
//TODO add image with 2 cakes
</section>
<section>
<div class="speaker">
<img class="avatar-full" src="images/andres-profile.jpg">
</div>
</section>
<section>
<p>@andresdom</p>
</section>
<section>
//TODO @andres add your intro
</section>
<section>
<div class="speaker">
// TODO @carmen add pic with teddyB
<img class="avatar-full" src="images/teddyB-profile.jpg">
</div>
</section>
<section>
<p>teddyB</p>
</section>
<section>
//TODO @carmen add funnies with teddyB
</section>
<!-- E2E GENERICS -->
<section>
<h2>E2E Testing</h2>
</section>
<section>
<h2>Why is it important?</h2>
<ul>
<li class="fragment">Tells you that everything is OK</li>
<li class="fragment">Prevents production incidents</li>
<li class="fragment">Checks the app from the user's perspective</li>
<li class="fragment">Manual testing is not a good idea</li>
</ul>
</section>
<section>
<h2>What do we e2e test?</h2>
<ul>
<li class="fragment">Major subpages or routes in the site</li>
<li class="fragment">Main user interaction flows</li>
<li class="fragment">Essential elements on a page</li>
</ul>
</section>
<!-- RULES -->
<section class="rules">
<h2>Protractor Styleguide</h2>
<p class="fragment">A set of rules and best practices for writing e2e tests with Protractor</p>
</section>
<section>
<h2>Protractor Styleguide</h2>
<ul class="no-bullet">
<li>Generic rules</li>
<li class="fragment">Project structure</li>
<li class="fragment">Locator strategies</li>
<li class="fragment">Page Objects</li>
<li class="fragment">Test suites</li>
</ul>
</section>
<!-- RULES-GENERIC -->
<section>
<h2>Protractor Styleguide</h2>
<ul class="no-bullet active">
<li class="current">Generic rules</li>
<li>Project structure</li>
<li>Locator strategies</li>
<li>Page Objects</li>
<li>Test suites</li>
</ul>
</section>
<!--don't cheat-->
<section>
<h2>Don't cheat on your tests</h2>
<p class="fragment">WHY: Tests are there for a reason. You'll only be cheating on yourself.</p>
</section>
<!--don't e2e what you can unit test-->
<section>
<h3>Don't e2e test what you can unit test</h3>
<p class="fragment">WHY: Unit tests are much faster than e2e tests</p>
</section>
<!--don't e2e what has unit tests-->
<section>
<h3>Don't e2e test what you already unit tested</h3>
<p class="fragment">WHY: This one should be pretty obvious ;)</p>
</section>
<!--don't e2e what has unit tests 2-->
<section>
<h3>Don't e2e test what you already unit tested</h3>
<p>WHY: Avoid duplicate tests</p>
</section>
<!-- RULES-PROJECT-STRUCTURE -->
<section>
<h2>Protractor Styleguide</h2>
<ul class="no-bullet active">
<li>Generic rules</li>
<li class="current">Project structure</li>
<li>Locator strategies</li>
<li>Page Objects</li>
<li>Test suites</li>
</ul>
</section>
<!--put all thests in a folder-->
<section>
<h3>Put all e2e test files in one dedicated folder</h3>
<div class="fragment">
<p>WHY:</p>
<ul>
<li>Easy to find</li>
<li>Separates them from unit tests</li>
<li>Cleaner folder structure</li>
</ul>
</div>
</section>
<section>
<pre>
<code class="javascript">
/* avoid */
|-- app
|-- home
home.module.js
home.controller.js
home.controller.spec.js
home.e2e.spec.js
home.page.js
|-- profile
profile.module.js
profile.controller.js
profile.directive.js
profile.controller.spec.js
profile.directive.page.js
profile.page.js
profile.e2e.spec.js
</code>
</pre>
</section>
<section>
<pre>
<code class="javascript">
/* recommended */
|-- app
|-- home
home.module.js
home.controller.js
|-- profile
profile.module.js
profile.controller.js
profile.directive.js
|-- test
|-- unit
|-- ...
|-- e2e
|-- home
homePageObject.js
home.spec.js
|-- profile
profilePageObject.js
profile.spec.js
</code>
</pre>
</section>
<section>
<pre>
<code class="javascript">
/* recommended */
|-- app
|-- home
home.module.js
home.controller.js
home.controller.spec.js
|-- e2e
homePageObject.js
home.spec.js
|-- profile
profile.module.js
profile.controller.js
profile.directive.js
profile.controller.spec.js
profile.directive.spec.js
|-- e2e
profilePageObject.js
profile.spec.js
</code>
</pre>
</section>
<!--use one configuration file-->
<section>
<h2>Use one configuration file</h2>
<div class="fragment">
<p>WHY:</p>
<ul>
<li>Use your build tool to setup different configurations</li>
<li>Avoid duplicate configuration code</li>
</ul>
</div>
</section>
<section>
<pre>
<code class="javascript">
/* avoid */
protractor.conf.local.js
protractor.conf.dev.js
protractor.conf.test.js
.....
</code>
</pre>
</section>
<section>
<pre>
<code class="javascript">
/* recommended */
/* protractor.conf.js */
exclude: [],
multiCapabilities: [{
browserName: 'chrome',
shardTestFiles: true,
maxInstances: 3
}],
allScriptsTimeout: 11000,
getPageTimeout: 10000,
framework: 'jasmine',
jasmineNodeOpts: {
isVerbose: false,
showColors: true,
includeStackTrace: false,
defaultTimeoutInterval: 40000
}
</code>
</pre>
</section>
<section>
<pre>
<code class="javascript">
/* recommended */
/* Gruntfile.js */
// grunt-protractor-coverage config
e2e.local: {
options: {
args: {
baseUrl: local_base_url,
seleniumAddress: local_selenium_address,
specs: ['..../**/*.spec.js']
}
}
},
e2e.dev: {
options: {
args: {
baseUrl: dev_base_url,
seleniumAddress: dev_selenium_address,
specs: ['..../**/*.spec.js']
}
}
}
</code>
</pre>
</section>
<!-- RULES-LOCATOR-STRATEGIES -->
<section>
<h2>Protractor Styleguide</h2>
<ul class="no-bullet active">
<li>Generic rules</li>
<li>Project structure</li>
<li class="current">Locator strategies</li>
<li>Page Objects</li>
<li>Test suites</li>
</ul>
</section>
<!--use protractor locators-->
<section>
<h3>Prefer protractor locators when possible</h3>
<div class="fragment">
<p>WHY:</p>
<ul>
<li>Access elements easier</li>
<li>Code is less likely to change than other markup</li>
<li>More readable locators</li>
</ul>
</div>
</section>
<section>
<pre>
<code class="html">
<ul class="red">
<li>{{color.name}}</li>
<li>{{color.shade}}</li>
<li>{{color.code}}</li>
</ul>
</code>
</pre>
<pre>
<code class="javascript">
/* avoid */
var nameElem = element.all(by.css('.red li')).get(0);
</code>
</pre>
</section>
<section>
<pre>
<code class="html">
<ul class="red">
<li>{{color.name}}</li>
<li>{{color.shade}}</li>
<li>{{color.code}}</li>
</ul>
</code>
</pre>
<pre>
<code class="javascript">
/* recommended */
var nameElem = element(by.binding('color.name'));
</code>
</pre>
</section>
<section>
<pre>
<code class="html">
<div class="details">
<div class="personal">
<input ng-model="person.name">
</div>
</div>
</code>
</pre>
<pre>
<code class="javascript">
/* avoid */
var nameElem = element.all(by.css('.details'))
.all(by.css('personal'))
.get(0);
</code>
</pre>
</section>
<section>
<pre>
<code class="html">
<div class="details">
<div class="personal">
<input ng-model="person.name">
</div>
</div>
</code>
</pre>
<pre>
<code class="javascript">
/* recommended */
var elem = element(by.model('person.name'));
</code>
</pre>
</section>
<!--use id and css-->
<section>
<h3>Prefer by.id and by.css when no protractor locators are available</h3>
<div class="fragment">
<p>WHY:</p>
<ul>
<li>Access elements easier</li>
<li>Select markup that is less likely to change</li>
<li>More readable locators</li>
</ul>
</div>
</section>
<!-- avoid text locators -->
<section>
<h3>Avoid text locators for text that changes frequently</h3>
<div class="fragment">
<p>WHY</p>
<ul>
<li>Text for buttons, links, and labels tends to change over time</li>
<li>Your tests should not break when you make minor text changes</li>
</ul>
</div>
</section>
<!--never use xpath-->
<section>
<h2>NEVER use xpath</h2>
<div class="fragment">
<p>WHY:</p>
<ul>
<li>Markup is very easily subject to change</li>
<li>Unreadable locator</li>
</ul>
</div>
</section>
<section>
<pre>
<code class="javascript">
/* avoid, source: stackoverflow */
var elem = element(by.xpath("//*@id="calc"]/form/section/section[2]/div/div/div[1]/div/div/div[3]/div[2]/div[2]/div[1]/div[1]/h3"));
</code>
</pre>
</section>
<!--never use xpath 2-->
<section>
<h2>NEVER use xpath</h2>
<div class="fragment">
<p>WHY:</p>
<ul>
<li>xpath is known to have performance issues</li>
<li>Unreadable locator</li>
</ul>
</div>
</section>
<section>
<pre>
<code class="javascript">
/* avoid */
// todo add example
</code>
</pre>
</section>
<!-- RULES-PAGE-OBJECTS -->
<section>
<h2>Protractor Styleguide</h2>
<ul class="no-bullet active">
<li>Generic rules</li>
<li>Project structure</li>
<li>Locator strategies</li>
<li class="current">Page Objects</li>
<li>Test suites</li>
</ul>
</section>
<!--use page objects-->
<section>
<h3>Use Page Objects to interact with the view under test</h3>
<div class="fragment">
<p>WHY:</p>
<ul>
<li>Encapsulate information about the elements on the page under test</li>
<li>They can be reused across multiple tests</li>
<li>Decouple the test logic from implementation details</li>
</ul>
</div>
</section>
<section>
<pre>
<code class="javascript">
/* avoid */
describe('Question page', function() {
it('should answer any question', function() {
var question = element(by.model('question.text'));
var answer = element(by.binding('answer'));
var button = element(by.css('.question-button'));
question.sendKeys("What is the purpose of meaning?");
button.click();
expect(answer.getText()).toEqual("Chocolate!");
});
});
</code>
</pre>
</section>
<section>
<pre>
<code class="javascript">
/* recommended */
/* question.page.js */
var QuestionPage = function() {
this.question = element(by.model('question.text'));
this.answer = element(by.binding('answer'));
this.button = element(by.className('question-button'));
this.ask = function(question) {
this.question.sendKeys(question);
this.button.click();
};
};
module.exports = UserPropertiesPage;
</code>
</pre>
</section>
<section>
<pre>
<code class="javascript">
/* recommended */
/* question.spec.js*/
var Question = require('./question.page');
describe('Question page', function() {
var question = new Question();
it('should ask any question', function() {
question.ask('What is the purpose of meaning?');
expect(question.answer.getText()).toEqual('Chocolate');
});
});
</code>
</pre>
</section>
<!--one page object per file-->
<section>
<h3>Declare one Page Object per file</h3>
<p class="fragment">WHY: Keeps code clean and makes things easy to find</p>
</section>
<!--single export-->
<section>
<h3>Use a single module.exports at the end of the Page Object file</h3>
<div class="fragment">
<p>WHY:</p>
<ul>
<li>One Page Object per file means there's only one class to export</li>
</ul>
</div>
</section>
<section>
<pre>
<code class="javascript">
/* avoid */
/* user-profile.page.js */
var UserProfilePage = function() {};
var UserSettingsPage = function() {};
module.exports = UserPropertiesPage;
module.exports = UserSettingsPage;
</code>
</pre>
</section>
<section>
<pre>
<code class="javascript">
/* recommended */
/* user-profile.page.js */
var UserProfilePage = function() {};
module.exports = UserPropertiesPage;
</code>
</pre>
</section>
<!--require all modules at the top-->
<section>
<h3>Require all the modules at the top</h3>
<div class="fragment">
<p>WHY:</p>
<ul>
<li>The module dependencies should be clear and easy to find</li>
</ul>
</div>
</section>
<section>
<pre>
<code class="javascript">
/* recommended */
/* user-properties.spec.js */
var UserPage = require('./user-properties.page');
var MenuPage = require('./menu.page');
var FooterPage = require('./footer.page');
describe('User properties page', function() {
...
});
</code>
</pre>
</section>
<!--create page object instances at the beginning-->
<section>
<h3>Instantiate all Page Objects at the beginning of the test suite</h3>
<div class="fragment">
<p>WHY:</p>
<ul>
<li>Separates dependencies from the test code</li>
<li>Makes the dependencies available to all specs of the suite</li>
</ul>
</div>
</section>
<section>
<pre>
<code>
/* recommended */
/* user-properties.spec.js */
var UserPage = require('./user-properties.page');
var MenuPage = require('./menu.page');
var FooterPage = require('./footer.page');
describe('User properties page', function() {
var user = new UserPage();
var menu = new MenuPage();
var footer = new FooterPage();
// specs
});
</code>
</pre>
</section>
<!--public elements in constructor-->
<section>
<h3>Declare all the Page Object public elements in the constructor</h3>
<div class="fragment">
<p>WHY:</p>
<ul>
<li>The user of the Page Object should have quick access to the available elements on a page</li>
</ul>
</div>
</section>
<section>
<pre>
<code class="html">
<form>
Name: <input type="text" ng-model="ctrl.user.name">
E-mail: <input type="text" ng-model="ctrl.user.email">
<button id="save-button">Save</button>
</form>
</code>
</pre>
<pre>
<code class="javascript">
/* avoid */
/* user-properties.page.js */
var name = element(by.model('ctrl.user.name'));
var email = element(by.model('ctrl.user.email'));
var saveButton = element(by.id('#save-button'));
var UserPropertiesPage = function() {
this.save = function() {
...
};
};
</code>
</pre>
</section>
<section>
<pre>
<code class="html">
<form>
Name: <input type="text" ng-model="ctrl.user.name">
E-mail: <input type="text" ng-model="ctrl.user.email">
<button id="save-button">Save</button>
</form>
</code>
</pre>
<pre>
<code class="javascript">
/* recommended */
/* user-properties.page.js */
var UserPropertiesPage = function() {
this.name = element(by.model('ctrl.user.name'));
this.email = element(by.model('ctrl.user.email'));
this.saveButton = element(by.id('#save-button'));
this.save = function() {
...
};
};
</code>
</pre>
</section>
<!-- page object functions -->
<section>
<h3>Declare Page Object functions for operations that require more that one step</h3>
<div class="fragment">
<p>WHY:</p>
<ul>
<li>Most elements are already exposed by the Page Object and can be used directly in the test</li>
<li>Doing otherwise will not have any added value</li>
</ul>
</div>
</section>
<section>
<pre style="height: 320px;">
<code class="javascript">
/* avoid */
/* user-properties.page.js */
var UserPropertiesPage = function() {
this.name = element(by.model('ctrl.user.name'));
this.saveButton = element(by.id('save-button'));
this.enterName = function(name) {
this.name.sendKeys(name);
};
};
</code>
</pre>
<pre>
<code class="javascript">
/* user-properties.spec.js*/
var UserPage = require('./user-properties.page');
describe('User properties page', function() {
var user = new UserPage();
it('should enable save button when user name entered', function() {
user.enterName('TeddyB');
expect(user.saveButton.isEnabled()).toBe(true);
});
});
</code>
</pre>
</section>
<section>
<pre>
<code class="javascript">
/* recommended */
/* user-properties.page.js */
var UserPropertiesPage = function() {
this.name = element(by.model('ctrl.user.name'));
this.saveButton = element(by.id('save-button'));
};
</code>
</pre>
<pre>
<code class="javascript">
/* user-properties.spec.js*/
var UserPage = require('./user-properties.page');
describe('User properties page', function() {
var user = new UserPage();
it('should enable save button when user name entered', function() {
user.name.sendKeys('TeddyB');
expect(user.saveButton.isEnabled()).toBe(true);
});
});
</code>
</pre>
</section>
<!-- no assertions in page objects -->
<section>
<h3>Don't make any assertions in your Page Objects</h3>
<div class="fragment">
<p>WHY:</p>
<ul>
<li>It is the responsibility of the test to do all the assertions</li>
<li>A reader of the test should be able to understand the behavior of the application by
looking at the test only
</li>
</ul>
</div>
</section>
<!-- mini page objects -->
<section>
<h3>Add Page Object wrappers for directives, dialogs, and common elements</h3>
<div class="fragment">
<p>WHY</p>
<ul>
<li>You can use them in multiple tests</li>
<li>Avoid code duplication</li>
<li>When the directive changes you only need to change the wrapper once</li>
</ul>
</div>
</section>
<!-- RULES-TEST-SUITES -->
<section>
<h2>Protractor Styleguide</h2>
<ul class="no-bullet active">
<li>Generic rules</li>
<li>Project structure</li>
<li>Locator strategies</li>
<li>Page Objects</li>
<li class="current">Test suites</li>
</ul>
</section>
<!--use jasmine 2-->
<section>
<h2>Use Jasmine 2</h2>
<div class="fragment">
<p>WHY:</p>
<ul>
<li>You can use <strong>beforeAll</strong> and
<strong>afterAll</strong></li>
<li>You can filter tests by name</li>
</ul>
</div>
</section>
<!--make your suites independent-->
<section>
<h3>Make your tests independent at least at the file level</h3>
<div class="fragment">
<p>WHY:</p>
<ul>
<li>You can run tests in parallel with sharding</li>
<li>The execution order is not guaranteed</li>
<li>You can run suites in isolation</li>
</ul>
</div>
</section>
</div>
</div>
<!-- reveal.js initialization -->
<script src="reveal-config.js"></script>
</body>
</html>