java.lang.Object
net.serenitybdd.screenplay.playwright.interactions.SetGeolocation
All Implemented Interfaces:
net.serenitybdd.core.SkipNested, net.serenitybdd.screenplay.Performable

public class SetGeolocation extends Object implements net.serenitybdd.screenplay.Performable
Set the browser's geolocation for testing location-based features.

Sample usage:

     // Set specific coordinates
     actor.attemptsTo(SetGeolocation.to(51.5074, -0.1278));  // London

     // Set with accuracy
     actor.attemptsTo(SetGeolocation.to(40.7128, -74.0060).withAccuracy(100));  // New York

     // Use predefined locations
     actor.attemptsTo(SetGeolocation.toNewYork());
     actor.attemptsTo(SetGeolocation.toLondon());
     actor.attemptsTo(SetGeolocation.toTokyo());

     // Clear geolocation
     actor.attemptsTo(SetGeolocation.clear());
 

Note: You must also grant the 'geolocation' permission for this to work. See GrantPermissions.

See Also:
  • Method Details

    • to

      public static SetGeolocation to(double latitude, double longitude)
      Set geolocation to the specified coordinates.
      Parameters:
      latitude - Latitude between -90 and 90
      longitude - Longitude between -180 and 180
    • clear

      public static SetGeolocation clear()
      Clear the geolocation override.
    • toNewYork

      public static SetGeolocation toNewYork()
      Set geolocation to New York City.
    • toLondon

      public static SetGeolocation toLondon()
      Set geolocation to London.
    • toTokyo

      public static SetGeolocation toTokyo()
      Set geolocation to Tokyo.
    • toSanFrancisco

      public static SetGeolocation toSanFrancisco()
      Set geolocation to San Francisco.
    • toSydney

      public static SetGeolocation toSydney()
      Set geolocation to Sydney.
    • toParis

      public static SetGeolocation toParis()
      Set geolocation to Paris.
    • withAccuracy

      public SetGeolocation withAccuracy(double accuracy)
      Set the accuracy of the geolocation in meters.
      Parameters:
      accuracy - Accuracy in meters (default is 0)
    • performAs

      public <T extends net.serenitybdd.screenplay.Actor> void performAs(T actor)
      Specified by:
      performAs in interface net.serenitybdd.screenplay.Performable