-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMultiBrowserTests.cs
More file actions
54 lines (44 loc) · 2.86 KB
/
MultiBrowserTests.cs
File metadata and controls
54 lines (44 loc) · 2.86 KB
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
using Lombiq.Tests.UI.Attributes;
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Services;
using OpenQA.Selenium;
using Shouldly;
using System.Threading.Tasks;
using Xunit;
namespace Lombiq.Tests.UI.Samples.Tests;
// Up until now, all of our tests were run via Chrome. However, it's important that you can run tests with any of the
// other supported browsers too, even running a test with all of them at once! This class shows you how.
public class MultiBrowserTests : UITestBase
{
public MultiBrowserTests(ITestOutputHelper testOutputHelper)
: base(testOutputHelper)
{
}
// Remember that back in BasicTests we had AnonymousHomePageShouldExist()? We have similar super-simple tests here,
// just demonstrating how to drive different browsers.
// First, let's see a test using Firefox. While the default browser is Chrome if you don't set anything, all
// ExecuteTest* methods can also accept a browser, if you want to use a different one.
[Fact]
public Task AnonymousHomePageShouldExistWithFirefox() =>
ExecuteTestAfterSetupAsync(NavbarIsCorrect, Browser.Firefox);
// This test is now marked not with the [Fact] attribute but [Theory]. With it, you can create so-called data-driven
// tests. [Chrome], [Firefox] are input parameters of the test, and thus in effect, you have now two tests:
// AnonymousHomePageShouldExistMultiBrowser once with Chrome and once with Firefox. See here for more info:
// https://andrewlock.net/creating-parameterised-tests-in-xunit-with-inlinedata-classdata-and-memberdata/.
// Note that all browsers will be automatically installed (as isolated instances just used for testing) with the
// specific version pinned by the UI Testing Toolbox. So, you don't need to preinstall them, nor do you have to
// worry about browser updates breaking your tests.
// [Edge] is also available for Microsoft Edge. However, due to the Edge driver's or the browser's download URL, and
// thus the automatic installation, routinely breaking (as of writing this, most recently:
// https://github.com/SeleniumHQ/selenium/issues/16055), we don't use it, nor do we recommend using it frequently.
[Theory, Chrome, Firefox]
public Task AnonymousHomePageShouldExistMultiBrowser(Browser browser) =>
ExecuteTestAfterSetupAsync(NavbarIsCorrect, browser);
// You can also set the browser for all tests at once in UITestBase. Check it out: Where there's some default config
// now, you could also have the following code, for example:
//// configuration.BrowserConfiguration.Browser = Browser.Firefox;
private static void NavbarIsCorrect(UITestContext context) =>
context.Get(By.ClassName("navbar-brand")).Text.ShouldBe("Lombiq's OSOCE - UI Testing");
}
// END OF TRAINING SECTION: Multi-browser tests.
// NEXT STATION: Head over to Tests/BasicVisualVerificationTests.cs.