Run cross-browser tests programmatically to compare layouts across multiple browser environments.
For web-app based cross-browser tests, see Compare the Layout in Different Browsers via web
.
If you want to check a layout on multiple different browsers, you have two options: a Selenium-based Crossbrowser test or a URL-based Crossbrowser test.
Selenium-based Crossbrowser Test If you need to interact with the website (e.g. to reach a certain state), the Selenium-based test is the right choice.
You need to specify the platform(s) and browsers on which you want to run the selenium test on.
The function in the example executeTestInBrowser does all the interaction with the website and creates states at each point in time you want to later check for possible differences in layout.
1
2
3
Platform platform = new Platform(PlatformType.WINDOWS , "11" , "64" );
BrowserSessionId chromeSessionId = executeTestInBrowser(new Browser(BrowserType.CHROME , "126" , platform));
BrowserSessionId firefoxSessionId = executeTestInBrowser(new Browser(BrowserType.FIREFOX , "124" , platform));
1
2
3
let platform = new Platform (PlatformType .WINDOWS , "11" , "64" );
let chromeSessionId = await executeTestInBrowser (new Browser (BrowserType .CHROME , "126" , platform ));
let firefoxSessionId = await executeTestInBrowser (new Browser (BrowserType .FIREFOX , "124" , platform ));
You can now run the comparison and wait for the result
1
2
3
4
5
6
7
TestRun testRun = webmateSession.testMgmt .startExecutionWithBuilder (ExpeditionComparisonSpec.ExpeditionComparisonCheckBuilder .builder (
"Example cross-browser comparison" ,
new OfflineExpeditionSpec(chromeSessionId),
ImmutableList.of (new OfflineExpeditionSpec(firefoxSessionId))
));
TestRunInfo testRunInfo = testRun.waitForCompletion ();
1
2
3
4
5
6
7
let testRun = webmateSession .testMgmt .startExecutionWithBuilder (ExpeditionComparisonSpec .ExpeditionComparisonCheckBuilder .builder (
"Example cross-browser comparison" ,
new OfflineExpeditionSpec (chromeSessionId ),
[new OfflineExpeditionSpec (firefoxSessionId )]
));
let testRunInfo = testRun .waitForCompletion ();
All code:
1
2
3
4
5
6
7
8
9
10
11
Platform platform = new Platform(PlatformType.WINDOWS , "11" , "64" );
BrowserSessionId chromeSessionId = executeTestInBrowser(new Browser(BrowserType.CHROME , "126" , platform));
BrowserSessionId firefoxSessionId = executeTestInBrowser(new Browser(BrowserType.FIREFOX , "124" , platform));
TestRun testRun = webmateSession.testMgmt .startExecutionWithBuilder (ExpeditionComparisonSpec.ExpeditionComparisonCheckBuilder .builder (
"Example cross-browser comparison" ,
new OfflineExpeditionSpec(chromeSessionId),
ImmutableList.of (new OfflineExpeditionSpec(firefoxSessionId))
));
TestRunInfo testRunInfo = testRun.waitForCompletion ();
1
2
3
4
5
6
7
8
9
10
11
let platform = new Platform (PlatformType .WINDOWS , "11" , "64" );
let chromeSessionId = await executeTestInBrowser (new Browser (BrowserType .CHROME , "126" , platform ));
let firefoxSessionId = await executeTestInBrowser (new Browser (BrowserType .FIREFOX , "124" , platform ));
let testRun = webmateSession .testMgmt .startExecutionWithBuilder (ExpeditionComparisonSpec .ExpeditionComparisonCheckBuilder .builder (
"Example cross-browser comparison" ,
new OfflineExpeditionSpec (chromeSessionId ),
[new OfflineExpeditionSpec (firefoxSessionId )]
));
let testRunInfo = testRun .waitForCompletion ();
URL Based Crossbrowser Test In the Selenium-based cross-browser test you implemented the interaction with the website yourself.
You can also use the URL-based cross-browser test if you do not need further interaction with the website and only need the browsers to visit the URLs.
First you have to create the reference browser and the browser(s) to compare
1
2
3
4
5
6
Browser referenceBrowser = new Browser(BrowserType.FIREFOX , "124" , new Platform(PlatformType.WINDOWS , "11" , "64" ));
List< Browser> crossBrowsers = ImmutableList.of (
new Browser(BrowserType.CHROME , "126" , new Platform(PlatformType.WINDOWS , "11" , "64" )),
new Browser(BrowserType.INTERNET_EXPLORER , "11" , new Platform(PlatformType.WINDOWS , "11" , "64" ))
);
1
2
3
4
5
6
7
let referenceBrowser = new Browser (BrowserType .FIREFOX , "124" , new Platform (PlatformType .WINDOWS , "11" , "64" ));
let crossBrowsers = [
new Browser (BrowserType .CHROME , "126" , new Platform (PlatformType .WINDOWS , "11" , "64" )),
new Browser (BrowserType .INTERNET_EXPLORER , "11" , new Platform (PlatformType .WINDOWS , "11" , "64" ))
];
Now you can specify the list of URL(s) that the browser(s) should visit
1
2
3
4
List< URI> urls = ImmutableList.of (
URI.create ("http://www.examplepage.org/version/future" ),
URI.create ("http://www.examplepage.org" )
);
1
2
3
4
let urls = [
"http://www.examplepage.org/version/future" ,
"http://www.examplepage.org"
];
Similar to Selenium-based cross-browser tests, you can now run the comparison and wait for the result
1
2
3
4
5
6
7
8
9
10
TestRun testRun = webmateSession.testMgmt .startExecutionWithBuilder (
ExpeditionComparisonSpec.ExpeditionComparisonCheckBuilder .builder (
"CrossBrowser Test via SDK" ,
ExpeditionSpecFactory.makeUrlListExpeditionSpec (urls, referenceBrowser),
crossBrowsers.stream ()
.map (browser -> ExpeditionSpecFactory.makeUrlListExpeditionSpec (urls, browser))
.collect (Collectors.toList ())
));
TestRunInfo info = testRun.waitForCompletion ();
1
2
3
4
5
6
7
let testExecutionSpecBuilder = ExpeditionComparisonCheckBuilder .builder (
"CrossBrowser Test via SDK" ,
ExpeditionSpecFactory .makeUrlListExpeditionSpec (urls , referenceBrowser ),
[...(crossBrowsers .map (browser => ExpeditionSpecFactory .makeUrlListExpeditionSpec (urls , browser )))]
);
let testRun = await webmateSession .testMgmt .startExecutionWithBuilder (testExecutionSpecBuilder ).toPromise ();
All code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Browser referenceBrowser = new Browser(BrowserType.FIREFOX , "124" , new Platform(PlatformType.WINDOWS , "11" , "64" ));
List< Browser> crossBrowsers = ImmutableList.of (
new Browser(BrowserType.CHROME , "126" , new Platform(PlatformType.WINDOWS , "11" , "64" )),
new Browser(BrowserType.INTERNET_EXPLORER , "11" , new Platform(PlatformType.WINDOWS , "11" , "64" ))
);
List< URI> urls = ImmutableList.of (
URI.create ("http://www.examplepage.org/version/future" ),
URI.create ("http://www.examplepage.org" )
);
TestRun testRun = webmateSession.testMgmt .startExecutionWithBuilder (
ExpeditionComparisonSpec.ExpeditionComparisonCheckBuilder .builder (
"CrossBrowser Test via SDK" ,
ExpeditionSpecFactory.makeUrlListExpeditionSpec (urls, referenceBrowser),
crossBrowsers.stream ()
.map (browser -> ExpeditionSpecFactory.makeUrlListExpeditionSpec (urls, browser))
.collect (Collectors.toList ())
));
TestRunInfo info = testRun.waitForCompletion ();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
let referenceBrowser = new Browser (BrowserType .FIREFOX , "124" , new Platform (PlatformType .WINDOWS , "11" , "64" ));
let crossBrowsers = [
new Browser (BrowserType .CHROME , "126" , new Platform (PlatformType .WINDOWS , "11" , "64" )),
new Browser (BrowserType .INTERNET_EXPLORER , "11" , new Platform (PlatformType .WINDOWS , "11" , "64" ))
];
let urls = [
"http://www.examplepage.org/version/future" ,
"http://www.examplepage.org"
];
let testExecutionSpecBuilder = ExpeditionComparisonCheckBuilder .builder (
"CrossBrowser Test via SDK" ,
ExpeditionSpecFactory .makeUrlListExpeditionSpec (urls , referenceBrowser ),
[...(crossBrowsers .map (browser => ExpeditionSpecFactory .makeUrlListExpeditionSpec (urls , browser )))]
);
let testRun = await webmateSession .testMgmt .startExecutionWithBuilder (testExecutionSpecBuilder ).toPromise ();
View results You can find the test results in the TestLab by clicking on your test run.
The top bar contains the number of differences across the browsers were found by the test (1), followed by the list of URLs and browsers (2).
You can select the URLs for which you want to view the results, if you applied the test on multiple URLs (3).
Below that you see a side-by-side comparison of the two browsers and if you selected multiple browsers to compare you can choose which one to display by clicking on the browser and choose one in the dropdown menu.
In the right sidebar there is the list of differences between the two views (1). Moving the cursor over an item in the list will highlight the corresponding elements in the browser views (2).
Clicking on an item in the list will highlight it permanently and show a box with more details about the difference at the bottom (3).