Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // LoveTweetUITests.swift
- // LoveTweetUITests
- //
- // Created by Daniel Fera on 13/07/2018.
- // Copyright Β© 2018 YiGu. All rights reserved.
- //
- import XCTest
- extension XCUIElement {
- /**
- Removes any current text in the field before typing in the new value
- - Parameter text: the text to enter into the field
- */
- func clearAndEnterText(text: String) {
- guard let stringValue = self.value as? String else {
- XCTFail("Tried to clear and enter text into a non string value")
- return
- }
- self.tap()
- let deleteString = String(repeating: XCUIKeyboardKey.delete.rawValue, count: stringValue.count)
- self.typeText(deleteString)
- self.typeText(text)
- self.typeText("\n")
- }
- }
- class LoveTweetUITests: XCTestCase {
- override func setUp() {
- super.setUp()
- // Put setup code here. This method is called before the invocation of each test method in the class.
- // In UI tests it is usually best to stop immediately when a failure occurs.
- continueAfterFailure = false
- // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
- XCUIApplication().launch()
- // In UI tests itβs important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
- }
- override func tearDown() {
- // Put teardown code here. This method is called after the invocation of each test method in the class.
- super.tearDown()
- }
- func getStringSalary(salary: Float) -> String {
- let ksal = Int(salary)
- return "$\(ksal)k"
- }
- func testThatNameTextFieldExists() {
- let app = XCUIApplication()
- let nameTextField = app.scrollViews.otherElements.containing(.staticText, identifier:"LoveTweet").children(matching: .other).element(boundBy: 0).children(matching: .textField).element
- nameTextField.tap()
- nameTextField.typeText("TestNume")
- sleep(1)
- XCTAssertEqual(nameTextField.exists, true)
- }
- func testThatTweetItButtonsWorksWithAllInfos() {
- let name = "TestNume"
- let birthDate = ("1996", "November", "21")
- let salary = 140.0
- let maxSalary = 350.0
- let normalizedSalary0 = (140.0/maxSalary)
- let normalizedSalary = CGFloat(normalizedSalary0)
- let work = "TestWork"
- let interestedGender = "Women"
- let dateFormatter = DateFormatter()
- dateFormatter.dateFormat = "yyyy' - 'MMMM' - 'dd"
- let dateBirth = dateFormatter.date(from: "\(birthDate.0) - \(birthDate.1) - \(birthDate.2)")
- let minAge = Date().timeIntervalSince(dateBirth!)
- let age = Int(minAge / (3600 * 24 * 365))
- let app = XCUIApplication()
- let nameTextField = app.textFields.firstMatch
- nameTextField.tap()
- nameTextField.clearAndEnterText(text: name)
- let femaleButton = app.scrollViews.otherElements.buttons["Female"]
- let maleButton = app.scrollViews.otherElements.buttons["Male"]
- let workTextField = app.textFields.element(boundBy: 1)
- workTextField.tap()
- workTextField.clearAndEnterText(text: work)
- femaleButton.tap()
- maleButton.tap()
- let datePicker = app.scrollViews.otherElements.datePickers
- datePicker.pickerWheels["1995"].adjust(toPickerWheelValue: birthDate.0)
- datePicker.pickerWheels["February"].adjust(toPickerWheelValue: birthDate.1)
- datePicker.pickerWheels["24"].adjust(toPickerWheelValue: birthDate.2)
- let salarySlider = app.sliders.firstMatch
- salarySlider.adjust(toNormalizedSliderPosition: normalizedSalary)
- let tweetItButton = app.scrollViews.otherElements.buttons["Tweet it!"]
- tweetItButton.tap()
- let loveTweetAlert = app.alerts["Love Tweet"]
- let successMessage = "Hi, I am \(name). As a \(age)-year-old \(work) earning \(getStringSalary(salary: Float(salary)))/year, I am interested in \(interestedGender). Feel free to contact me!"
- print(successMessage)
- XCTAssertEqual(loveTweetAlert.staticTexts[successMessage].exists, true)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement