How to use driver.getPageSource method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

JobRolesTestSelenium.js

Source:JobRolesTestSelenium.js Github

copy

Full Screen

...12    await driver.findElement(By.id('password')).sendKeys(config.employeeUser.password)13    await driver.findElement(By.xpath('//*[@id="main-content"]/form/button')).click()14    await driver.wait(until.titleIs('Home'))15    expect(title).to.equal('Login')16    var htmlSource = await driver.getPageSource()17    fs.appendFile('app/assets/snapshots/home-snapshot.html', htmlSource, function (err) {18      if (err) throw err19      console.log('Saved!')20    })21  })22  it('should wait until home page opens', async () => {23    const title = await driver.getTitle()24    const button = await driver.findElement(By.xpath('//*[@id="main-content"]/div/div[1]/a')).getText()25    expect(title).to.equal('Home')26    expect(button).to.equal('Search jobs')27  })28  it('should click button and open job roles', async () => {29    driver.findElement(By.xpath('//*[@id="main-content"]/div/div[1]/a')).click()30    await driver.wait(until.titleIs('List of Job Roles'))31    const title = await driver.getTitle()32    expect(title).to.equal('List of Job Roles')33    var htmlSource = await driver.getPageSource()34    fs.appendFile('app/assets/snapshots/jobRoles-snapshot.html', htmlSource, function (err) {35      if (err) throw err36      console.log('Saved!')37    })38  })39  it('should have correct first row displayed on job roles page', async () => {40    var expectedFirstRow = ['Software Engineer', 'Engineering', 'Engineering', 'Associate']41    var elements = (await driver.findElements(By.className('govuk-table__cell')))42    var jobRole = await elements[0].getText()43    var jobCapability = await elements[1].getText()44    var jobFamily = await elements[2].getText()45    var bandLevel = await elements[3].getText()46    var firstRow = [jobRole, jobCapability, jobFamily, bandLevel]47    expect(firstRow).to.eql(expectedFirstRow)48  })49  it('should display filter box on job roles page', async () => {50    var filter1 = await driver.findElement(By.xpath('//*[@id="accordion-default-heading-1"]')).getText()51    expect(filter1).to.eql('Filter by Job Role')52    var filter2 = await driver.findElement(By.xpath('//*[@id="accordion-default-heading-2"]')).getText()53    expect(filter2).to.eql('Filter by Capability')54    var filter3 = await driver.findElement(By.xpath('//*[@id="accordion-default-heading-3"]')).getText()55    expect(filter3).to.eql('Filter by Job Family')56    var filter4 = await driver.findElement(By.xpath('//*[@id="accordion-default-heading-4"]')).getText()57    expect(filter4).to.eql('Filter by Band Level')58  })59  it('should filter job roles when update table button is clicked', async () => {60    await driver.findElement(By.xpath('//*[@id="accordion-default-heading-2"]')).click()61    await driver.findElement(By.id('capability-2')).click()62    await driver.findElement(By.id('capability-3')).click()63    await driver.findElement(By.id('capability-4')).click()64    await driver.findElement(By.id('capability-5')).click()65    await driver.findElement(By.id('capability-6')).click()66    await driver.findElement(By.id('capability-7')).click()67    await driver.findElement(By.id('capability-8')).click()68    expect(await driver.findElement(By.id('capability-2')).isSelected()).to.eql(false)69    expect(await driver.findElement(By.id('capability-3')).isSelected()).to.eql(false)70    expect(await driver.findElement(By.id('capability-4')).isSelected()).to.eql(false)71    expect(await driver.findElement(By.id('capability-5')).isSelected()).to.eql(false)72    expect(await driver.findElement(By.id('capability-6')).isSelected()).to.eql(false)73    expect(await driver.findElement(By.id('capability-7')).isSelected()).to.eql(false)74    expect(await driver.findElement(By.id('capability-8')).isSelected()).to.eql(false)75    await driver.findElement(By.xpath('//*[@id="accordion-default-heading-2"]')).click()76    await driver.findElement(By.xpath('//*[@id="main-content"]/form/button')).click()77    const title = await driver.getTitle()78    expect(title).to.equal('List of Job Roles')79  })80  it('should click more info and display job spec', async () => {81    driver.findElement(By.linkText('More Info')).click()82    await driver.wait(until.titleIs('Job Specification'))83    const title = await driver.getTitle()84    expect(title).to.equal('Job Specification')85    var htmlSource = await driver.getPageSource()86    fs.appendFile('app/assets/snapshots/jobSpec-snapshot.html', htmlSource, function (err) {87      if (err) throw err88      console.log('Saved!')89    })90  })91  it('should click back and display job roles, Tests back button works', async () => {92    driver.findElement(By.linkText('Back')).click()93    await driver.wait(until.titleIs('List of Job Roles'))94    const title = await driver.getTitle()95    expect(title).to.equal('List of Job Roles')96  })97  it('should click band level and display band level', async () => {98    await driver.findElement(By.linkText('Associate')).click()99    const title = await driver.getTitle()100    var heading = await driver.findElement(By.className('govuk-heading-xl')).getText()101    expect(heading).to.equal('Associate Competency Information')102    expect(title).to.equal('Job Band Level Competencies')103    var htmlSource = await driver.getPageSource()104    fs.appendFile('app/assets/snapshots/competencies-snapshot.html', htmlSource, function (err) {105      if (err) throw err106      console.log('Saved!')107    })108  })109  it('should click training button and display available training courses', async () => {110    driver.findElement(By.xpath('//*[@id="main-content"]/a')).click()111    await driver.wait(until.titleIs('Job Band Level Training'))112    const title = await driver.getTitle()113    expect(title).to.equal('Job Band Level Training')114  })115  it('should display link and heading', async () => {116    const link = await driver.findElement(By.linkText('View course'))117    var heading = await driver.findElement(By.className('govuk-heading-xl')).getText()118    expect(heading).to.equal('Available Training Courses for Associate')119    expect(link).to.exist // eslint-disable-line120  })121  // put in bit for clicking training link122  it('should click home and display home', async () => {123    driver.findElement(By.linkText('Home')).click()124    await driver.wait(until.titleIs('Home'))125    const title = await driver.getTitle()126    expect(title).to.equal('Home')127  })128  it('should click View Role Matrix and confirm table', async () => {129    driver.findElement(By.linkText('View Role Matrix')).click()130    await driver.wait(until.titleIs('List of Job Roles'))131    const title = await driver.getTitle()132    var element = await driver.findElements(By.linkText('Software Engineer'))133    var jobRole = await element[element.length - 1].getText()134    expect(jobRole).to.equal('Software Engineer')135    expect(title).to.equal('List of Job Roles')136  })137  it('should click on a role and go to job spec page', async () => {138    var elements = await driver.findElements(By.linkText('Software Engineer'))139    await elements[elements.length - 1].click()140    const title = await driver.getTitle()141    var heading = await driver.findElement(By.className('govuk-heading-xl')).getText()142    expect(title).to.equal('Job Specification')143    expect(heading).to.equal('Software Engineer Spec')144  })145  it('should click home and then click job Families button and confirm table', async () => {146    await driver.findElement(By.linkText('Home')).click()147    await driver.findElement(By.linkText('View Job Families')).click()148    const titleJobFamily = await driver.getTitle()149    expect(titleJobFamily).to.equal('Job Families')150    var elements = await driver.findElements(By.className('govuk-table__cell'))151    var jobCapability = await elements[0].getText()152    var jobFamily = await elements[1].getText()153    expect(jobCapability).to.equal('Engineering')154    expect(jobFamily).to.equal('Engineering Strategy and Planning')155    var htmlSource = await driver.getPageSource()156    fs.appendFile('app/assets/snapshots/jobFamilies-snapshot.html', htmlSource, function (err) {157      if (err) throw err158      console.log('Saved!')159    })160  })161  it('should click on view capability lead and confirm table', async () => {162    await driver.findElement(By.linkText('Home')).click()163    await driver.findElement(By.linkText('View Capability Lead')).click()164    const title = await driver.getTitle()165    expect(title).to.equal('List of Capabilty Leads')166    var expectedFirstRow = ['Dave', 'Boats', 'Engineering']167    var elements = (await driver.findElements(By.className('govuk-table__cell')))168    var forename = await elements[0].getText()169    var surname = await elements[1].getText()170    var capability = await elements[2].getText()171    var firstRow = [forename, surname, capability]172    expect(firstRow).to.eql(expectedFirstRow)173    var htmlSource = await driver.getPageSource()174    fs.appendFile('app/assets/snapshots/capabilityLeads-snapshot.html', htmlSource, function (err) {175      if (err) throw err176      console.log('Saved!')177    })178  })179  it('should click on capability lead more info link and get right page', async () => {180    await driver.findElement(By.linkText('More Info')).click()181    const title = await driver.getTitle()182    expect(title).to.equal('View Capability Lead Info')183    var text = await driver.findElement(By.className('govuk-summary-list__value')).getText()184    expect(text).to.equal('Dave Boats')185    var htmlSource = await driver.getPageSource()186    fs.appendFile('app/assets/snapshots/viewCapabilityLeads-snapshot.html', htmlSource, function (err) {187      if (err) throw err188      console.log('Saved!')189    })190  })191  it('Asssert the title on view all capability leads webpage is correct', async () => {192    await driver.get('http://localhost:3000/viewAllCapabilities')193    const title = await driver.getTitle()194    console.log(title)195    expect(title).to.equal('List of Capabilty Leads')196  })197  it('Asssert the title on view capability lead webpage is correct', async () => {198    await driver.get('http://localhost:3000/capabilityLeadInfo?leadID=1')199    const title = await driver.getTitle()200    console.log(title)201    expect(title).to.equal('View Capability Lead Info')202  })203  it('should logout and login as admin', async () => {204    var config = JSON.parse(fs.readFileSync('selenium-test/seleniumConfig.json', 'utf8'))205    await driver.get('http://localhost:3000/home')206    var title = await driver.getTitle()207    expect(title).to.equal('Home')208    await driver.findElement(By.xpath('//*[@id="main-content"]/div/div[2]/aside/a')).click()209    title = await driver.getTitle()210    expect(title).to.equal('Logged Out')211    var logoutPageHtmlSource = await driver.getPageSource()212    fs.appendFile('app/assets/snapshots/logout-snapshot.html', logoutPageHtmlSource, function (err) {213      if (err) throw err214      console.log('Saved!')215    })216    await driver.findElement(By.xpath('//*[@id="main-content"]/a')).click()217    title = await driver.getTitle()218    expect(title).to.equal('Login')219    const username = await driver.findElement(By.id('username'))220    await username.sendKeys('aaa')221    for (let i = 0; i < 20; i++) {222      await username.sendKeys(Key.BACK_SPACE)223    }224    console.log(config.adminUser)225    await username.sendKeys(config.adminUser.username)226    const password = await driver.findElement(By.id('password'))227    await password.sendKeys('aaa')228    for (let i = 0; i < 20; i++) {229      await password.sendKeys(Key.BACK_SPACE)230    }231    await password.sendKeys(config.adminUser.password)232    await driver.findElement(By.xpath('/html/body/div[1]/main/form/button')).click()233    var homeTitle = await driver.getTitle()234    expect(homeTitle).to.equal('Home')235    var adminHomeHtmlSource = await driver.getPageSource()236    fs.appendFile('app/assets/snapshots/adminHome-snapshot.html', adminHomeHtmlSource, function (err) {237      if (err) throw err238      console.log('Saved!')239    })240  })241  it('should wait until add role page opens', async () => {242    await driver.get('http://localhost:3000/addrole')243    const title = await driver.getTitle()244    const button = await driver.findElement(By.xpath('//*[@id="main-content"]/form/button')).getText()245    expect(title).to.equal('Add a New Role')246    expect(button).to.equal('Submit')247    var htmlSource = await driver.getPageSource()248    fs.appendFile('app/assets/snapshots/addRoles-snapshot.html', htmlSource, function (err) {249      if (err) throw err250      console.log('Saved!')251    })252  })253  it('Should add, edit and delete a job role and return to the job roles page after each', async () => {254    // adding a role255    await driver.findElement(By.xpath('//*[@id="jobRole"]')).sendKeys('seleniumtestname')256    await driver.findElement(By.xpath('//*[@id="jobSpec"]')).sendKeys('seleniumtestspec')257    await driver.findElement(By.xpath('//*[@id="jobLink"]')).sendKeys('seleniumtestlink')258    await driver.findElement(By.xpath('//*[@id="jobResponsibilities"]')).sendKeys('seleniumtestresponsibilities')259    driver.findElement(By.xpath('//*[@id="jobBandLevel"]/option[2]')).click()260    driver.findElement(By.xpath('//*[@id="jobFamily"]/option[3]')).click()261    await driver.findElement(By.xpath('//*[@id="main-content"]/form/button')).click()262    const title = await driver.getTitle()263    expect(title).to.equal('List of Job Roles')264    var elements = (await driver.findElements(By.className('govuk-table__cell')))265    var rows = (await driver.findElements(By.className('govuk-table__row')))266    var columns = elements.length / (rows.length - 1)267    for (let i = 0; i < elements.length; i++) {268      if (await elements[i].getText() === 'seleniumtestname') {269        expect(true)270        var link = await driver.findElement(By.xpath('//*[@id="main-content"]/form/table/tbody/tr[' + ((i / columns) + 1) + ']/td[6]')).getText()271        expect(link).to.equal('Edit')272        await driver.findElement(By.xpath('//*[@id="main-content"]/form/table/tbody/tr[' + ((i / columns) + 1) + ']/td[6]/a')).click()273        break274      }275    }276    const title2 = await driver.getTitle()277    expect(title2).to.equal('Edit a Role')278    await driver.findElement(By.xpath('//*[@id="jobLink"]')).sendKeys('.com')279    await driver.findElement(By.xpath('//*[@id="jobRole"]')).clear()280    await driver.findElement(By.xpath('//*[@id="jobRole"]')).sendKeys('selenium')281    await driver.findElement(By.xpath('//*[@id="jobResponsibilities"]')).sendKeys('hello')282    await driver.findElement(By.xpath('//*[@id="main-content"]/form/button')).click()283    const title3 = await driver.getTitle()284    expect(title3).to.equal('List of Job Roles')285    var elements2 = (await driver.findElements(By.className('govuk-table__cell')))286    var rows2 = (await driver.findElements(By.className('govuk-table__row')))287    var columns2 = elements2.length / (rows2.length - 1)288    for (let i = 0; i < elements2.length; i++) {289      if (await elements2[i].getText() === 'selenium') {290        expect(true)291        var link2 = await driver.findElement(By.xpath('//*[@id="main-content"]/form/table/tbody/tr[' + ((i / columns2) + 1) + ']/td[7]')).getText()292        expect(link2).to.equal('Delete')293        await driver.findElement(By.xpath('//*[@id="main-content"]/form/table/tbody/tr[' + ((i / columns2) + 1) + ']/td[7]/a')).click()294        break295      }296    }297    const title4 = await driver.getTitle()298    console.log(title4)299    expect(title4).to.equal('Delete a Role')300    const check = await driver.findElement(By.xpath('//*[@id="main-content"]/h2')).getText()301    console.log(check)302    expect(check).to.equal('Delete selenium')303    await driver.findElement(By.xpath('//*[@id="main-content"]/form/button')).click()304    var alert = await driver.switchTo().alert().getText()305    console.log(alert)306    expect(alert).to.equal('Are you sure you want to delete this role?')307    await driver.switchTo().alert().accept()308    const title5 = await driver.getTitle()309    console.log(title5)310    expect(title5).to.equal('List of Job Roles')311    var elements3 = (await driver.findElements(By.className('govuk-table__cell')))312    for (let i = 0; i < elements3.length; i++) {313      if (await elements3[i].getText() === 'selenium') {314        expect(1).to.equal(2)315        break316      }317    }318  })319  it('Assert the title on create capability webpage is correct', async () => {320    await driver.get('http://localhost:3000/createCapabilityForm')321    const title = await driver.getTitle()322    expect(title).to.equal('Create A Capability')323    var htmlSource = await driver.getPageSource()324    fs.appendFile('app/assets/snapshots/createCapabilty-snapshot.html', htmlSource, function (err) {325      if (err) throw err326      console.log('Saved!')327    })328  })329  it('Assert the title on create band level webpage is correct', async () => {330    await driver.get('http://localhost:3000/createBandLevel')331    const title = await driver.getTitle()332    expect(title).to.equal('Add a New Band')333    var htmlSource = await driver.getPageSource()334    fs.appendFile('app/assets/snapshots/addBand-snapshot.html', htmlSource, function (err) {335      if (err) throw err336      console.log('Saved!')337    })338  })339  it('Should enter correct details and submit successfully', async () => {340    await driver.findElement(By.id('jobBandLevel')).sendKeys('Selenium Test')341    await driver.findElement(By.xpath('/html/body/div/main/form/div[2]/select/option[1]')).click()342    await driver.findElement(By.className('govuk-button')).click()343    const title = await driver.getTitle()344    expect(title).to.equal('Add a New Band Training')345    var htmlSource = await driver.getPageSource()346    fs.appendFile('app/assets/snapshots/addBandAddTraining-snapshot.html', htmlSource, function (err) {347      if (err) throw err348      console.log('Saved!')349    })350  })351  it('Should click a training box and submit', async () => {352    await driver.findElement(By.className('govuk-checkboxes__input')).click()353    await driver.findElement(By.className('govuk-button')).click()354    const title = await driver.getTitle()355    expect(title).to.equal('Add a New Band Competency')356    var htmlSource = await driver.getPageSource()357    fs.appendFile('app/assets/snapshots/addBandAddCompetencies-snapshot.html', htmlSource, function (err) {358      if (err) throw err359      console.log('Saved!')360    })361  })362  it('Should click a competency box and submit', async () => {363    await driver.findElement(By.className('govuk-checkboxes__input')).click()364    await driver.findElement(By.className('govuk-button')).click()365    const title = await driver.getTitle()366    expect(title).to.equal('Home')367  })368  after(async () => driver.quit())...

Full Screen

Full Screen

mocha_test.js

Source:mocha_test.js Github

copy

Full Screen

...15  16  it('Jump to Find page', function(done) {17    driver.get(URL);18    driver.findElement(webdriver.By.className("glyphicon  glyphicon-search")).click().then(()=>{19      driver.getPageSource().then(function(scource){20        assert.equal(scource.includes("lastNameGroup"), true);21        done();22      }).catch(message=>{23        console.log(message);24      });25    });26  });27  it('Creat an owner ', function(done) {28    driver.get(URL_add_owners);29    driver.findElement(webdriver.By.id('firstName')).sendKeys('Bokun').then(()=>{30      driver.findElement(webdriver.By.id('lastName')).sendKeys('Zhao').then(()=>{31        driver.findElement(webdriver.By.id('address')).sendKeys('3435 Drummond').then(()=>{32          driver.findElement(webdriver.By.id('city')).sendKeys('Montreal').then(()=>{33            driver.findElement(webdriver.By.id('telephone')).sendKeys('4383839202\n').then(()=>{34              driver.getPageSource().then(function(scource){35                assert.equal(scource.includes("Owner Information"), true); // Load the info page36                done();37              }).catch(message=>{38                console.log(message);39              });40            });41          });42        });43      });44    });45  });46  it('Creat an different owner ', function(done) {47    driver.get(URL_add_owners);48    driver.findElement(webdriver.By.id('firstName')).sendKeys('Yuelin').then(()=>{49      driver.findElement(webdriver.By.id('lastName')).sendKeys('Liu').then(()=>{50        driver.findElement(webdriver.By.id('address')).sendKeys('1100 Penfield').then(()=>{51          driver.findElement(webdriver.By.id('city')).sendKeys('Montreal').then(()=>{52            driver.findElement(webdriver.By.id('telephone')).sendKeys('4383839202\n').then(()=>{53              driver.getPageSource().then(function(scource){54                assert.equal(scource.includes("Owner Information"), true); // Load the info page55                done();56              }).catch(message=>{57                console.log(message);58              });59            });60          });61        });62      });63    });64  });65  it('Creat and find an owner', function(done) {66    driver.get(URL_add_owners);67    driver.findElement(webdriver.By.id('firstName')).sendKeys('Yuelin').then(()=>{68      driver.findElement(webdriver.By.id('lastName')).sendKeys('Liu').then(()=>{69        driver.findElement(webdriver.By.id('address')).sendKeys('1100 Penfield').then(()=>{70          driver.findElement(webdriver.By.id('city')).sendKeys('Montreal').then(()=>{71            driver.findElement(webdriver.By.id('telephone')).sendKeys('4389279373\n').then(()=>{72              driver.get(URL_find_owners).then(()=>{73                driver.findElement(webdriver.By.id('lastName')).sendKeys('Liu\n').then(()=>{74                  driver.getPageSource().then(function(scource){75                    assert.equal(scource.includes("Yuelin Liu"), true); // Load the info page76                    done();77                  }).catch(message=>{78                    console.log(message);79                  });80                });81              });82            });83          });84        });85      });86    });87  });88  it('Modify attributes of an owner', function(done) {89  driver.get(URL_find_owners);90    driver.findElement(webdriver.By.id('lastName')).sendKeys('Liu\n').then(()=>{91      driver.findElement(webdriver.By.linkText("Yuelin Liu")).click().then(()=>{92        driver.findElement(webdriver.By.linkText("Edit Owner")).click().then(()=>{93          driver.findElement(webdriver.By.id('telephone')).sendKeys('598342521\n').then(()=>{94            driver.getPageSource().then(function(scource){95              assert.equal(scource.includes("598342521"), true); // Load the info page96              done();97            }).catch(message=>{98              console.log(message);99            });100          })101        })102      })  103    })    104  });105  it('Add new Pet', function(done) {106    driver.get(URL_find_owners);107    driver.findElement(webdriver.By.id('lastName')).sendKeys('Zhao\n').then(()=>{108      driver.getPageSource().then(source => {109        if(source.includes("Pets and Visits")){110          driver.findElement(webdriver.By.linkText("Add New Pet")).click().then(()=>{111            driver.findElement(webdriver.By.id('type')).sendKeys('dog').then(()=>{112              driver.findElement(webdriver.By.id('birthDate')).sendKeys('2015-01-01').then(()=>{113                driver.findElement(webdriver.By.id('name')).sendKeys('Tom\n');114              });115            });116          });117        }else{118          driver.findElement(webdriver.By.linkText("Bokun Zhao")).click().then(()=>{119            driver.findElement(webdriver.By.linkText("Add New Pet")).click().then(()=>{120              driver.findElement(webdriver.By.id('type')).sendKeys('dog').then(()=>{121                driver.findElement(webdriver.By.id('birthDate')).sendKeys('2015-01-01').then(()=>{122                  driver.findElement(webdriver.By.id('name')).sendKeys('Tom\n');123                });124              });125            });126          });127        }128      }).then(()=>{129          driver.getPageSource().then(function(source2){130          assert.equal(source2.includes("Bokun Zhao"), true); 131          //assert.equal(scource.includes("Tom"), true); 132          done();133        }).catch(message=>{134          console.log(message);135        });136      });137    });138  });139  it('Add second pet', function(done) {140    driver.get(URL_find_owners);141    driver.findElement(webdriver.By.id('lastName')).sendKeys('Liu\n').then(()=>{142      driver.findElement(webdriver.By.linkText("Yuelin Liu")).click().then(()=>{143        driver.findElement(webdriver.By.linkText("Add New Pet")).click().then(()=>{144          driver.findElement(webdriver.By.id('type')).sendKeys('cat').then(()=>{145            driver.findElement(webdriver.By.id('birthDate')).sendKeys('2017-01-01').then(()=>{146              driver.findElement(webdriver.By.id('name')).sendKeys('Sam\n').then(()=>{147                done();148              });149            });150          });151        });152      }).catch(message=>{153        console.log(message);154      });155    });156  });157  it('Update Pet', function(done) {158    driver.get(URL_find_owners);159    driver.findElement(webdriver.By.id('lastName')).sendKeys('Liu\n').then(()=>{160      driver.findElement(webdriver.By.linkText("Yuelin Liu")).click().then(()=>{161        driver.findElement(webdriver.By.linkText("Edit Pet")).click().then(()=>{162          driver.findElement(webdriver.By.id('name')).clear().then(()=>{163            driver.findElement(webdriver.By.id('name')).sendKeys('BigSam\n').then(()=>{164              driver.getPageSource().then(function(scource){165                assert.equal(scource.includes("BigSam"), true); 166                done();167              }).catch(message=>{168                console.log(message);169              });170            });171          });172        });173      }).catch(message=>{174        console.log(message);175      });176    });177  });178  it('Update Pet Again', function(done) {179    driver.get(URL_find_owners);180    driver.findElement(webdriver.By.id('lastName')).sendKeys('Liu\n').then(()=>{181      driver.findElement(webdriver.By.linkText("Yuelin Liu")).click().then(()=>{182        driver.findElement(webdriver.By.linkText("Edit Pet")).click().then(()=>{183          driver.findElement(webdriver.By.id('name')).clear().then(()=>{184            driver.findElement(webdriver.By.id('name')).sendKeys('Sam\n').then(()=>{185              driver.getPageSource().then(function(scource){186                assert.equal(scource.includes("BigSam"), false); 187                assert.equal(scource.includes("Sam"), true); 188                done();189              }).catch(message=>{190                console.log(message);191              });192            });193          });194        });195      }).catch(message=>{196        console.log(message);197      });198    });199  });200  201  it('Add Visit', function(done) {202    driver.get(URL_find_owners);203    driver.findElement(webdriver.By.id('lastName')).sendKeys('Liu\n').then(()=>{204      driver.findElement(webdriver.By.linkText("Yuelin Liu")).click().then(()=>{205      driver.findElement(webdriver.By.linkText("Add Visit")).click().then(()=>{206        driver.findElement(webdriver.By.id('date')).clear().then(()=>{207          driver.findElement(webdriver.By.id('date')).sendKeys('2021-07-07').then(()=>{208            driver.findElement(webdriver.By.id('description')).sendKeys('The pet has flu.\n').then(()=>{209              driver.getPageSource().then(function(scource){210                assert.equal(scource.includes("flu"), true); 211                done();212              }).catch(message=>{213                console.log(message);214              });215            });216          });217        });218      });219    });220  });221  });222  it('Add Second Visit', function(done) {223    driver.get(URL_find_owners);224    driver.findElement(webdriver.By.id('lastName')).sendKeys('Liu\n').then(()=>{225      driver.findElement(webdriver.By.linkText("Yuelin Liu")).click().then(()=>{226      driver.findElement(webdriver.By.linkText("Add Visit")).click().then(()=>{227        driver.findElement(webdriver.By.id('date')).clear().then(()=>{228          driver.findElement(webdriver.By.id('date')).sendKeys('2021-09-09').then(()=>{229            driver.findElement(webdriver.By.id('description')).sendKeys('The pet is in good health.\n').then(()=>{230              driver.getPageSource().then(function(scource){231                assert.equal(scource.includes("health"), true); 232                done();233              }).catch(message=>{234                console.log(message);235              });236            });237          });238        });239      });240    });241  });242  });243 244  after(function() { driver.quit(); });...

Full Screen

Full Screen

login-steps.js

Source:login-steps.js Github

copy

Full Screen

...29        )30      })31  });32  this.Then(/^We should find "([^"]*)"$/, function (sourceMatch, next) {33    this.driver.getPageSource()34      .then(function(source) {35        assert.equal(36          source.indexOf(sourceMatch) > -1,37          true,38          next,39          'Expected source to contain ' + sourceMatch40        )41      })42  });43  this.Then(/^We should log in$/, function (next) {44    var self = this;45    this.driver.getPageSource()46      .then(function (source) {47        var username = self.driver48          .findElement(webdriver.By.name("_username"));49        var password = self.driver50          .findElement(webdriver.By.name("_password"));51        debug(globals.browser_name)52        if(_.indexOf(globals.webdriver_browsers, globals.browser_name) > -1) {53          debug("using webdriver default")54          // Chrome: not working55          // Safari: all elements clicked and filled56          // Internet Explorer: only password clicks and fills57          // Firefox: all elements clicked and filled58          // iPhone: not working59          // iPad: untested60          // Android: untested61          // Edge: untested62          username63            .click()64            .then(function() {65              username66                .sendKeys(conf.config.page_user)67            })68          password69            .click()70            .then(function() {71              password72                .sendKeys(conf.config.page_user_pass)73            })74        }75        else if(_.indexOf(globals.action_sequence_browsers, globals.browser_name) > -1) {76          debug("using action sequence")77          // Chrome: all elements clicked and filled78          // Safari: untested79          // Internet untested80          // Firefox: untested81          // iPhone: not working82          // iPad: untested83          // Android: Samsung Works84          // Edge: works85          var user_actions = new webdriver.ActionSequence(self.driver);86          user_actions87            .click(username)88            .sendKeys(conf.config.page_user)89            .click(password)90            .sendKeys(conf.config.page_user_pass)91            .perform();92        }93        // Section results94        // Chrome: submit works and page loads (6s)95        // Safari: submit works, but page does not load (15s)96        // Internet Explorer: username is empty, submit works, login failure97        // Firefox: submit works and page loads (6s)98        // iPhone: untested99        // iPad: untested100        // Android: Samsung Works101        // Edge: works102        var submit_btn = self.driver.findElement(webdriver.By.id("_submit"));103        submit_btn.click()104          .then(function() {105            return self.driver.wait(function () {106              debug('waiting for element ODRDashboardGraphs')107              return self.driver.getPageSource()108                .then(function(pageSource) {109                  if(pageSource.match(/Invalid login./)) {110                    throw("Invalid login.")111                  }112                  return self.driver.isElementPresent(webdriver.By.id("ODRDashboardGraphs"));113                })114            }, 15000)115              .then(function() {116                return self.driver.getPageSource()117                  .then(function (dash_source) {118                    return assert.equal(119                      dash_source.indexOf('Logout') > -1,120                      true,121                      next,122                      'Expected source to contain logout'123                    )124                  })125              })126          })127      })128  });129  /*130    // hover over element....131	var webdriver = require('selenium-webdriver');132	var driver = new webdriver.Builder().usingServer().withCapabilities({'browserName': 'chrome' }).build();133	driver.manage().window().setSize(1280, 1000).then(function() {134		driver.get('http://www.shazam.com/discover/track/58858793');135		driver.findElement(webdriver.By.css('.ta-tracks li:first-child')).then(function(elem){136			driver.actions().mouseMove(elem).perform();137			driver.sleep(5000);138   */139  /*140  this.Then(/^We snap a screenshot$/, function (next) {141    return this.driver.takeScreenshot();142  });143  */144  this.Then(/^We should see "([^"]*)"$/, function (sourceMatch, next) {145    this.driver.getPageSource()146      .then(function(source) {147        assert.equal(source.indexOf(sourceMatch) > -1, true, next, 'Expected source to contain ' + sourceMatch);148        next()149      })150      .catch(function(error) {151        return testerror.handleError(error, session_id)152      });153  });154  this.Then(/^We should take a screenshot of the "([^"]*)"$/, function (sourceMatch, next) {155      this.driver.takeScreenshot().then(function (data) {156          debug('Screenshot');157          next()158          /*159          var base64Data = data.replace(/^data:image\/png;base64,/, "")160          var ss_path = 'screenshots/' + moment().format('YYYY-MM-DD-HH')161          debug('path start');162          return mkpath(ss_path, function(fs_error) {163              debug('path function');164              if(fs_error) {165                  debug('path fail');166                  debug(fs_err);167                  return testerror.handleError(error, session_id)168              }169              else {170                  debug('path success');171                  fs.writeFile(ss_path + '/' + sourceMatch + ".png", base64Data, 'base64', function (err) {172                      if (err) {173                          debug(err);174                          return testerror.handleError(error, session_id)175                      }176                      next()177                  });178              }179          })180          */181      })182      .catch(function(error) {183          debug(error);184          return testerror.handleError(error, session_id)185      });186  });187  this.Then(/^We should also see "([^"]*)"$/, function (sourceMatch, next) {188    this.driver.getPageSource()189      .then(function(source) {190        assert.equal(source.indexOf(sourceMatch) > -1, true, next, 'Expected source to contain ' + sourceMatch);191        next()192      })193      .catch(function(error) {194        return testerror.handleError(error, session_id)195      });196  });...

Full Screen

Full Screen

xcloud.spec.js

Source:xcloud.spec.js Github

copy

Full Screen

...3        // browser.getLogs('logcat');4        driver.startRecordingScreen();5        driver.takeScreenshot();6        driver.takeScreenshot();7        driver.getPageSource();8        driver.takeScreenshot();9        driver.getPageSource();10        driver.takeScreenshot();11        driver.getPageSource();12        driver.takeScreenshot();13        driver.stopRecordingScreen();14        driver.getCurrentPackage();15        driver.getCurrentActivity();16        driver.getPageSource();17        // browser.getLogs('logcat');18        driver.startRecordingScreen();19        driver.takeScreenshot();20        driver.getPageSource();21        driver.takeScreenshot();22        driver.getPageSource();23        driver.takeScreenshot();24        driver.getPageSource();25        driver.takeScreenshot();26        driver.getPageSource();27        // browser.getLogs('logcat');28        // NO STOPPING!!!!29        driver.startRecordingScreen();30        driver.takeScreenshot();31        driver.takeScreenshot();32        driver.getPageSource();33        driver.takeScreenshot();34        driver.getPageSource();35        driver.takeScreenshot();36        driver.getPageSource();37        driver.takeScreenshot();38        driver.stopRecordingScreen();39        driver.takeScreenshot();40        driver.getPageSource();41        // browser.getLogs('logcat');42        driver.startRecordingScreen();43        for(let i=0; i < 100; i++) {44            driver.pressKeyCode(69);45        }46        driver.takeScreenshot();47        driver.getPageSource();48        driver.takeScreenshot();49        driver.getPageSource();50        driver.takeScreenshot();51        driver.getPageSource();52        driver.stopRecordingScreen();53        driver.takeScreenshot();54        driver.getPageSource();55        // browser.getLogs('logcat');56        driver.startRecordingScreen();57        for(let i=0; i < 100; i++) {58            driver.pressKeyCode(69);59        }60        driver.takeScreenshot();61        driver.getPageSource();62        driver.takeScreenshot();63        driver.getPageSource();64        driver.takeScreenshot();65        driver.getPageSource();66        driver.stopRecordingScreen();67        driver.takeScreenshot();68        driver.getPageSource();69        driver.takeScreenshot();70        driver.getPageSource();71        driver.takeScreenshot();72        driver.getPageSource();73        // browser.getLogs('logcat');74        driver.startRecordingScreen();75        driver.takeScreenshot();76        driver.getPageSource();77        driver.stopRecordingScreen();78        driver.takeScreenshot();79        driver.getPageSource();80        // browser.getLogs('logcat');81        driver.startRecordingScreen();82        driver.takeScreenshot();83        driver.getPageSource();84        driver.takeScreenshot();85        driver.getPageSource();86        driver.takeScreenshot();87        driver.getPageSource();88        driver.stopRecordingScreen();89        driver.takeScreenshot();90        driver.getPageSource();91        driver.takeScreenshot();92        driver.getPageSource();93        driver.takeScreenshot();94        driver.getPageSource();95        // browser.getLogs('logcat');96        driver.startRecordingScreen();97        driver.takeScreenshot();98        driver.getPageSource();99        driver.stopRecordingScreen();100        driver.takeScreenshot();101        driver.getPageSource();102        driver.takeScreenshot();103        driver.getPageSource();104        driver.takeScreenshot();105        driver.getPageSource();106        driver.takeScreenshot();107        driver.getPageSource();108        driver.takeScreenshot();109        driver.getPageSource();110        driver.takeScreenshot();111        driver.getPageSource();112        driver.takeScreenshot();113        driver.getPageSource();114        driver.takeScreenshot();115        driver.getPageSource();116        driver.takeScreenshot();117        driver.getPageSource();118        // VERY STRANGE, NOW THERE IS A STOP119        driver.stopRecordingScreen();120        driver.getPageSource();121        // browser.getLogs('logcat');122        driver.startRecordingScreen();123        driver.takeScreenshot();124        driver.getPageSource();125        driver.stopRecordingScreen();126        driver.getPageSource();127        // browser.getLogs('logcat');128        driver.startRecordingScreen();129        driver.takeScreenshot();130        driver.getPageSource();131        driver.stopRecordingScreen();132        driver.getPageSource();133        // browser.getLogs('logcat');134        driver.startRecordingScreen();135        for(let i=0; i < 100; i++) {136            driver.pressKeyCode(69);137        }138        driver.takeScreenshot();139        driver.getPageSource();140        driver.stopRecordingScreen();141        driver.getPageSource();142        // browser.getLogs('logcat');143        driver.startRecordingScreen();144        driver.takeScreenshot();145        driver.getPageSource();146        driver.stopRecordingScreen();147        driver.getPageSource();148        // browser.getLogs('logcat');149        driver.startRecordingScreen();150        driver.takeScreenshot();151        driver.getPageSource();152        driver.stopRecordingScreen();153        driver.getPageSource();154        // browser.getLogs('logcat');155        driver.startRecordingScreen();156        driver.takeScreenshot();157        driver.getPageSource();158        driver.stopRecordingScreen();159        driver.getPageSource();160        // browser.getLogs('logcat');161        driver.startRecordingScreen();162        for(let i=0; i < 100; i++) {163            driver.pressKeyCode(69);164        }165        driver.takeScreenshot();166        driver.getPageSource();167        driver.stopRecordingScreen();168        driver.getPageSource();169        driver.takeScreenshot();170        driver.getPageSource();171        driver.getPageSource();172        driver.takeScreenshot();173        driver.getPageSource();174        driver.getPageSource();175        driver.takeScreenshot();176        driver.getPageSource();177        driver.getPageSource();178        driver.takeScreenshot();179        driver.getPageSource();180        driver.getPageSource();181        // browser.getLogs('logcat');182    });...

Full Screen

Full Screen

webdriverHelper.js

Source:webdriverHelper.js Github

copy

Full Screen

...16    caps.set("acceptSslCerts", true);17    caps.set("phantomjs.page.settings.userAgent", userAgent);18    var driver = new webdriver.Builder().withCapabilities(caps).build();19    return driver.get('https://www.upwork.com/ab/account-security/login').then(function () {20        driver.getPageSource().then(function (source) {21            fs.writeFileSync('source_0.html', source);22        });23        return driver.findElement(by.id('login_username')).sendKeys(usr);24    }).then(function () {25        return driver.findElement(by.id('login_password')).sendKeys(psw);26    }).then(function () {27        driver.getPageSource().then(function (source) {28            fs.writeFileSync('source.html', source);29        });30        return driver.wait(function () {31            return driver.findElement(by.css('.m-md-top .btn-primary')).isDisplayed();32        }, 10000);33    }).then(function () {34        return driver.findElement(by.css('.m-md-top .btn-primary')).click();35    }).then(function () {36        return driver.manage().getCookies().then(function (cookies) {37            var cookieStr = '';38            cookies.forEach(function (cookie, index, array) {39                cookieStr += cookie.name + '=' + cookie.value + '; ';40            });41            driver.quit();42            return cookieStr;43        });44    });45}46var allProcess = function (usr, psw) {47    var entity = {};48    var jobsHtml = [];49    var applicants = [];50    entity.jobsHtml = jobsHtml;51    entity.applicants = applicants;52    var caps = webdriver.Capabilities.phantomjs();53    caps.set("browserConnectionEnabled", true);54    caps.set("handlesAlerts", true);55    caps.set("databaseEnabled", true);56    caps.set("locationContextEnabled", true);57    caps.set("applicationCacheEnabled", true);58    caps.set("webStorageEnabled", true);59    caps.set("acceptSslCerts", true);60    caps.set("phantomjs.page.settings.userAgent", userAgent);61    var driver = new webdriver.Builder().withCapabilities(caps).build();62    return driver.get('https://www.upwork.com/ab/account-security/login').then(function () {63        driver.getPageSource().then(function (source) {64            fs.writeFileSync('source_0.html', source);65        });66        return driver.findElement(by.id('login_username')).sendKeys(usr);67    }).then(function () {68        return driver.findElement(by.id('login_password')).sendKeys(psw);69    }).then(function () {70        driver.getPageSource().then(function (source) {71            fs.writeFileSync('source.html', source);72        });73        return driver.wait(function () {74            return driver.findElement(by.css('.m-md-top .btn-primary')).isDisplayed();75        }, 10000);76    }).then(function () {77        return driver.findElement(by.css('.m-md-top .btn-primary')).click();78    }).then(function () {79        return driver.get('https://www.upwork.com/jobs/?spellcheck=1&highlight=1&sortBy=s_ctime+desc&cn1%5B%5D=Web%2C+Mobile+%26+Software+Dev&cn2%5B%5D=Web+Development&cn2%5B%5D=Other+-+Software+Development&cn2%5B%5D=Desktop+Software+Development&cn2%5B%5D=Scripts+%26+Utilities&exp%5B%5D=2&exp%5B%5D=3&amount%5B%5D=Min&amount%5B%5D=1k');80    }).then(function () {81        return driver.getPageSource();82    }).then(function (source) {83        var phpVar = source.match(/var phpVars =(.*);/)[1];84        var phpVarJson = JSON.parse(phpVar);85        entity.jobs = phpVarJson;86        var linkArray = [];87        phpVarJson.jobs.forEach(function (job, index, array) {88            var dataKey = job.ciphertext;89            var link = 'https://www.upwork.com/jobs/' + dataKey;90            linkArray.push(link);91        });92        var context = {linkArray: linkArray};93        return context;94    }).then(function (context) {95        var link = context.linkArray[0];96        return driver.get(link).then(function () {97            return context;98        })99    }).then(function (context) {100        console.log('start working on job html');101        return driver.getPageSource().then(function (source) {102            entity.jobsHtml.push(source)103            return context;104        });105    }).then(function (context) {106        console.log('start working on applicants');107        var applicantsLink = context.linkArray[0] + '/applicants';108        return driver.get(applicantsLink).then(function () {109            return driver.getPageSource().then(function (source) {110                // console.log(source);111                var $ = cheerio.load(source);112                var jsonStr = $('pre').text();113                var applicants = JSON.parse(jsonStr);114                entity.applicants.push(applicants);115                return 0;116            });117        });118    }).then(function () {119        var folderName = Date.now().toString();120        fs.mkdirSync(folderName);121        fs.writeFileSync(folderName + '/' + 'result.json', JSON.stringify(entity));122    });123}...

Full Screen

Full Screen

source-e2e-specs.js

Source:source-e2e-specs.js Github

copy

Full Screen

...21  after(async function () {22    await driver.deleteSession();23  });24  it('should return the page source', async function () {25    let source = await driver.getPageSource();26    await assertSource(source);27  });28  it('should get less source when compression is enabled', async function () {29    let getSourceWithoutCompression = async () => {30      await driver.updateSettings({ignoreUnimportantViews: false});31      return await driver.getPageSource();32    };33    let getSourceWithCompression = async () => {34      await driver.updateSettings({ignoreUnimportantViews: true});35      return await driver.getPageSource();36    };37    let sourceWithoutCompression = await getSourceWithoutCompression();38    let sourceWithCompression = await getSourceWithCompression();39    sourceWithoutCompression.length.should.be.greaterThan(sourceWithCompression.length);40  });...

Full Screen

Full Screen

basics-specs.js

Source:basics-specs.js Github

copy

Full Screen

...9        browserName: 'safari',10        noReset: true,11      }).driver;12      it('it should use safari default init page', async function () {13        (await driver.getPageSource()).should.include('Apple');14      });15    });16  }17  describe('default init', function () {18    const driver = setup(this, {19      browserName: 'safari',20      noReset: true,21    }).driver;22    it('it should use appium default init page', async function () {23      (await driver.getPageSource()).should.include('Let\'s browse!');24    });25  });26  describe('init with safariInitialUrl', function () {27    const driver = setup(this, {28      browserName: 'safari',29      safariInitialUrl: env.GUINEA_TEST_END_POINT,30      noReset: true,31    }).driver;32    it('should go to the requested page', async function () {33      (await driver.getPageSource()).should.include('I am some page content');34    });35  });...

Full Screen

Full Screen

source-specs.js

Source:source-specs.js Github

copy

Full Screen

...12    proxySpy.reset();13  });14  describe('getPageSource', () => {15    it('should send translated GET request to WDA', async () => {16      await driver.getPageSource();17      proxySpy.calledOnce.should.be.true;18      proxySpy.firstCall.args[0].should.eql('/source');19      proxySpy.firstCall.args[1].should.eql('GET');20    });21    it('should insert received xml into AppiumAUT tags', async () => {22      let src = await driver.getPageSource();23      src.indexOf(xmlHeader).should.eql(0);24      src.indexOf(appiumHeadTag).should.eql(xmlHeader.length);25      src.indexOf(appiumFootTag).should.eql(srcTree.length + appiumHeadTag.length);26    });27  });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3    .withCapabilities({4    })5    .build();6    driver.getPageSource().then(function (pageSource) {7        console.log(pageSource);8    });9});10driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var By = webdriver.By;3var until = webdriver.until;4var driver = new webdriver.Builder()5    .forBrowser('chrome')6    .build();7driver.getPageSource().then(function (pageSource) {8    console.log(pageSource);9    driver.quit();10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3    .forBrowser('chrome')4    .build();5driver.getPageSource().then(function (source) {6    console.log(source);7});8driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3    .forBrowser('chrome')4    .build();5driver.getPageSource().then(function (source) {6    console.log(source);7});8driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver'),2    until = webdriver.until;3var driver = new webdriver.Builder()4    .forBrowser('chrome')5    .build();6driver.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnG')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.getPageSource().then(function (pageSource) {10    console.log(pageSource);11});12driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver'),2until = webdriver.until;3var driver = new webdriver.Builder()4    .forBrowser('chrome')5    .build();6driver.getPageSource().then(function(source){7    console.log(source);8});9driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var fs = require('fs');3var driver = wd.remote("localhost", 4723);4driver.init({5}, function(err, sessionID) {6  if (err) {7    throw err;8  }9  console.log("Session ID: ", sessionID);10  driver.source(function(err, res) {11    if (err) {12      throw err;13    }14    console.log(res);15    fs.writeFile('./pageSource.txt', res, function(err) {16      if (err) {17        throw err;18      }19      console.log('file saved');20    });21  });22});23var fs = require('fs');24var source = fs.readFileSync('./pageSource.txt', 'utf8');25console.log(source);

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2}).build();3driver.getPageSource().then(function (source) {4    console.log(source);5    var text = source.match(/text="(.*)"/);6    console.log(text[1]);7});

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.

Run Appium Android Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful