How to use testAutolayout method of CancellingWKWebViewNavigationDelegate class

Best Swift-snapshot-testing code snippet using CancellingWKWebViewNavigationDelegate.testAutolayout

SnapshotTestingTests.swift

Source:SnapshotTestingTests.swift Github

copy

Full Screen

...76    _assertInlineSnapshot(matching: URL(string: "https://www.pointfree.co")!, as: .dump, with: """77    - https://www.pointfree.co78    """)79  }80  func testAutolayout() {81    #if os(iOS)82    let vc = UIViewController()83    vc.view.translatesAutoresizingMaskIntoConstraints = false84    let subview = UIView()85    subview.translatesAutoresizingMaskIntoConstraints = false86    vc.view.addSubview(subview)87    NSLayoutConstraint.activate([88      subview.topAnchor.constraint(equalTo: vc.view.topAnchor),89      subview.bottomAnchor.constraint(equalTo: vc.view.bottomAnchor),90      subview.leftAnchor.constraint(equalTo: vc.view.leftAnchor),91      subview.rightAnchor.constraint(equalTo: vc.view.rightAnchor),92      ])93    assertSnapshot(matching: vc, as: .image)94    #endif95  }96  func testDeterministicDictionaryAndSetSnapshots() {97    struct Person: Hashable { let name: String }98    struct DictionarySetContainer { let dict: [String: Int], set: Set<Person> }99    let set = DictionarySetContainer(100      dict: ["c": 3, "a": 1, "b": 2],101      set: [.init(name: "Brandon"), .init(name: "Stephen")]102    )103    assertSnapshot(matching: set, as: .dump)104    _assertInlineSnapshot(matching: set, as: .dump, with: """105    ▿ DictionarySetContainer106      ▿ dict: 3 key/value pairs107        ▿ (2 elements)108          - key: "a"109          - value: 1110        ▿ (2 elements)111          - key: "b"112          - value: 2113        ▿ (2 elements)114          - key: "c"115          - value: 3116      ▿ set: 2 members117        ▿ Person118          - name: "Brandon"119        ▿ Person120          - name: "Stephen"121    """)122  }123  func testCaseIterable() {124    enum Direction: String, CaseIterable {125      case up, down, left, right126      var rotatedLeft: Direction {127        switch self {128        case .up:    return .left129        case .down:  return .right130        case .left:  return .down131        case .right: return .up132        }133      }134    }135    assertSnapshot(136      matching: { $0.rotatedLeft },137      as: Snapshotting<Direction, String>.func(into: .description)138    )139  }140  func testCGPath() {141    #if os(iOS) || os(tvOS) || os(macOS)142    let path = CGPath.heart143    let osName: String144    #if os(iOS)145    osName = "iOS"146    #elseif os(tvOS)147    osName = "tvOS"148    #elseif os(macOS)149    osName = "macOS"150    #endif151    if !ProcessInfo.processInfo.environment.keys.contains("GITHUB_WORKFLOW") {152      assertSnapshot(matching: path, as: .image, named: osName)153    }154    if #available(iOS 11.0, OSX 10.13, tvOS 11.0, *) {155      assertSnapshot(matching: path, as: .elementsDescription, named: osName)156    }157    #endif158  }159  func testData() {160    let data = Data([0xDE, 0xAD, 0xBE, 0xEF])161    assertSnapshot(matching: data, as: .data)162  }163  func testEncodable() {164    struct User: Encodable { let id: Int, name: String, bio: String }165    let user = User(id: 1, name: "Blobby", bio: "Blobbed around the world.")166    if #available(iOS 11.0, macOS 10.13, tvOS 11.0, *) {167      assertSnapshot(matching: user, as: .json)168    }169    assertSnapshot(matching: user, as: .plist)170  }171  func testMixedViews() {172//    #if os(iOS) || os(macOS)173//    // NB: CircleCI crashes while trying to instantiate SKView.174//    if !ProcessInfo.processInfo.environment.keys.contains("GITHUB_WORKFLOW") {175//      let webView = WKWebView(frame: .init(x: 0, y: 0, width: 50, height: 50))176//      webView.loadHTMLString("🌎", baseURL: nil)177//178//      let skView = SKView(frame: .init(x: 50, y: 0, width: 50, height: 50))179//      let scene = SKScene(size: .init(width: 50, height: 50))180//      let node = SKShapeNode(circleOfRadius: 15)181//      node.fillColor = .red182//      node.position = .init(x: 25, y: 25)183//      scene.addChild(node)184//      skView.presentScene(scene)185//186//      let view = View(frame: .init(x: 0, y: 0, width: 100, height: 50))187//      view.addSubview(webView)188//      view.addSubview(skView)189//190//      assertSnapshot(matching: view, as: .image, named: platform)191//    }192//    #endif193  }194  func testMultipleSnapshots() {195    assertSnapshot(matching: [1], as: .dump)196    assertSnapshot(matching: [1, 2], as: .dump)197  }198  func testNamedAssertion() {199    struct User { let id: Int, name: String, bio: String }200    let user = User(id: 1, name: "Blobby", bio: "Blobbed around the world.")201    assertSnapshot(matching: user, as: .dump, named: "named")202  }203  func testNSBezierPath() {204    #if os(macOS)205    let path = NSBezierPath.heart206    if !ProcessInfo.processInfo.environment.keys.contains("GITHUB_WORKFLOW") {207      assertSnapshot(matching: path, as: .image, named: "macOS")208    }209    assertSnapshot(matching: path, as: .elementsDescription, named: "macOS")210    #endif211  }212  func testNSView() {213    #if os(macOS)214    let button = NSButton()215    button.bezelStyle = .rounded216    button.title = "Push Me"217    button.sizeToFit()218    if !ProcessInfo.processInfo.environment.keys.contains("GITHUB_WORKFLOW") {219      assertSnapshot(matching: button, as: .image)220      assertSnapshot(matching: button, as: .recursiveDescription)221    }222    #endif223  }224  225  func testNSViewWithLayer() {226    #if os(macOS)227    let view = NSView()228    view.frame = CGRect(x: 0.0, y: 0.0, width: 10.0, height: 10.0)229    view.wantsLayer = true230    view.layer?.backgroundColor = NSColor.green.cgColor231    view.layer?.cornerRadius = 5232    if !ProcessInfo.processInfo.environment.keys.contains("GITHUB_WORKFLOW") {233      assertSnapshot(matching: view, as: .image)234      assertSnapshot(matching: view, as: .recursiveDescription)235    }236    #endif237  }238  func testPrecision() {239    #if os(iOS) || os(macOS) || os(tvOS)240    #if os(iOS) || os(tvOS)241    let label = UILabel()242    #if os(iOS)243    label.frame = CGRect(origin: .zero, size: CGSize(width: 43.5, height: 20.5))244    #elseif os(tvOS)245    label.frame = CGRect(origin: .zero, size: CGSize(width: 98, height: 46))246    #endif247    label.backgroundColor = .white248    #elseif os(macOS)249    let label = NSTextField()250    label.frame = CGRect(origin: .zero, size: CGSize(width: 37, height: 16))251    label.backgroundColor = .white252    label.isBezeled = false253    label.isEditable = false254    #endif255    if !ProcessInfo.processInfo.environment.keys.contains("GITHUB_WORKFLOW") {256      label.text = "Hello."257      assertSnapshot(matching: label, as: .image(precision: 0.9), named: platform)258      label.text = "Hello"259      assertSnapshot(matching: label, as: .image(precision: 0.9), named: platform)260    }261    #endif262  }263  func testSCNView() {264//    #if os(iOS) || os(macOS) || os(tvOS)265//    // NB: CircleCI crashes while trying to instantiate SCNView.266//    if !ProcessInfo.processInfo.environment.keys.contains("GITHUB_WORKFLOW") {267//      let scene = SCNScene()268//269//      let sphereGeometry = SCNSphere(radius: 3)270//      sphereGeometry.segmentCount = 200271//      let sphereNode = SCNNode(geometry: sphereGeometry)272//      sphereNode.position = SCNVector3Zero273//      scene.rootNode.addChildNode(sphereNode)274//275//      sphereGeometry.firstMaterial?.diffuse.contents = URL(fileURLWithPath: String(#file), isDirectory: false)276//        .deletingLastPathComponent()277//        .appendingPathComponent("__Fixtures__/earth.png")278//279//      let cameraNode = SCNNode()280//      cameraNode.camera = SCNCamera()281//      cameraNode.position = SCNVector3Make(0, 0, 8)282//      scene.rootNode.addChildNode(cameraNode)283//284//      let omniLight = SCNLight()285//      omniLight.type = .omni286//      let omniLightNode = SCNNode()287//      omniLightNode.light = omniLight288//      omniLightNode.position = SCNVector3Make(10, 10, 10)289//      scene.rootNode.addChildNode(omniLightNode)290//291//      assertSnapshot(292//        matching: scene,293//        as: .image(size: .init(width: 500, height: 500)),294//        named: platform295//      )296//    }297//    #endif298  }299  func testSKView() {300//    #if os(iOS) || os(macOS) || os(tvOS)301//    // NB: CircleCI crashes while trying to instantiate SKView.302//    if !ProcessInfo.processInfo.environment.keys.contains("GITHUB_WORKFLOW") {303//      let scene = SKScene(size: .init(width: 50, height: 50))304//      let node = SKShapeNode(circleOfRadius: 15)305//      node.fillColor = .red306//      node.position = .init(x: 25, y: 25)307//      scene.addChild(node)308//309//      assertSnapshot(310//        matching: scene,311//        as: .image(size: .init(width: 50, height: 50)),312//        named: platform313//      )314//    }315//    #endif316  }317  func testTableViewController() {318    #if os(iOS)319    class TableViewController: UITableViewController {320      override func viewDidLoad() {321        super.viewDidLoad()322        self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")323      }324      override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {325        return 10326      }327      override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {328        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)329        cell.textLabel?.text = "\(indexPath.row)"330        return cell331      }332    }333    let tableViewController = TableViewController()334    assertSnapshot(matching: tableViewController, as: .image(on: .iPhoneSe))335    #endif336  }337  func testAssertMultipleSnapshot() {338    #if os(iOS)339    class TableViewController: UITableViewController {340      override func viewDidLoad() {341        super.viewDidLoad()342        self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")343      }344      override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {345        return 10346      }347      override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {348        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)349        cell.textLabel?.text = "\(indexPath.row)"350        return cell351      }352    }353    let tableViewController = TableViewController()354    assertSnapshots(matching: tableViewController, as: ["iPhoneSE-image" : .image(on: .iPhoneSe), "iPad-image" : .image(on: .iPadMini)])355    assertSnapshots(matching: tableViewController, as: [.image(on: .iPhoneX), .image(on: .iPhoneXsMax)])356    #endif357  }358  func testTraits() {359    #if os(iOS) || os(tvOS)360    if #available(iOS 11.0, tvOS 11.0, *) {361      class MyViewController: UIViewController {362        let topLabel = UILabel()363        let leadingLabel = UILabel()364        let trailingLabel = UILabel()365        let bottomLabel = UILabel()366        override func viewDidLoad() {367          super.viewDidLoad()368          self.navigationItem.leftBarButtonItem = .init(barButtonSystemItem: .add, target: nil, action: nil)369          self.view.backgroundColor = .white370          self.topLabel.text = "What's"371          self.leadingLabel.text = "the"372          self.trailingLabel.text = "point"373          self.bottomLabel.text = "?"374          self.topLabel.translatesAutoresizingMaskIntoConstraints = false375          self.leadingLabel.translatesAutoresizingMaskIntoConstraints = false376          self.trailingLabel.translatesAutoresizingMaskIntoConstraints = false377          self.bottomLabel.translatesAutoresizingMaskIntoConstraints = false378          self.view.addSubview(self.topLabel)379          self.view.addSubview(self.leadingLabel)380          self.view.addSubview(self.trailingLabel)381          self.view.addSubview(self.bottomLabel)382          NSLayoutConstraint.activate([383            self.topLabel.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),384            self.topLabel.centerXAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.centerXAnchor),385            self.leadingLabel.leadingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leadingAnchor),386            self.leadingLabel.trailingAnchor.constraint(lessThanOrEqualTo: self.view.safeAreaLayoutGuide.centerXAnchor),387//            self.leadingLabel.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.centerXAnchor),388            self.leadingLabel.centerYAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.centerYAnchor),389            self.trailingLabel.leadingAnchor.constraint(greaterThanOrEqualTo: self.view.safeAreaLayoutGuide.centerXAnchor),390            self.trailingLabel.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor),391            self.trailingLabel.centerYAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.centerYAnchor),392            self.bottomLabel.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor),393            self.bottomLabel.centerXAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.centerXAnchor),394            ])395        }396        override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {397          super.traitCollectionDidChange(previousTraitCollection)398          self.topLabel.font = .preferredFont(forTextStyle: .headline, compatibleWith: self.traitCollection)399          self.leadingLabel.font = .preferredFont(forTextStyle: .body, compatibleWith: self.traitCollection)400          self.trailingLabel.font = .preferredFont(forTextStyle: .body, compatibleWith: self.traitCollection)401          self.bottomLabel.font = .preferredFont(forTextStyle: .subheadline, compatibleWith: self.traitCollection)402          self.view.setNeedsUpdateConstraints()403          self.view.updateConstraintsIfNeeded()404        }405      }406      let viewController = MyViewController()407      #if os(iOS)408      assertSnapshot(matching: viewController, as: .image(on: .iPhoneSe), named: "iphone-se")409      assertSnapshot(matching: viewController, as: .image(on: .iPhone8), named: "iphone-8")410      assertSnapshot(matching: viewController, as: .image(on: .iPhone8Plus), named: "iphone-8-plus")411      assertSnapshot(matching: viewController, as: .image(on: .iPhoneX), named: "iphone-x")412      assertSnapshot(matching: viewController, as: .image(on: .iPhoneXr), named: "iphone-xr")413      assertSnapshot(matching: viewController, as: .image(on: .iPhoneXsMax), named: "iphone-xs-max")414      assertSnapshot(matching: viewController, as: .image(on: .iPadMini), named: "ipad-mini")415      assertSnapshot(matching: viewController, as: .image(on: .iPad9_7), named: "ipad-9-7")416      assertSnapshot(matching: viewController, as: .image(on: .iPad10_2), named: "ipad-10-2")417      assertSnapshot(matching: viewController, as: .image(on: .iPadPro10_5), named: "ipad-pro-10-5")418      assertSnapshot(matching: viewController, as: .image(on: .iPadPro11), named: "ipad-pro-11")419      assertSnapshot(matching: viewController, as: .image(on: .iPadPro12_9), named: "ipad-pro-12-9")420      assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPhoneSe), named: "iphone-se")421      assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPhone8), named: "iphone-8")422      assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPhone8Plus), named: "iphone-8-plus")423      assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPhoneX), named: "iphone-x")424      assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPhoneXr), named: "iphone-xr")425      assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPhoneXsMax), named: "iphone-xs-max")426      assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPadMini), named: "ipad-mini")427      assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPad9_7), named: "ipad-9-7")428      assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPad10_2), named: "ipad-10-2")429      assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPadPro10_5), named: "ipad-pro-10-5")430      assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPadPro11), named: "ipad-pro-11")431      assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPadPro12_9), named: "ipad-pro-12-9")432      assertSnapshot(matching: viewController, as: .image(on: .iPhoneSe(.portrait)), named: "iphone-se")433      assertSnapshot(matching: viewController, as: .image(on: .iPhone8(.portrait)), named: "iphone-8")434      assertSnapshot(matching: viewController, as: .image(on: .iPhone8Plus(.portrait)), named: "iphone-8-plus")435      assertSnapshot(matching: viewController, as: .image(on: .iPhoneX(.portrait)), named: "iphone-x")436      assertSnapshot(matching: viewController, as: .image(on: .iPhoneXr(.portrait)), named: "iphone-xr")437      assertSnapshot(matching: viewController, as: .image(on: .iPhoneXsMax(.portrait)), named: "iphone-xs-max")438      assertSnapshot(matching: viewController, as: .image(on: .iPadMini(.landscape)), named: "ipad-mini")439      assertSnapshot(matching: viewController, as: .image(on: .iPad9_7(.landscape)), named: "ipad-9-7")440      assertSnapshot(matching: viewController, as: .image(on: .iPad10_2(.landscape)), named: "ipad-10-2")441      assertSnapshot(matching: viewController, as: .image(on: .iPadPro10_5(.landscape)), named: "ipad-pro-10-5")442      assertSnapshot(matching: viewController, as: .image(on: .iPadPro11(.landscape)), named: "ipad-pro-11")443      assertSnapshot(matching: viewController, as: .image(on: .iPadPro12_9(.landscape)), named: "ipad-pro-12-9")444      assertSnapshot(matching: viewController, as: .image(on: .iPadMini(.landscape(splitView: .oneThird))), named: "ipad-mini-33-split-landscape")445      assertSnapshot(matching: viewController, as: .image(on: .iPadMini(.landscape(splitView: .oneHalf))), named: "ipad-mini-50-split-landscape")446      assertSnapshot(matching: viewController, as: .image(on: .iPadMini(.landscape(splitView: .twoThirds))), named: "ipad-mini-66-split-landscape")447      assertSnapshot(matching: viewController, as: .image(on: .iPadMini(.portrait(splitView: .oneThird))), named: "ipad-mini-33-split-portrait")448      assertSnapshot(matching: viewController, as: .image(on: .iPadMini(.portrait(splitView: .twoThirds))), named: "ipad-mini-66-split-portrait")449      assertSnapshot(matching: viewController, as: .image(on: .iPad9_7(.landscape(splitView: .oneThird))), named: "ipad-9-7-33-split-landscape")450      assertSnapshot(matching: viewController, as: .image(on: .iPad9_7(.landscape(splitView: .oneHalf))), named: "ipad-9-7-50-split-landscape")451      assertSnapshot(matching: viewController, as: .image(on: .iPad9_7(.landscape(splitView: .twoThirds))), named: "ipad-9-7-66-split-landscape")452      assertSnapshot(matching: viewController, as: .image(on: .iPad9_7(.portrait(splitView: .oneThird))), named: "ipad-9-7-33-split-portrait")453      assertSnapshot(matching: viewController, as: .image(on: .iPad9_7(.portrait(splitView: .twoThirds))), named: "ipad-9-7-66-split-portrait")454      assertSnapshot(matching: viewController, as: .image(on: .iPad10_2(.landscape(splitView: .oneThird))), named: "ipad-10-2-split-landscape")455      assertSnapshot(matching: viewController, as: .image(on: .iPad10_2(.landscape(splitView: .oneHalf))), named: "ipad-10-2-50-split-landscape")456      assertSnapshot(matching: viewController, as: .image(on: .iPad10_2(.landscape(splitView: .twoThirds))), named: "ipad-10-2-66-split-landscape")457      assertSnapshot(matching: viewController, as: .image(on: .iPad10_2(.portrait(splitView: .oneThird))), named: "ipad-10-2-33-split-portrait")458      assertSnapshot(matching: viewController, as: .image(on: .iPad10_2(.portrait(splitView: .twoThirds))), named: "ipad-10-2-66-split-portrait")459      460      assertSnapshot(matching: viewController, as: .image(on: .iPadPro10_5(.landscape(splitView: .oneThird))), named: "ipad-pro-10inch-33-split-landscape")461      assertSnapshot(matching: viewController, as: .image(on: .iPadPro10_5(.landscape(splitView: .oneHalf))), named: "ipad-pro-10inch-50-split-landscape")462      assertSnapshot(matching: viewController, as: .image(on: .iPadPro10_5(.landscape(splitView: .twoThirds))), named: "ipad-pro-10inch-66-split-landscape")463      assertSnapshot(matching: viewController, as: .image(on: .iPadPro10_5(.portrait(splitView: .oneThird))), named: "ipad-pro-10inch-33-split-portrait")464      assertSnapshot(matching: viewController, as: .image(on: .iPadPro10_5(.portrait(splitView: .twoThirds))), named: "ipad-pro-10inch-66-split-portrait")465      466      assertSnapshot(matching: viewController, as: .image(on: .iPadPro11(.landscape(splitView: .oneThird))), named: "ipad-pro-11inch-33-split-landscape")467      assertSnapshot(matching: viewController, as: .image(on: .iPadPro11(.landscape(splitView: .oneHalf))), named: "ipad-pro-11inch-50-split-landscape")468      assertSnapshot(matching: viewController, as: .image(on: .iPadPro11(.landscape(splitView: .twoThirds))), named: "ipad-pro-11inch-66-split-landscape")469      assertSnapshot(matching: viewController, as: .image(on: .iPadPro11(.portrait(splitView: .oneThird))), named: "ipad-pro-11inch-33-split-portrait")470      assertSnapshot(matching: viewController, as: .image(on: .iPadPro11(.portrait(splitView: .twoThirds))), named: "ipad-pro-11inch-66-split-portrait")471      472      assertSnapshot(matching: viewController, as: .image(on: .iPadPro12_9(.landscape(splitView: .oneThird))), named: "ipad-pro-12inch-33-split-landscape")473      assertSnapshot(matching: viewController, as: .image(on: .iPadPro12_9(.landscape(splitView: .oneHalf))), named: "ipad-pro-12inch-50-split-landscape")474      assertSnapshot(matching: viewController, as: .image(on: .iPadPro12_9(.landscape(splitView: .twoThirds))), named: "ipad-pro-12inch-66-split-landscape")475      assertSnapshot(matching: viewController, as: .image(on: .iPadPro12_9(.portrait(splitView: .oneThird))), named: "ipad-pro-12inch-33-split-portrait")476      assertSnapshot(matching: viewController, as: .image(on: .iPadPro12_9(.portrait(splitView: .twoThirds))), named: "ipad-pro-12inch-66-split-portrait")477      478      assertSnapshot(479        matching: viewController, as: .image(on: .iPhoneSe(.landscape)), named: "iphone-se-alternative")480      assertSnapshot(481        matching: viewController, as: .image(on: .iPhone8(.landscape)), named: "iphone-8-alternative")482      assertSnapshot(483        matching: viewController, as: .image(on: .iPhone8Plus(.landscape)), named: "iphone-8-plus-alternative")484      assertSnapshot(485        matching: viewController, as: .image(on: .iPhoneX(.landscape)), named: "iphone-x-alternative")486      assertSnapshot(487        matching: viewController, as: .image(on: .iPhoneXr(.landscape)), named: "iphone-xr-alternative")488      assertSnapshot(489        matching: viewController, as: .image(on: .iPhoneXsMax(.landscape)), named: "iphone-xs-max-alternative")490      assertSnapshot(491        matching: viewController, as: .image(on: .iPadMini(.portrait)), named: "ipad-mini-alternative")492      assertSnapshot(493        matching: viewController, as: .image(on: .iPad9_7(.portrait)), named: "ipad-9-7-alternative")494      assertSnapshot(495        matching: viewController, as: .image(on: .iPad10_2(.portrait)), named: "ipad-10-2-alternative")496      assertSnapshot(497        matching: viewController, as: .image(on: .iPadPro10_5(.portrait)), named: "ipad-pro-10-5-alternative")498      assertSnapshot(499        matching: viewController, as: .image(on: .iPadPro11(.portrait)), named: "ipad-pro-11-alternative")500      assertSnapshot(501        matching: viewController, as: .image(on: .iPadPro12_9(.portrait)), named: "ipad-pro-12-9-alternative")502      allContentSizes.forEach { name, contentSize in503          assertSnapshot(504            matching: viewController,505            as: .image(on: .iPhoneSe, traits: .init(preferredContentSizeCategory: contentSize)),506            named: "iphone-se-\(name)"507          )508      }509      #elseif os(tvOS)510      assertSnapshot(511        matching: viewController, as: .image(on: .tv), named: "tv")512      assertSnapshot(513        matching: viewController, as: .image(on: .tv4K), named: "tv4k")514      #endif515    }516    #endif517  }518  func testTraitsEmbeddedInTabNavigation() {519    #if os(iOS)520    if #available(iOS 11.0, *) {521      class MyViewController: UIViewController {522        let topLabel = UILabel()523        let leadingLabel = UILabel()524        let trailingLabel = UILabel()525        let bottomLabel = UILabel()526        override func viewDidLoad() {527          super.viewDidLoad()528          self.navigationItem.leftBarButtonItem = .init(barButtonSystemItem: .add, target: nil, action: nil)529          self.view.backgroundColor = .white530          self.topLabel.text = "What's"531          self.leadingLabel.text = "the"532          self.trailingLabel.text = "point"533          self.bottomLabel.text = "?"534          self.topLabel.translatesAutoresizingMaskIntoConstraints = false535          self.leadingLabel.translatesAutoresizingMaskIntoConstraints = false536          self.trailingLabel.translatesAutoresizingMaskIntoConstraints = false537          self.bottomLabel.translatesAutoresizingMaskIntoConstraints = false538          self.view.addSubview(self.topLabel)539          self.view.addSubview(self.leadingLabel)540          self.view.addSubview(self.trailingLabel)541          self.view.addSubview(self.bottomLabel)542          NSLayoutConstraint.activate([543            self.topLabel.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),544            self.topLabel.centerXAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.centerXAnchor),545            self.leadingLabel.leadingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leadingAnchor),546            self.leadingLabel.trailingAnchor.constraint(lessThanOrEqualTo: self.view.safeAreaLayoutGuide.centerXAnchor),547//            self.leadingLabel.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.centerXAnchor),548            self.leadingLabel.centerYAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.centerYAnchor),549            self.trailingLabel.leadingAnchor.constraint(greaterThanOrEqualTo: self.view.safeAreaLayoutGuide.centerXAnchor),550            self.trailingLabel.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor),551            self.trailingLabel.centerYAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.centerYAnchor),552            self.bottomLabel.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor),553            self.bottomLabel.centerXAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.centerXAnchor),554            ])555        }556        override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {557          super.traitCollectionDidChange(previousTraitCollection)558          self.topLabel.font = .preferredFont(forTextStyle: .headline, compatibleWith: self.traitCollection)559          self.leadingLabel.font = .preferredFont(forTextStyle: .body, compatibleWith: self.traitCollection)560          self.trailingLabel.font = .preferredFont(forTextStyle: .body, compatibleWith: self.traitCollection)561          self.bottomLabel.font = .preferredFont(forTextStyle: .subheadline, compatibleWith: self.traitCollection)562          self.view.setNeedsUpdateConstraints()563          self.view.updateConstraintsIfNeeded()564        }565      }566      let myViewController = MyViewController()567      let navController = UINavigationController(rootViewController: myViewController)568      let viewController = UITabBarController()569      viewController.setViewControllers([navController], animated: false)570      assertSnapshot(matching: viewController, as: .image(on: .iPhoneSe), named: "iphone-se")571      assertSnapshot(matching: viewController, as: .image(on: .iPhone8), named: "iphone-8")572      assertSnapshot(matching: viewController, as: .image(on: .iPhone8Plus), named: "iphone-8-plus")573      assertSnapshot(matching: viewController, as: .image(on: .iPhoneX), named: "iphone-x")574      assertSnapshot(matching: viewController, as: .image(on: .iPhoneXr), named: "iphone-xr")575      assertSnapshot(matching: viewController, as: .image(on: .iPhoneXsMax), named: "iphone-xs-max")576      assertSnapshot(matching: viewController, as: .image(on: .iPadMini), named: "ipad-mini")577      assertSnapshot(matching: viewController, as: .image(on: .iPad9_7), named: "ipad-9-7")578      assertSnapshot(matching: viewController, as: .image(on: .iPad10_2), named: "ipad-10-2")579      assertSnapshot(matching: viewController, as: .image(on: .iPadPro10_5), named: "ipad-pro-10-5")580      assertSnapshot(matching: viewController, as: .image(on: .iPadPro11), named: "ipad-pro-11")581      assertSnapshot(matching: viewController, as: .image(on: .iPadPro12_9), named: "ipad-pro-12-9")582      assertSnapshot(matching: viewController, as: .image(on: .iPhoneSe(.portrait)), named: "iphone-se")583      assertSnapshot(matching: viewController, as: .image(on: .iPhone8(.portrait)), named: "iphone-8")584      assertSnapshot(matching: viewController, as: .image(on: .iPhone8Plus(.portrait)), named: "iphone-8-plus")585      assertSnapshot(matching: viewController, as: .image(on: .iPhoneX(.portrait)), named: "iphone-x")586      assertSnapshot(matching: viewController, as: .image(on: .iPhoneXr(.portrait)), named: "iphone-xr")587      assertSnapshot(matching: viewController, as: .image(on: .iPhoneXsMax(.portrait)), named: "iphone-xs-max")588      assertSnapshot(matching: viewController, as: .image(on: .iPadMini(.landscape)), named: "ipad-mini")589      assertSnapshot(matching: viewController, as: .image(on: .iPad9_7(.landscape)), named: "ipad-9-7")590      assertSnapshot(matching: viewController, as: .image(on: .iPad10_2(.landscape)), named: "ipad-10-2")591      assertSnapshot(matching: viewController, as: .image(on: .iPadPro10_5(.landscape)), named: "ipad-pro-10-5")592      assertSnapshot(matching: viewController, as: .image(on: .iPadPro11(.landscape)), named: "ipad-pro-11")593      assertSnapshot(matching: viewController, as: .image(on: .iPadPro12_9(.landscape)), named: "ipad-pro-12-9")594      assertSnapshot(595        matching: viewController, as: .image(on: .iPhoneSe(.landscape)), named: "iphone-se-alternative")596      assertSnapshot(597        matching: viewController, as: .image(on: .iPhone8(.landscape)), named: "iphone-8-alternative")598      assertSnapshot(599        matching: viewController, as: .image(on: .iPhone8Plus(.landscape)), named: "iphone-8-plus-alternative")600      assertSnapshot(601        matching: viewController, as: .image(on: .iPhoneX(.landscape)), named: "iphone-x-alternative")602      assertSnapshot(603        matching: viewController, as: .image(on: .iPhoneXr(.landscape)), named: "iphone-xr-alternative")604      assertSnapshot(605        matching: viewController, as: .image(on: .iPhoneXsMax(.landscape)), named: "iphone-xs-max-alternative")606      assertSnapshot(607        matching: viewController, as: .image(on: .iPadMini(.portrait)), named: "ipad-mini-alternative")608      assertSnapshot(609        matching: viewController, as: .image(on: .iPad9_7(.portrait)), named: "ipad-9-7-alternative")610      assertSnapshot(611        matching: viewController, as: .image(on: .iPad10_2(.portrait)), named: "ipad-10-2-alternative")612      assertSnapshot(613        matching: viewController, as: .image(on: .iPadPro10_5(.portrait)), named: "ipad-pro-10-5-alternative")614      assertSnapshot(615        matching: viewController, as: .image(on: .iPadPro11(.portrait)), named: "ipad-pro-11-alternative")616      assertSnapshot(617        matching: viewController, as: .image(on: .iPadPro12_9(.portrait)), named: "ipad-pro-12-9-alternative")618    }619    #endif620  }621  func testCollectionViewsWithMultipleScreenSizes() {622    #if os(iOS)623    final class CollectionViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {624      let flowLayout: UICollectionViewFlowLayout = {625        let layout = UICollectionViewFlowLayout()626        layout.scrollDirection = .horizontal627        layout.minimumLineSpacing = 20628        return layout629      }()630      lazy var collectionView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)631      override func viewDidLoad() {632        super.viewDidLoad()633        view.backgroundColor = .white634        view.addSubview(collectionView)635        collectionView.backgroundColor = .white636        collectionView.dataSource = self637        collectionView.delegate = self638        collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell")639        collectionView.translatesAutoresizingMaskIntoConstraints = false640        NSLayoutConstraint.activate([641          collectionView.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor),642          collectionView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),643          collectionView.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor),644          collectionView.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.bottomAnchor)645        ])646        collectionView.reloadData()647      }648      override func viewDidLayoutSubviews() {649        super.viewDidLayoutSubviews()650        collectionView.collectionViewLayout.invalidateLayout()651      }652      override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {653        super.traitCollectionDidChange(previousTraitCollection)654        collectionView.collectionViewLayout.invalidateLayout()655      }656      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {657        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath)658        cell.contentView.backgroundColor = .orange659        return cell660      }661      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {662        return 20663      }664      func collectionView(665        _ collectionView: UICollectionView,666        layout collectionViewLayout: UICollectionViewLayout,667        sizeForItemAt indexPath: IndexPath668        ) -> CGSize {669        return CGSize(670          width: min(collectionView.frame.width - 50, 300),671          height: collectionView.frame.height672        )673      }674    }675    let viewController = CollectionViewController()676    assertSnapshots(matching: viewController, as: [677      "ipad": .image(on: .iPadPro12_9),678      "iphoneSe": .image(on: .iPhoneSe),679      "iphone8": .image(on: .iPhone8),680      "iphoneMax": .image(on: .iPhoneXsMax)681    ])682    #endif683  }684  func testTraitsWithView() {685    #if os(iOS)686    if #available(iOS 11.0, *) {687      let label = UILabel()688      label.font = .preferredFont(forTextStyle: .title1)689      label.adjustsFontForContentSizeCategory = true690      label.text = "What's the point?"691      allContentSizes.forEach { name, contentSize in692        assertSnapshot(693          matching: label,694          as: .image(traits: .init(preferredContentSizeCategory: contentSize)),695          named: "label-\(name)"696        )697      }698    }699    #endif700  }701  func testTraitsWithViewController() {702    #if os(iOS)703    let label = UILabel()704    label.font = .preferredFont(forTextStyle: .title1)705    label.adjustsFontForContentSizeCategory = true706    label.text = "What's the point?"707    let viewController = UIViewController()708    viewController.view.addSubview(label)709    label.translatesAutoresizingMaskIntoConstraints = false710    NSLayoutConstraint.activate([711      label.leadingAnchor.constraint(equalTo: viewController.view.layoutMarginsGuide.leadingAnchor),712      label.topAnchor.constraint(equalTo: viewController.view.layoutMarginsGuide.topAnchor),713      label.trailingAnchor.constraint(equalTo: viewController.view.layoutMarginsGuide.trailingAnchor)714    ])715    allContentSizes.forEach { name, contentSize in716      assertSnapshot(717        matching: viewController,718        as: .recursiveDescription(on: .iPhoneSe, traits: .init(preferredContentSizeCategory: contentSize)),719        named: "label-\(name)"720      )721    }722    #endif723  }724  func testUIBezierPath() {725    #if os(iOS) || os(tvOS)726    let path = UIBezierPath.heart727    let osName: String728    #if os(iOS)729    osName = "iOS"730    #elseif os(tvOS)731    osName = "tvOS"732    #endif733    if !ProcessInfo.processInfo.environment.keys.contains("GITHUB_WORKFLOW") {734      assertSnapshot(matching: path, as: .image, named: osName)735    }736    if #available(iOS 11.0, tvOS 11.0, *) {737      assertSnapshot(matching: path, as: .elementsDescription, named: osName)738    }739    #endif740  }741  func testUIView() {742    #if os(iOS)743    let view = UIButton(type: .contactAdd)744    assertSnapshot(matching: view, as: .image)745    assertSnapshot(matching: view, as: .recursiveDescription)746    #endif747  }748  func testUIViewControllerLifeCycle() {749    #if os(iOS)750    class ViewController: UIViewController {751      let viewDidLoadExpectation: XCTestExpectation752      let viewWillAppearExpectation: XCTestExpectation753      let viewDidAppearExpectation: XCTestExpectation754      let viewWillDisappearExpectation: XCTestExpectation755      let viewDidDisappearExpectation: XCTestExpectation756      init(viewDidLoadExpectation: XCTestExpectation,757           viewWillAppearExpectation: XCTestExpectation,758           viewDidAppearExpectation: XCTestExpectation,759           viewWillDisappearExpectation: XCTestExpectation,760           viewDidDisappearExpectation: XCTestExpectation){761        self.viewDidLoadExpectation = viewDidLoadExpectation762        self.viewWillAppearExpectation = viewWillAppearExpectation763        self.viewDidAppearExpectation = viewDidAppearExpectation764        self.viewWillDisappearExpectation = viewWillDisappearExpectation765        self.viewDidDisappearExpectation = viewDidDisappearExpectation766        super.init(nibName: nil, bundle: nil)767      }768      required init?(coder: NSCoder) {769        fatalError("init(coder:) has not been implemented")770      }771      override func viewDidLoad() {772        super.viewDidLoad()773        viewDidLoadExpectation.fulfill()774      }775      override func viewWillAppear(_ animated: Bool) {776        super.viewWillAppear(animated)777        viewWillAppearExpectation.fulfill()778      }779      override func viewDidAppear(_ animated: Bool) {780        super.viewDidAppear(animated)781        viewDidAppearExpectation.fulfill()782      }783      override func viewWillDisappear(_ animated: Bool) {784        super.viewWillDisappear(animated)785        viewWillDisappearExpectation.fulfill()786      }787      override func viewDidDisappear(_ animated: Bool) {788        super.viewDidDisappear(animated)789        viewDidDisappearExpectation.fulfill()790      }791    }792    let viewDidLoadExpectation = expectation(description: "viewDidLoad")793    let viewWillAppearExpectation = expectation(description: "viewWillAppear")794    let viewDidAppearExpectation = expectation(description: "viewDidAppear")795    let viewWillDisappearExpectation = expectation(description: "viewWillDisappear")796    let viewDidDisappearExpectation = expectation(description: "viewDidDisappear")797    viewWillAppearExpectation.expectedFulfillmentCount = 4798    viewDidAppearExpectation.expectedFulfillmentCount = 4799    viewWillDisappearExpectation.expectedFulfillmentCount = 4800    viewDidDisappearExpectation.expectedFulfillmentCount = 4801    let viewController = ViewController(802      viewDidLoadExpectation: viewDidLoadExpectation,803      viewWillAppearExpectation: viewWillAppearExpectation,804      viewDidAppearExpectation: viewDidAppearExpectation,805      viewWillDisappearExpectation: viewWillDisappearExpectation,806      viewDidDisappearExpectation: viewDidDisappearExpectation807    )808    assertSnapshot(matching: viewController, as: .image)809    assertSnapshot(matching: viewController, as: .image)810    wait(for: [811      viewDidLoadExpectation,812      viewWillAppearExpectation,813      viewDidAppearExpectation,814      viewWillDisappearExpectation,815      viewDidDisappearExpectation,816    ], timeout: 1.0, enforceOrder: true)817    #endif818  }819  func testCALayer() {820    #if os(iOS)821    let layer = CALayer()822    layer.frame = CGRect(x: 0, y: 0, width: 100, height: 100)823    layer.backgroundColor = UIColor.red.cgColor824    layer.borderWidth = 4.0825    layer.borderColor = UIColor.black.cgColor826    assertSnapshot(matching: layer, as: .image)827    #endif828  }829  func testCALayerWithGradient() {830    #if os(iOS)831    let baseLayer = CALayer()832    baseLayer.frame = CGRect(x: 0, y: 0, width: 100, height: 100)833    let gradientLayer = CAGradientLayer()834    gradientLayer.colors = [UIColor.red.cgColor, UIColor.yellow.cgColor]835    gradientLayer.frame = baseLayer.frame836    baseLayer.addSublayer(gradientLayer)837    assertSnapshot(matching: baseLayer, as: .image)838    #endif839  }840  func testViewControllerHierarchy() {841    #if os(iOS)842    let page = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal)843    page.setViewControllers([UIViewController()], direction: .forward, animated: false)844    let tab = UITabBarController()845    tab.viewControllers = [846      UINavigationController(rootViewController: page),847      UINavigationController(rootViewController: UIViewController()),848      UINavigationController(rootViewController: UIViewController()),849      UINavigationController(rootViewController: UIViewController()),850      UINavigationController(rootViewController: UIViewController())851    ]852    assertSnapshot(matching: tab, as: .hierarchy)853    #endif854  }855  func testURLRequest() {856    var get = URLRequest(url: URL(string: "https://www.pointfree.co/")!)857    get.addValue("pf_session={}", forHTTPHeaderField: "Cookie")858    get.addValue("text/html", forHTTPHeaderField: "Accept")859    get.addValue("application/json", forHTTPHeaderField: "Content-Type")860    assertSnapshot(matching: get, as: .raw, named: "get")861    assertSnapshot(matching: get, as: .curl, named: "get-curl")862    var getWithQuery = URLRequest(url: URL(string: "https://www.pointfree.co?key_2=value_2&key_1=value_1&key_3=value_3")!)863    getWithQuery.addValue("pf_session={}", forHTTPHeaderField: "Cookie")864    getWithQuery.addValue("text/html", forHTTPHeaderField: "Accept")865    getWithQuery.addValue("application/json", forHTTPHeaderField: "Content-Type")866    assertSnapshot(matching: getWithQuery, as: .raw, named: "get-with-query")867    assertSnapshot(matching: getWithQuery, as: .curl, named: "get-with-query-curl")868    var post = URLRequest(url: URL(string: "https://www.pointfree.co/subscribe")!)869    post.httpMethod = "POST"870    post.addValue("pf_session={\"user_id\":\"0\"}", forHTTPHeaderField: "Cookie")871    post.addValue("text/html", forHTTPHeaderField: "Accept")872    post.httpBody = Data("pricing[billing]=monthly&pricing[lane]=individual".utf8)873    assertSnapshot(matching: post, as: .raw, named: "post")874    assertSnapshot(matching: post, as: .curl, named: "post-curl")875    876    var postWithJSON = URLRequest(url: URL(string: "http://dummy.restapiexample.com/api/v1/create")!)877    postWithJSON.httpMethod = "POST"878    postWithJSON.addValue("application/json", forHTTPHeaderField: "Content-Type")879    postWithJSON.addValue("application/json", forHTTPHeaderField: "Accept")880    postWithJSON.httpBody = Data("{\"name\":\"tammy134235345235\", \"salary\":0, \"age\":\"tammy133\"}".utf8)881    assertSnapshot(matching: postWithJSON, as: .raw, named: "post-with-json")882    assertSnapshot(matching: postWithJSON, as: .curl, named: "post-with-json-curl")883    var head = URLRequest(url: URL(string: "https://www.pointfree.co/")!)884    head.httpMethod = "HEAD"885    head.addValue("pf_session={}", forHTTPHeaderField: "Cookie")886    assertSnapshot(matching: head, as: .raw, named: "head")887    assertSnapshot(matching: head, as: .curl, named: "head-curl")888    post = URLRequest(url: URL(string: "https://www.pointfree.co/subscribe")!)889    post.httpMethod = "POST"890    post.addValue("pf_session={\"user_id\":\"0\"}", forHTTPHeaderField: "Cookie")891    post.addValue("application/json", forHTTPHeaderField: "Accept")892    post.httpBody = Data("""893                         {"pricing": {"lane": "individual","billing": "monthly"}}894                         """.utf8)895    _assertInlineSnapshot(matching: post, as: .raw(pretty: true), with: """896    POST https://www.pointfree.co/subscribe897    Accept: application/json898    Cookie: pf_session={"user_id":"0"}899    900    {901      "pricing" : {902        "billing" : "monthly",903        "lane" : "individual"904      }905    }906    """)907  }908  func testWebView() throws {909    #if os(iOS) || os(macOS)910    let fixtureUrl = URL(fileURLWithPath: String(#file), isDirectory: false)911      .deletingLastPathComponent()912      .appendingPathComponent("__Fixtures__/pointfree.html")913    let html = try String(contentsOf: fixtureUrl)914    let webView = WKWebView()915    webView.loadHTMLString(html, baseURL: nil)916    if !ProcessInfo.processInfo.environment.keys.contains("GITHUB_WORKFLOW") {917      assertSnapshot(918        matching: webView,919        as: .image(size: .init(width: 800, height: 600)),920        named: platform921      )922    }923    #endif924  }925  func testViewWithZeroHeightOrWidth() {926    #if os(iOS) || os(tvOS)927    var rect = CGRect(x: 0, y: 0, width: 350, height: 0)928    var view = UIView(frame: rect)929    view.backgroundColor = .red930    assertSnapshot(matching: view, as: .image, named: "noHeight")931    932    rect = CGRect(x: 0, y: 0, width: 0, height: 350)933    view = UIView(frame: rect)934    view.backgroundColor = .green935    assertSnapshot(matching: view, as: .image, named: "noWidth")936    rect = CGRect(x: 0, y: 0, width: 0, height: 0)937    view = UIView(frame: rect)938    view.backgroundColor = .blue939    assertSnapshot(matching: view, as: .image, named: "noWidth.noHeight")940    #endif941  }942  func testEmbeddedWebView() throws {943    #if os(iOS)944    let label = UILabel()945    label.text = "Hello, Blob!"946    let fixtureUrl = URL(fileURLWithPath: String(#file), isDirectory: false)947      .deletingLastPathComponent()948      .appendingPathComponent("__Fixtures__/pointfree.html")949    let html = try String(contentsOf: fixtureUrl)950    let webView = WKWebView()951    webView.loadHTMLString(html, baseURL: nil)952    webView.isHidden = true953    let stackView = UIStackView(arrangedSubviews: [label, webView])954    stackView.axis = .vertical955    if !ProcessInfo.processInfo.environment.keys.contains("GITHUB_WORKFLOW") {956      assertSnapshot(957        matching: stackView,958        as: .image(size: .init(width: 800, height: 600)),959        named: platform960      )961    }962    #endif963  }964  #if os(iOS) || os(macOS)965  final class ManipulatingWKWebViewNavigationDelegate: NSObject, WKNavigationDelegate {966    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {967      webView.evaluateJavaScript("document.body.children[0].classList.remove(\"hero\")") // Change layout968    }969  }970  func testWebViewWithManipulatingNavigationDelegate() throws {971    let manipulatingWKWebViewNavigationDelegate = ManipulatingWKWebViewNavigationDelegate()972    let webView = WKWebView()973    webView.navigationDelegate = manipulatingWKWebViewNavigationDelegate974    let fixtureUrl = URL(fileURLWithPath: String(#file), isDirectory: false)975      .deletingLastPathComponent()976      .appendingPathComponent("__Fixtures__/pointfree.html")977    let html = try String(contentsOf: fixtureUrl)978    webView.loadHTMLString(html, baseURL: nil)979    if !ProcessInfo.processInfo.environment.keys.contains("GITHUB_WORKFLOW") {980      assertSnapshot(981        matching: webView,982        as: .image(size: .init(width: 800, height: 600)),983        named: platform984      )985    }986    _ = manipulatingWKWebViewNavigationDelegate987  }988  #if os(iOS) || os(macOS)989  func testWebViewWithRealUrl() throws {990    let manipulatingWKWebViewNavigationDelegate = ManipulatingWKWebViewNavigationDelegate()991    let webView = WKWebView()992    webView.navigationDelegate = manipulatingWKWebViewNavigationDelegate993    webView.load(URLRequest(url: URL(string: "https://www.pointfree.co")!))994    if !ProcessInfo.processInfo.environment.keys.contains("GITHUB_WORKFLOW") {995      assertSnapshot(996        matching: webView,997        as: .image(size: .init(width: 800, height: 600)),998        named: platform999      )1000    }1001    _ = manipulatingWKWebViewNavigationDelegate1002  }1003  #endif1004  final class CancellingWKWebViewNavigationDelegate: NSObject, WKNavigationDelegate {1005    func webView(1006      _ webView: WKWebView,1007      decidePolicyFor navigationAction: WKNavigationAction,1008      decisionHandler: @escaping (WKNavigationActionPolicy) -> Void1009    ) {1010      decisionHandler(.cancel)1011    }1012  }1013  func testWebViewWithCancellingNavigationDelegate() throws {1014    let cancellingWKWebViewNavigationDelegate = CancellingWKWebViewNavigationDelegate()1015    let webView = WKWebView()1016    webView.navigationDelegate = cancellingWKWebViewNavigationDelegate1017    let fixtureUrl = URL(fileURLWithPath: String(#file), isDirectory: false)1018      .deletingLastPathComponent()1019      .appendingPathComponent("__Fixtures__/pointfree.html")1020    let html = try String(contentsOf: fixtureUrl)1021    webView.loadHTMLString(html, baseURL: nil)1022    if !ProcessInfo.processInfo.environment.keys.contains("GITHUB_WORKFLOW") {1023      assertSnapshot(1024        matching: webView,1025        as: .image(size: .init(width: 800, height: 600)),1026        named: platform1027      )1028    }1029    _ = cancellingWKWebViewNavigationDelegate1030  }1031  #endif1032  @available(iOS 13.0, *)1033  func testSwiftUIView_iOS() {1034    #if os(iOS)1035    struct MyView: SwiftUI.View {1036      var body: some SwiftUI.View {1037        HStack {1038          Image(systemName: "checkmark.circle.fill")1039            Text("Checked").fixedSize()1040        }1041        .padding(5)1042        .background(RoundedRectangle(cornerRadius: 5.0).fill(Color.blue))1043        .padding(10)1044      }1045    }1046    let view = MyView().background(Color.yellow)1047    assertSnapshot(matching: view, as: .image(traits: .init(userInterfaceStyle: .light)))1048    assertSnapshot(matching: view, as: .image(layout: .sizeThatFits, traits: .init(userInterfaceStyle: .light)), named: "size-that-fits")1049    assertSnapshot(matching: view, as: .image(layout: .fixed(width: 200.0, height: 100.0), traits: .init(userInterfaceStyle: .light)), named: "fixed")1050    assertSnapshot(matching: view, as: .image(layout: .device(config: .iPhoneSe), traits: .init(userInterfaceStyle: .light)), named: "device")1051    #endif1052  }1053  @available(tvOS 13.0, *)1054  func testSwiftUIView_tvOS() {1055    #if os(tvOS)1056    struct MyView: SwiftUI.View {1057      var body: some SwiftUI.View {1058        HStack {1059          Image(systemName: "checkmark.circle.fill")1060            Text("Checked").fixedSize()1061        }1062        .padding(5)1063        .background(RoundedRectangle(cornerRadius: 5.0).fill(Color.blue))1064        .padding(10)1065      }1066    }1067    let view = MyView().background(Color.yellow)1068    assertSnapshot(matching: view, as: .image())1069    assertSnapshot(matching: view, as: .image(layout: .sizeThatFits), named: "size-that-fits")1070    assertSnapshot(matching: view, as: .image(layout: .fixed(width: 300.0, height: 100.0)), named: "fixed")1071    assertSnapshot(matching: view, as: .image(layout: .device(config: .tv)), named: "device")1072    #endif1073  }1074  @available(*, deprecated)1075  func testIsRecordingProxy() {1076    SnapshotTesting.record = true1077    XCTAssertEqual(isRecording, true)1078    SnapshotTesting.record = false1079    XCTAssertEqual(isRecording, false)1080  }1081}1082#if os(iOS)1083private let allContentSizes =1084  [1085    "extra-small": UIContentSizeCategory.extraSmall,1086    "small": .small,1087    "medium": .medium,1088    "large": .large,1089    "extra-large": .extraLarge,1090    "extra-extra-large": .extraExtraLarge,1091    "extra-extra-extra-large": .extraExtraExtraLarge,1092    "accessibility-medium": .accessibilityMedium,1093    "accessibility-large": .accessibilityLarge,1094    "accessibility-extra-large": .accessibilityExtraLarge,1095    "accessibility-extra-extra-large": .accessibilityExtraExtraLarge,1096    "accessibility-extra-extra-extra-large": .accessibilityExtraExtraExtraLarge,1097    ]1098#endif1099#if os(Linux) || os(Windows)1100extension SnapshotTestingTests {1101  static var allTests : [(String, (SnapshotTestingTests) -> () throws -> Void)] {1102    return [1103      ("testAny", testAny),1104      ("testAnySnapshotStringConvertible", testAnySnapshotStringConvertible),1105      ("testAutolayout", testAutolayout),1106      ("testDeterministicDictionaryAndSetSnapshots", testDeterministicDictionaryAndSetSnapshots),1107      ("testEncodable", testEncodable),1108      ("testMixedViews", testMixedViews),1109      ("testMultipleSnapshots", testMultipleSnapshots),1110      ("testNamedAssertion", testNamedAssertion),1111      ("testPrecision", testPrecision),1112      ("testSCNView", testSCNView),1113      ("testSKView", testSKView),1114      ("testTableViewController", testTableViewController),1115      ("testTraits", testTraits),1116      ("testTraitsEmbeddedInTabNavigation", testTraitsEmbeddedInTabNavigation),1117      ("testTraitsWithView", testTraitsWithView),1118      ("testUIView", testUIView),1119      ("testURLRequest", testURLRequest),...

Full Screen

Full Screen

testAutolayout

Using AI Code Generation

copy

Full Screen

1import UIKit2import WebKit3class ViewController: UIViewController {4    override func viewDidLoad() {5        super.viewDidLoad()6        let request = URLRequest(url: url!)7        webView.load(request)8        webView.navigationDelegate = CancellingWKWebViewNavigationDelegate()9    }10}11import UIKit12import WebKit13class CancellingWKWebViewNavigationDelegate: NSObject, WKNavigationDelegate {14    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {15        print("didStartProvisionalNavigation")16    }17    func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {18        print("didCommit")19    }20    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {21        print("didFinish")22    }23    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {24        print("didFail")25    }26    func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {27        print("didFailProvisionalNavigation")28    }29}30class CancellingWKWebViewNavigationDelegate: NSObject, WKNavigationDelegate {31    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {32        print("didStartProvisionalNavigation")33    }34    func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {35        print("didCommit")36    }37    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {38        print("didFinish")39        webView.stopLoading()40    }41    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {

Full Screen

Full Screen

testAutolayout

Using AI Code Generation

copy

Full Screen

1import UIKit2import WebKit3class ViewController: UIViewController, WKNavigationDelegate {4    override func viewDidLoad() {5        super.viewDidLoad()6        self.cancellingWKWebViewNavigationDelegate = CancellingWKWebViewNavigationDelegate()7        let request = URLRequest(url: url!)8        self.webView.load(request)9    }10    override func viewDidAppear(_ animated: Bool) {11        super.viewDidAppear(animated)12        self.cancellingWKWebViewNavigationDelegate.testAutolayout()13    }14}15import UIKit16import WebKit17class CancellingWKWebViewNavigationDelegate: NSObject, WKNavigationDelegate {18    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {19        self.webView.evaluateJavaScript("document.body.scrollHeight") { (result, error) in20            if let height = result as? CGFloat {21            }22        }23    }24    func testAutolayout() {25        let webView = WKWebView()26        let request = URLRequest(url: url!)27        webView.load(request)28        self.webViewHeightConstraint = webView.heightAnchor.constraint(equalToConstant: 0)29    }30}

Full Screen

Full Screen

testAutolayout

Using AI Code Generation

copy

Full Screen

1import UIKit2import WebKit3class ViewController: UIViewController {4    override func viewDidLoad() {5        super.viewDidLoad()6        self.cancellingWKWebViewNavigationDelegate = CancellingWKWebViewNavigationDelegate()7        self.cancellingWKWebViewNavigationDelegate?.testAutolayout(myWebView)8    }9}10import UIKit11import WebKit12class CancellingWKWebViewNavigationDelegate: NSObject, WKNavigationDelegate {13    func testAutolayout(_ myWebView: WKWebView) {14    }15    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {16        print("didStartProvisionalNavigation")17    }18    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {19        print("didFinish")20    }21    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {22        print("didFail")23    }24    func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {25        print("didFailProvisionalNavigation")26    }27}28import UIKit29import WebKit30class WKWebView: UIView {31    func load(_ request: URLRequest) {32        print("load")33    }34}35import UIKit36protocol WKNavigationDelegate: class {37    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!)38    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!)39    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error)40    func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error)41}42import UIKit43class WKNavigation {44}

Full Screen

Full Screen

testAutolayout

Using AI Code Generation

copy

Full Screen

1let testAutolayout = CancellingWKWebViewNavigationDelegate()2testAutolayout.testAutolayout()3let testAutolayout = CancellingWKWebViewNavigationDelegate()4testAutolayout.testAutolayout()5let testAutolayout = CancellingWKWebViewNavigationDelegate()6testAutolayout.testAutolayout()7let testAutolayout = CancellingWKWebViewNavigationDelegate()8testAutolayout.testAutolayout()9let testAutolayout = CancellingWKWebViewNavigationDelegate()10testAutolayout.testAutolayout()11let testAutolayout = CancellingWKWebViewNavigationDelegate()12testAutolayout.testAutolayout()13let testAutolayout = CancellingWKWebViewNavigationDelegate()14testAutolayout.testAutolayout()15let testAutolayout = CancellingWKWebViewNavigationDelegate()16testAutolayout.testAutolayout()17let testAutolayout = CancellingWKWebViewNavigationDelegate()18testAutolayout.testAutolayout()19let testAutolayout = CancellingWKWebViewNavigationDelegate()20testAutolayout.testAutolayout()21let testAutolayout = CancellingWKWebViewNavigationDelegate()22testAutolayout.testAutolayout()

Full Screen

Full Screen

testAutolayout

Using AI Code Generation

copy

Full Screen

1import UIKit2import WebKit3class ViewController: UIViewController {4    override func viewDidLoad() {5        super.viewDidLoad()6        let request = URLRequest(url: url!)7        webView.load(request)8        webView.navigationDelegate = CancellingWKWebViewNavigationDelegate()9    }10    override func viewDidLayoutSubviews() {11        super.viewDidLayoutSubviews()12        webView.navigationDelegate?.testAutolayout()13    }14}15class CancellingWKWebViewNavigationDelegate: NSObject, WKNavigationDelegate {16    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {17        print("didStartProvisionalNavigation")18    }19    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {20        print("didFinish")21    }22    func testAutolayout() {23        print("testAutolayout")24    }25}26import UIKit27import WebKit28class ViewController: UIViewController {29    override func viewDidLoad() {30        super.viewDidLoad()31        let request = URLRequest(url: url!)32        webView.load(request)33        webView.navigationDelegate = CancellingWKWebViewNavigationDelegate()34    }35    override func viewDidLayoutSubviews() {36        super.viewDidLayoutSubviews()37        (webView.navigationDelegate as? CancellingWKWebViewNavigationDelegate)?.testAutolayout()38    }39}40class CancellingWKWebViewNavigationDelegate: NSObject, WKNavigationDelegate {41    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {42        print("didStartProvisionalNavigation")43    }44    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {45        print("didFinish")46    }47    func testAutolayout() {48        print("testAutolayout")49    }50}

Full Screen

Full Screen

testAutolayout

Using AI Code Generation

copy

Full Screen

1let webView = WKWebView()2let delegate = CancellingWKWebViewNavigationDelegate()3delegate.testAutolayout(webView: webView)4func testAutolayout(webView: WKWebView) {5    NSLayoutConstraint.activate([6        webView.topAnchor.constraint(equalTo: view.topAnchor),7        webView.leadingAnchor.constraint(equalTo: view.leadingAnchor),8        webView.trailingAnchor.constraint(equalTo: view.trailingAnchor),9        webView.bottomAnchor.constraint(equalTo: view.bottomAnchor)10}11let webView = WKWebView()12let delegate = CancellingWKWebViewNavigationDelegate()13delegate.testAutolayout(webView: webView)14func testAutolayout(webView: WKWebView) {15    NSLayoutConstraint.activate([16        webView.topAnchor.constraint(equalTo: view.topAnchor),17        webView.leadingAnchor.constraint(equalTo: view.leadingAnchor),18        webView.trailingAnchor.constraint(equalTo: view.trailingAnchor),19        webView.bottomAnchor.constraint(equalTo: view.bottomAnchor)20}21let webView = WKWebView()22let delegate = CancellingWKWebViewNavigationDelegate()23delegate.testAutolayout(webView: webView)24func testAutolayout(webView: WKWebView) {25    NSLayoutConstraint.activate([26        webView.topAnchor.constraint(equalTo: view.topAnchor),27        webView.leadingAnchor.constraint(equalTo: view.leadingAnchor),28        webView.trailingAnchor.constraint(equalTo: view.trailingAnchor),29        webView.bottomAnchor.constraint(equalTo: view.bottomAnchor)30}31let webView = WKWebView()32let delegate = CancellingWKWebViewNavigationDelegate()33delegate.testAutolayout(webView: webView)

Full Screen

Full Screen

testAutolayout

Using AI Code Generation

copy

Full Screen

1class ViewController: UIViewController, CancellingWKWebViewNavigationDelegate {2    override func viewDidLoad() {3        super.viewDidLoad()4        webView.load(URLRequest(url: url))5    }6    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {7        testAutolayout(webView)8    }9}10class CancellingWKWebViewNavigationDelegate: NSObject, WKNavigationDelegate {11    private var cancellationBlock: (() -> Void)?12    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {13    }14    func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {15        cancellationBlock?()16    }17    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {18        cancellationBlock?()19    }20    func webViewWebContentProcessDidTerminate(_ webView: WKWebView) {21        cancellationBlock?()22    }23    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {24        cancellationBlock = {25            decisionHandler(.cancel)26        }27        decisionHandler(.allow)28    }29    func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {30        cancellationBlock = {31            decisionHandler(.cancel)32        }33        decisionHandler(.allow)34    }35    func testAutolayout(_ webView: WKWebView) {36        print("testAutolayout")37        body {38            margin: 0;39            padding: 0;40        }41        .container {42            width: 100%;43            height: 100%;44            display: flex;

Full Screen

Full Screen

testAutolayout

Using AI Code Generation

copy

Full Screen

1import UIKit2import WebKit3class ViewController: UIViewController {4    override func viewDidLoad() {5        super.viewDidLoad()6        let config = WKWebViewConfiguration()7        delegate = CancellingWKWebViewNavigationDelegate()8        webView = WKWebView(frame: .zero, configuration: config)9        containerView.addSubview(webView!)10        webView?.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true11        webView?.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true12        webView?.leadingAnchor.constraint(equalTo: containerView.leadingAnchor).isActive = true13        webView?.trailingAnchor.constraint(equalTo: containerView.trailingAnchor).isActive = true14    }15    @IBAction func testAutolayout(_ sender: Any) {16        delegate?.testAutolayout()17    }18}19class CancellingWKWebViewNavigationDelegate: NSObject, WKNavigationDelegate {20    func testAutolayout() {21        print("testAutolayout")22    }23    func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {24        print("didCommit")25    }26    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {27        print("didFinish")28    }29    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {30        print("didFail")31    }32    func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {33        print("didFailProvisionalNavigation")34    }35    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {36        print("didStartProvisionalNavigation")37    }38    func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {39        print("didReceiveServerRedirectForProvisionalNavigation")40    }41    func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession

Full Screen

Full Screen

testAutolayout

Using AI Code Generation

copy

Full Screen

1import UIKit2import WebKit3class ViewController: UIViewController, WKNavigationDelegate {4    override func viewDidLoad() {5        super.viewDidLoad()6        delegate = CancellingWKWebViewNavigationDelegate()7        webView = WKWebView(frame: .zero)8        delegate?.testAutolayout(webView: webView)9        view.addSubview(webView)10    }11}12class CancellingWKWebViewNavigationDelegate: NSObject, WKNavigationDelegate {13    func testAutolayout(webView: WKWebView) {14        let topConstraint = NSLayoutConstraint(item: webView, attribute: .top, relatedBy: .equal, toItem: webView.superview, attribute: .top, multiplier: 1, constant: 0)15        let leftConstraint = NSLayoutConstraint(item: webView, attribute: .left, relatedBy: .equal, toItem: webView.superview, attribute: .left, multiplier: 1, constant: 0)16        let rightConstraint = NSLayoutConstraint(item: webView, attribute: .right, relatedBy: .equal, toItem: webView.superview, attribute: .right, multiplier: 1, constant: 0)17        let bottomConstraint = NSLayoutConstraint(item: webView, attribute: .bottom, relatedBy: .equal, toItem: webView.superview, attribute: .bottom, multiplier: 1, constant: 0)18        webView.superview?.addConstraints([topConstraint, leftConstraint, rightConstraint, bottomConstraint])19    }20}

Full Screen

Full Screen

testAutolayout

Using AI Code Generation

copy

Full Screen

1let testAutolayout = CancellingWKWebViewNavigationDelegate()2testAutolayout.testAutolayout(view: self.view)3let testAutolayout = CancellingWKWebViewNavigationDelegate()4testAutolayout.testAutolayout(view: self.view)5let testAutolayout = CancellingWKWebViewNavigationDelegate()6testAutolayout.testAutolayout(view: self.view)7let testAutolayout = CancellingWKWebViewNavigationDelegate()8testAutolayout.testAutolayout(view: self.view)9let testAutolayout = CancellingWKWebViewNavigationDelegate()10testAutolayout.testAutolayout(view: self.view)11let testAutolayout = CancellingWKWebViewNavigationDelegate()12testAutolayout.testAutolayout(view: self.view)13let testAutolayout = CancellingWKWebViewNavigationDelegate()14testAutolayout.testAutolayout(view: self.view)

Full Screen

Full Screen

testAutolayout

Using AI Code Generation

copy

Full Screen

1lettestAutolayout=CancellingWKWebViewNavigationDelegate()2testAutolayout.testAutolayout(view:self.view)3let testAutolayout = CancellingWKWebViewNavigationDelegate()4testAutolayout.testAutolayout(view: self.view)5let testAutolayout = CancellingWKWebViewNavigationDelegate()6testAutolayout.testAutolayout(view: self.view)7let testAutolayout = CancellingWKWebViewNavigationDelegate()8testAutolayout.testAutolayout(view: self.view)9let testAutolayout = CancellingWKWebViewNavigationDelegate()10testAutolayout.testAutolayout(view: self.view)11let testAutolayout = CancellingWKWebViewNavigationDelegate()12testAutolayout.testAutolayout(view: self.view)13let testAutolayout = CancellingWKWebViewNavigationDelegate()14testAutolayout.testAutolayout(view: self.view)

Full Screen

Full Screen

testAutolayout

Using AI Code Generation

copy

Full Screen

1import UIKit2import WebKit3class ViewController: UIViewController {4    override func viewDidLoad() {5        super.viewDidLoad()6        let request = URLRequest(url: url!)7        webView.load(request)8        webView.navigationDelegate = CancellingWKWebViewNavigationDelegate()9    }10    override func viewDidLayoutSubviews() {11        super.viewDidLayoutSubviews()12        webView.navigationDelegate?.testAutolayout()13    }14}15class CancellingWKWebViewNavigationDelegate: NSObject, WKNavigationDelegate {16    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {17        print("didStartProvisionalNavigation")18    }19    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {20        print("didFinish")21    }22    func testAutolayout() {23        print("testAutolayout")24    }25}26import UIKit27import WebKit28class ViewController: UIViewController {29    override func viewDidLoad() {30        super.viewDidLoad()31        let request = URLRequest(url: url!)32        webView.load(request)33        webView.navigationDelegate = CancellingWKWebViewNavigationDelegate()34    }35    override func viewDidLayoutSubviews() {36        super.viewDidLayoutSubviews()37        (webView.navigationDelegate as? CancellingWKWebViewNavigationDelegate)?.testAutolayout()38    }39}40class CancellingWKWebViewNavigationDelegate: NSObject, WKNavigationDelegate {41    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {42        print("didStartProvisionalNavigation")43    }44    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {45        print("didFinish")46    }47    func testAutolayout() {48        print("testAutolayout")49    }50}

Full Screen

Full Screen

testAutolayout

Using AI Code Generation

copy

Full Screen

1class ViewController: UIViewController, CancellingWKWebViewNavigationDelegate {2    override func viewDidLoad() {3        super.viewDidLoad()4        webView.load(URLRequest(url: url))5    }6    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {7        testAutolayout(webView)8    }9}10class CancellingWKWebViewNavigationDelegate: NSObject, WKNavigationDelegate {11    private var cancellationBlock: (() -> Void)?12    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {13    }14    func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {15        cancellationBlock?()16    }17    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {18        cancellationBlock?()19    }20    func webViewWebContentProcessDidTerminate(_ webView: WKWebView) {21        cancellationBlock?()22    }23    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {24        cancellationBlock = {25            decisionHandler(.cancel)26        }27        decisionHandler(.allow)28    }29    func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {30        cancellationBlock = {31            decisionHandler(.cancel)32        }33        decisionHandler(.allow)34    }35    func testAutolayout(_ webView: WKWebView) {36        print("testAutolayout")37        body {38            margin: 0;39            padding: 0;40        }41        .container {42            width: 100%;43            height: 100%;44            display: flex;

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful